UltrasonicNXT has uploaded a new change for review.
https://gerrit.wikimedia.org/r/120369
Change subject: Change away mechanism to be automatic
......................................................................
Change away mechanism to be automatic
Users will be automatically marked as away on a varying scale after 10
minutes of write inactivity.
Idle times are now given.
DB changes needed.
Change-Id: I0b28bf326ae4a816ec4dc88aba9ebb51fff6178b
---
D Away.api.php
M GetNew.api.php
M Kick.api.php
M MediaWikiChat.css
M MediaWikiChat.hooks.php
M MediaWikiChat.i18n.php
M MediaWikiChat.js
M MediaWikiChat.php
M MediaWikiChatClass.php
M Send.api.php
M SendPM.api.php
M SpecialChat.template.php
M chat_users.sql
M cu_away.sql
A cu_away_new.sql
15 files changed, 94 insertions(+), 133 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiChat
refs/changes/69/120369/1
diff --git a/Away.api.php b/Away.api.php
deleted file mode 100644
index 7033855..0000000
--- a/Away.api.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-class ChatAwayAPI extends ApiBase {
-
- public function execute() {
- $result = $this->getResult();
- $user = $this->getUser();
-
- if ( $user->isAllowed( 'chat' ) ) {
- $away = $this->getMain()->getVal( 'away' ) ? 1 : 0;
-
- $dbw = wfGetDB( DB_MASTER );
-
- $dbw->update(
- 'chat_users',
- array( 'cu_away' => $away ),
- array( 'cu_user_id' => $user->getId() ),
- __METHOD__
- );
-
- $result->addValue( $this->getModuleName(), 'timestamp',
MediaWikiChat::now() );
-
- } else {
- $result->addValue( $this->getModuleName(), 'error',
'you are not allowed to chat' );
- }
-
- return true;
- }
-
- public function getDescription() {
- return 'Toggle away on the current user.';
- }
-
- public function getAllowedParams() {
- return array(
- 'away' => array (
- ApiBase::PARAM_TYPE => 'boolean',
- ApiBase::PARAM_REQUIRED => true
- )
- );
- }
-
- public function getParamDescription() {
- return array(
- 'away' => 'Whether the current user should be away or
not away.'
- );
- }
-
- public function getExamples() {
- return array(
- 'api.php?action=chataway&away=true' => 'Make the
current user away'
- );
- }
-
- public function mustBePosted() {
- return true;
- }
-}
\ No newline at end of file
diff --git a/GetNew.api.php b/GetNew.api.php
index 9453326..d15b708 100644
--- a/GetNew.api.php
+++ b/GetNew.api.php
@@ -4,7 +4,7 @@
class ChatGetNewAPI extends ApiBase {
public function execute() {
- global $wgChatSocialAvatars;
+ global $wgChatSocialAvatars, $wgChatOnlineTimeout;
$result = $this->getResult();
$mName = $this->getModuleName();
@@ -17,14 +17,12 @@
$thisCheck = MediaWikiChat::now();
- $res = $dbr->selectField(
+ $lastCheck = $dbr->selectField(
'chat_users',
'cu_timestamp',
array( 'cu_user_id' => $user->getId() ),
__METHOD__
);
-
- $lastCheck = strval( $res );
if ( $lastCheck ) {
$dbw->update(
@@ -33,6 +31,11 @@
array( 'cu_user_id' => $user->getId() ),
__METHOD__
);
+
+ if ( $lastCheck < $thisCheck -
$wgChatOnlineTimeout ) {
+ MediaWikiChat::updateAway( $user ); //
user is returning from offline, so say they're not away
+ }
+
} else {
$dbw->insert(
'chat_users',
@@ -135,9 +138,7 @@
}
if ( array_key_exists( $id, $onlineUsers ) ) {
$result->addValue( array( $mName,
'users', $idString ), 'online', true );
- if ( $onlineUsers[$id] ) {
- $result->addValue( array(
$mName, 'users', $idString ), 'away', true );
- }
+ $result->addValue( array( $mName,
'users', $idString ), 'away', $onlineUsers[$id] );
}
$groups = $userObject->getGroups();
if ( in_array( 'chatmod', $groups ) ||
in_array( 'sysop', $groups ) ) {
diff --git a/Kick.api.php b/Kick.api.php
index cf162bb..7a1d9ca 100644
--- a/Kick.api.php
+++ b/Kick.api.php
@@ -39,6 +39,8 @@
) );
$logEntry->insert();
+ MediaWikiChat::updateAway( $user );
+
$result->addValue( $this->getModuleName(), 'timestamp',
$timestamp );
} else {
diff --git a/MediaWikiChat.css b/MediaWikiChat.css
index c4493e6..d46d794 100644
--- a/MediaWikiChat.css
+++ b/MediaWikiChat.css
@@ -141,23 +141,4 @@
}
#mwchat-type {
position: relative;
-}
-#mwchat-away-link {
- float: right;
- margin-right: 5px;
-}
-.mwchat-grey img {
- -webkit-filter: grayscale(1); /* old webkit */
- -webkit-filter: grayscale(100%); /* new webkit */
- -moz-filter: grayscale(100%); /* safari */
- -ms-filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
/* maybe ie */
- filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); /*
maybe ie */
- filter: gray; /* maybe ie */
- filter: grayscale(100%); /* future */
-}
-.mwchat-grey span, .mwchat-grey a {
- color: #555 !important;
-}
-.mwchat-grey .mwchat-useritem-header {
- background-color: #f8f8f8;
}
\ No newline at end of file
diff --git a/MediaWikiChat.hooks.php b/MediaWikiChat.hooks.php
index eceb8f7..0f0e2e3 100644
--- a/MediaWikiChat.hooks.php
+++ b/MediaWikiChat.hooks.php
@@ -60,6 +60,7 @@
$updater->addExtensionTable( 'chat', $dir . 'chat.sql', true );
$updater->addExtensionTable( 'chat_users', $dir .
'chat_users.sql', true );
$updater->addExtensionField( 'chat_users', 'cu_away', $dir .
'cu_away.sql' );
+ $updater->modifyExtensionField( 'chat_users', 'cu_away', $dir .
'/cu_away_new.sql' );
return true;
}
diff --git a/MediaWikiChat.i18n.php b/MediaWikiChat.i18n.php
index 50ceb42..4390cdb 100644
--- a/MediaWikiChat.i18n.php
+++ b/MediaWikiChat.i18n.php
@@ -83,9 +83,8 @@
'tog-chat-ping-message' => 'Play a sound on receiving normal messages',
'prefs-chat' => 'Chat',
- 'chat-away-link' => 'online',
- 'chat-back-link' => 'away',
- 'chat-user-is-away' => 'This user is away'
+ 'chat-idle-minutes' => 'This user has been idle for {{PLURAL:$1|a
minute|$1 minutes}}',
+ 'chat-idle-hours' => 'This user has been idle for {{PLURAL:$1|an
hour|$1 hours}}',
);
/** Message documentation (Message documentation)
@@ -240,8 +239,8 @@
'tog-chat-ping-message' => 'Label for checkbox for whether to use chat
in fullscreen.',
'prefs-chat' => 'Header for the chat preferences at
[[Special:Preferences]].
{{Identical|Chat}}',
- 'chat-away-link' => '{{Identical|Online}}',
- 'chat-back-link' => '{{Identical|Away}}',
+ 'chat-idle-minutes' => 'Tooltip for users who have been away for over
10 minutes. The number of minutes is $1. {{Related|Chat-idle-hours}}',
+ 'chat-idle-hours' => 'Tooltip for users who have been away for over 1
hour. The number of hours is $1. {{Related|Chat-idle-minutes}}',
);
/** Arabic (العربية)
diff --git a/MediaWikiChat.js b/MediaWikiChat.js
index ac10df3..16273c9 100644
--- a/MediaWikiChat.js
+++ b/MediaWikiChat.js
@@ -138,8 +138,9 @@
if ( user.mod ) {
MediaWikiChat.userData[userId].mod =
true;
}
- if ( user.online ) {
+ if ( user.online && user.id != mw.config.get(
'wgUserId' ) ) {
onlineUsers[onlineUsers.length] =
userId;
+ MediaWikiChat.userData[userId].away =
user.away;
}
}
@@ -149,13 +150,9 @@
for ( var userId in data.users ) { // has to be done
after doUsers
user = MediaWikiChat.userData[userId];
- userE = MediaWikiChat.safe( user.name );
- if ( data.users[userId].away ) {
- $( '#mwchat-users #' + userE
).addClass( 'mwchat-grey' );
- $( '#mwchat-users #' + userE + '
.mwchat-useritem-header' ).attr( 'title', mw.message( 'chat-user-is-away'
).text() );
- } else {
- $( '#mwchat-users #' + userE
).removeClass( 'mwchat-grey' );
- $( '#mwchat-users #' + userE + '
.mwchat-useritem-header' ).attr( 'title', mw.message( 'chat-private-message'
).text() );
+ if ( user.id != mw.config.get( 'wgUserId' ) ) {
+ userE = MediaWikiChat.safe( user.name );
+ MediaWikiChat.greyscale( $(
'#mwchat-users #' + userE ), user.away );
}
}
@@ -350,6 +347,50 @@
MediaWikiChat.flashPrivate();
},
+ greyscale: function( element, microseconds ) {
+ element = element.children( '.mwchat-useritem-header' );
+
+ var hours = microseconds / 360000.0; // 360000 = 1 hour.
+ var tooltip = '';
+
+ if ( hours > 1 ) {
+ tooltip = mw.message( 'chat-idle-hours', Math.round(
hours ) );
+ decimal = 1;
+ } else {
+ var minutes = microseconds / 6000;
+ if ( minutes > 10 ) {
+ tooltip = mw.message( 'chat-idle-minutes',
Math.round( minutes ) );
+ } else {
+ tooltip = mw.message( 'chat-private-message' );
+ }
+ }
+
+ $( element ).attr( 'title', tooltip );
+
+ // Make it so anything under 10 mins will give 0, and then the
colouring happens between 10 and 60 mins
+ hours = ( hours * 1.1 ) - 0.1;
+ if ( hours < 0 ) {
+ hours = 0;
+ }
+
+ var percent = Math.round( hours * 100 );
+
+ $( element ).children( 'img' ).css( {
+ '-webkit-filter': 'grayscale(' + hours + ')', /* old
webkit */
+ '-webkit-filter': 'grayscale(' + percent + '%)', /* new
webkit */
+ '-moz-filter': 'grayscale(' + percent + '%)', /*
mozilla */
+ '-ms-filter':
'progid:DXImageTransform.Microsoft.BasicImage(grayscale=' + hours + ')', /*
maybe ie */
+ 'filter':
'progid:DXImageTransform.Microsoft.BasicImage(grayscale=' + hours + ')', /*
maybe ie */
+ 'filter': 'grayscale(' + percent + '%)' /* future */
+ } );
+
+ var b = Math.round( hours * 10 + 238 ); // 238 > 248 Useritem
header background gets lighter
+ $( element ).css( 'background-color', 'rgb(' + b + ', ' + b +
', ' + b + ')' );
+
+ var c = Math.round( hours * 85 ); // 0 > 85 User name text gets
lighter
+ $( element ).children( 'span' ).css( 'color', 'rgb(' + c + ', '
+ c + ', ' + c + ')' );
+ },
+
doUsers: function( newusers ) {
var allusers = MediaWikiChat.users.concat( newusers );
allusers = MediaWikiChat.unique( allusers );
@@ -380,7 +421,7 @@
var userE = MediaWikiChat.safe( user.name );
var html = '<div class="mwchat-useritem noshow" data-unread=""
data-name="' + user.name + '" data-id="' + userId + '" id="' + userE + '">';
- html += '<div class="mwchat-useritem-header" title="' +
mw.message( 'chat-private-message' ).text() + '">';
+ html += '<div class="mwchat-useritem-header">';
if ( mw.config.get( 'wgChatSocialAvatars' ) ) {
html += '<img src="' + user.avatar + '" />';
@@ -538,7 +579,6 @@
},
audio: function( filename ) {
- //var audio = new Audio( mw.config.get( 'wgScriptPath') +
'/extensions/MediaWikiChat/burp.ogg' );
var audio = document.createElement( 'audio' );
var path = mw.config.get( 'wgScriptPath') +
'/extensions/MediaWikiChat/audio/' + filename;
@@ -614,33 +654,6 @@
var height = $( '#mwchat-content' ).height();
$( '#mwchat-users' ).animate( { 'height': height }, 'fast' );
$( '#mwchat-me' ).animate( { 'top': height }, 'fast' );
- } );
-
- $( '#mwchat-away-link' ).click( function() {
- if ( MediaWikiChat.away ) {
- $.ajax( {
- type: 'POST',
- url: mw.config.get( 'wgScriptPath' ) +
'/api.php',
- data: { 'action': 'chataway', 'format': 'json' }
- } ).done( function( msg ) {
- $( '#mwchat-me' ).removeClass( 'mwchat-grey' );
- $( '#mwchat-away-link' ).html( mw.message(
'chat-away-link' ).text() );
- MediaWikiChat.away = false;
- console.log( msg );
- } );
- } else {
- $.ajax( {
- type: 'POST',
- url: mw.config.get( 'wgScriptPath' ) +
'/api.php',
- data: { 'action': 'chataway', 'away': 'away',
'format': 'json' }
- } ).done( function( msg ) {
- $( '#mwchat-me' ).addClass( 'mwchat-grey' );
- $( '#mwchat-away-link' ).html( mw.message(
'chat-back-link' ).text() );
- MediaWikiChat.away = true;
- console.log( msg );
- } );
- }
-
} );
} );
diff --git a/MediaWikiChat.php b/MediaWikiChat.php
index 10e83e7..72efe91 100644
--- a/MediaWikiChat.php
+++ b/MediaWikiChat.php
@@ -17,7 +17,7 @@
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'MediaWikiChat',
- 'version' => '2.9.3',
+ 'version' => '2.10.0',
'author' => 'Adam Carter/UltrasonicNXT',
'url' => 'https://www.mediawiki.org/wiki/Extension:MediaWikiChat',
'descriptionmsg' => 'chat-desc',
@@ -45,7 +45,7 @@
'chat-block', 'chat-private-message', 'chat-user-is-moderator',
'chat-you-are-moderator', 'chat-joined', 'chat-left',
'chat-mod-image', 'chat-yesterday', 'chat-flood',
'chat-too-long',
- 'chat-away-link', 'chat-back-link', 'chat-user-is-away'
+ 'chat-idle-minutes', 'chat-idle-hours',
),
'dependencies' => 'mediawiki.jqueryMsg',
'localBasePath' => dirname( __FILE__ ),
diff --git a/MediaWikiChatClass.php b/MediaWikiChatClass.php
index d8e3d19..7737988 100644
--- a/MediaWikiChatClass.php
+++ b/MediaWikiChatClass.php
@@ -77,7 +77,8 @@
if ( $wgUser->isAllowed( 'chat' ) ) {
$dbr = wfGetDB( DB_SLAVE );
- $timestamp = MediaWikiChat::now() -
$wgChatOnlineTimeout;
+ $now = MediaWikiChat::now();
+ $timestamp = $now - $wgChatOnlineTimeout;
$res = $dbr->select(
'chat_users',
@@ -92,7 +93,11 @@
$data = array();
foreach ( $res as $row ) {
- $data[$row->cu_user_id] = $row->cu_away == true;
+ $away = $row->cu_away;
+
+ $data[$row->cu_user_id] = $now - $away; //
number of microseconds since user was last seen
+
+ file_put_contents( 'c:/temp/now.log', "$now -
$away" );
}
return $data;
} else {
@@ -271,4 +276,19 @@
);
}
}
+
+ /**
+ * Update the away timestamp (last time user sent message) for the
given user to now
+ *
+ * @param User $user
+ */
+ static function updateAway( User $user ) {
+ $dbw = wfGetDB( DB_MASTER );
+
+ $dbw->update(
+ 'chat_users',
+ array( 'cu_away' => MediaWikiChat::now() ),
+ array( 'cu_user_id' => $user->getId() )
+ );
+ }
}
\ No newline at end of file
diff --git a/Send.api.php b/Send.api.php
index 27da8e9..334bde5 100644
--- a/Send.api.php
+++ b/Send.api.php
@@ -56,6 +56,7 @@
$logEntry->insert();
MediaWikiChat::deleteEntryIfNeeded();
+ MediaWikiChat::updateAway( $user );
$result->addValue( $this->getModuleName(),
'timestamp', $timestamp );
diff --git a/SendPM.api.php b/SendPM.api.php
index 4ed8582..1f72a0e 100644
--- a/SendPM.api.php
+++ b/SendPM.api.php
@@ -42,6 +42,7 @@
$logEntry->insert();
MediaWikiChat::deleteEntryIfNeeded();
+ MediaWikiChat::updateAway( $user );
$result->addValue( $this->getModuleName(),
'timestamp', $timestamp );
diff --git a/SpecialChat.template.php b/SpecialChat.template.php
index b3f21c9..8d1f0be 100644
--- a/SpecialChat.template.php
+++ b/SpecialChat.template.php
@@ -43,7 +43,6 @@
<div id="mwchat-me">
<img src="" alt="" />
<span class="mwchat-useritem-user"></span>
- <a href="javascript:;"
id="mwchat-away-link"><?php echo wfMessage( 'chat-away-link' )->plain() ?></a>
</div>
</div>
<?php
diff --git a/chat_users.sql b/chat_users.sql
index 0d9ec65..9a98396 100644
--- a/chat_users.sql
+++ b/chat_users.sql
@@ -1,5 +1,5 @@
CREATE TABLE /*_*/chat_users (
cu_user_id int(10),
cu_timestamp binary(12),
- cu_away tinyint(1)
+ cu_away binary(12)
) /*$wgDBTableOptions*/;
\ No newline at end of file
diff --git a/cu_away.sql b/cu_away.sql
index 4388460..c4c40f3 100644
--- a/cu_away.sql
+++ b/cu_away.sql
@@ -1 +1 @@
-ALTER TABLE `chat_users` ADD cu_away boolean
\ No newline at end of file
+ALTER TABLE `chat_users` ADD cu_away binary(12)
\ No newline at end of file
diff --git a/cu_away_new.sql b/cu_away_new.sql
new file mode 100644
index 0000000..a7f8c85
--- /dev/null
+++ b/cu_away_new.sql
@@ -0,0 +1 @@
+ALTER TABLE `chat_users` MODIFY cu_away binary(12)
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/120369
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b28bf326ae4a816ec4dc88aba9ebb51fff6178b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiChat
Gerrit-Branch: master
Gerrit-Owner: UltrasonicNXT <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits