UltrasonicNXT has uploaded a new change for review. https://gerrit.wikimedia.org/r/117690
Change subject: Add users being away ...................................................................... Add users being away Via a toggle in the mwchat-me section. An away user will have a lighter background color, greyer text, a tooltip, and on some browsers, a greyscale avatar Requires update.php due to field addition in chat_users table Change-Id: I99675f26f00c517784b021ca69e0edd24496ba7d --- A Away.api.php M GetNew.api.php M MediaWikiChat.css M MediaWikiChat.hooks.php M MediaWikiChat.i18n.php M MediaWikiChat.js M MediaWikiChat.php M MediaWikiChatClass.php M SpecialChat.template.php M chat_users.sql A cu_away.sql 11 files changed, 150 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiChat refs/changes/90/117690/1 diff --git a/Away.api.php b/Away.api.php new file mode 100644 index 0000000..7033855 --- /dev/null +++ b/Away.api.php @@ -0,0 +1,58 @@ +<?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 0bebb4f..2c87c87 100644 --- a/GetNew.api.php +++ b/GetNew.api.php @@ -17,10 +17,10 @@ $thisCheck = MediaWikiChat::now(); $res = $dbr->selectField( - 'chat_users', - array( 'cu_timestamp' ), - array( 'cu_user_id' => $wgUser->getId() ), - __METHOD__ + 'chat_users', + 'cu_timestamp', + array( 'cu_user_id' => $wgUser->getId() ), + __METHOD__ ); $lastCheck = strval( $res ); @@ -120,7 +120,7 @@ $users[$wgUser->getId()] = true; // ensure current user is in the users list $onlineUsers = MediaWikiChat::getOnline(); - foreach ( $onlineUsers as $id ) { + foreach ( $onlineUsers as $id => $away ) { $users[$id] = true; // ensure all online users are present in the users list } $genderCache = GenderCache::singleton(); @@ -132,9 +132,12 @@ if ( $wgChatSocialAvatars ) { $result->addValue( array( $mName, 'users', $idString ), 'avatar', MediaWikiChat::getAvatar( $id ) ); } - if ( in_array( $id, $onlineUsers ) ) { + 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 ); + } $groups = $userObject->getGroups(); if ( in_array( 'chatmod', $groups ) || in_array( 'sysop', $groups ) ) { $result->addValue( array( $mName, 'users', $idString ), 'mod', true ); diff --git a/MediaWikiChat.css b/MediaWikiChat.css index 9f0967c..c4493e6 100644 --- a/MediaWikiChat.css +++ b/MediaWikiChat.css @@ -138,4 +138,26 @@ } #mwchat-options { margin-top: 10px; +} +#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 7725fd4..f918e48 100644 --- a/MediaWikiChat.hooks.php +++ b/MediaWikiChat.hooks.php @@ -59,6 +59,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' ); return true; } @@ -79,7 +80,7 @@ if ( count( $users ) ) { $arr = array(); - foreach ( $users as $id ) { + foreach ( $users as $id => $away ) { $user = User::newFromId( $id ); $avatar = MediaWikiChat::getAvatar( $id ); $page = str_replace( '$1', 'User:' . rawurlencode( $user->getName() ), $wgArticlePath ); diff --git a/MediaWikiChat.i18n.php b/MediaWikiChat.i18n.php index 3d37caa..47aa7a3 100644 --- a/MediaWikiChat.i18n.php +++ b/MediaWikiChat.i18n.php @@ -81,7 +81,11 @@ 'tog-chat-ping-mention' => 'Play a sound on receiving mentions', 'tog-chat-ping-pm' => 'Play a sound on receiving private messages', 'tog-chat-ping-message' => 'Play a sound on receiving normal messages', - 'prefs-chat' => 'Chat' + 'prefs-chat' => 'Chat', + + 'chat-away-link' => 'online', + 'chat-back-link' => 'away', + 'chat-user-is-away' => 'this user is away' ); /** Message documentation (Message documentation) diff --git a/MediaWikiChat.js b/MediaWikiChat.js index 2d88a51..d5f65c6 100644 --- a/MediaWikiChat.js +++ b/MediaWikiChat.js @@ -10,6 +10,7 @@ userData: [], focussed: true, title: document.title, + away: false, pad: function( num, size ) { var s = num + ''; @@ -146,6 +147,18 @@ MediaWikiChat.doUsers( onlineUsers ); + 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() ); + } + } + for ( var messageTimestamp in data.messages ) { var message = data.messages[messageTimestamp]; MediaWikiChat.addMessage( @@ -195,6 +208,9 @@ MediaWikiChat.addMe(); } ); + }, + + doAway: function( id, away ) { }, scrollToBottom: function() { @@ -602,6 +618,33 @@ $( '#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 ); + } ); + } + + } ); } ); $( window ).blur( function() { diff --git a/MediaWikiChat.php b/MediaWikiChat.php index 5c62663..632a321 100644 --- a/MediaWikiChat.php +++ b/MediaWikiChat.php @@ -17,7 +17,7 @@ $wgExtensionCredits['specialpage'][] = array( 'path' => __FILE__, 'name' => 'MediaWikiChat', - 'version' => '2.8.0', + 'version' => '2.9.0', 'author' => 'Adam Carter/UltrasonicNXT', 'url' => 'https://www.mediawiki.org/wiki/Extension:MediaWikiChat', 'descriptionmsg' => 'chat-desc', @@ -45,6 +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' ), 'dependencies' => 'mediawiki.jqueryMsg', 'localBasePath' => dirname( __FILE__ ), @@ -84,10 +85,12 @@ $wgAutoloadClasses['ChatSendAPI'] = $dir . 'Send.api.php'; $wgAutoloadClasses['ChatSendPMAPI'] = $dir . 'SendPM.api.php'; $wgAutoloadClasses['ChatKickAPI'] = $dir . 'Kick.api.php'; +$wgAutoloadClasses['ChatAwayAPI'] = $dir . 'Away.api.php'; $wgAPIModules['chatgetnew'] = 'ChatGetNewAPI'; $wgAPIModules['chatsend'] = 'ChatSendAPI'; $wgAPIModules['chatsendpm'] = 'ChatSendPMAPI'; $wgAPIModules['chatkick'] = 'ChatKickAPI'; +$wgAPIModules['chataway'] = 'ChatAwayAPI'; // Logs $wgLogTypes[] = 'chat'; diff --git a/MediaWikiChatClass.php b/MediaWikiChatClass.php index 495abec..d8e3d19 100644 --- a/MediaWikiChatClass.php +++ b/MediaWikiChatClass.php @@ -81,7 +81,7 @@ $res = $dbr->select( 'chat_users', - 'cu_user_id', + array( 'cu_user_id', 'cu_away' ), array( "cu_timestamp > $timestamp", "cu_user_id != {$wgUser->getId()}" @@ -92,9 +92,7 @@ $data = array(); foreach ( $res as $row ) { - $id = $row->cu_user_id; - - $data[] = $id; + $data[$row->cu_user_id] = $row->cu_away == true; } return $data; } else { diff --git a/SpecialChat.template.php b/SpecialChat.template.php index 8d1f0be..5ecd2ce 100644 --- a/SpecialChat.template.php +++ b/SpecialChat.template.php @@ -30,7 +30,7 @@ </div> <div id="mwchat-type"> <input type="text" placeholder="<?php echo wfMessage( 'chat-type-your-message' )->plain() ?>" /> - </div> + </div> <div id="mwchat-options"> <a target="_blank" href="<?php echo SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-misc' )->getFullURL(); ?>"><?php echo wfMessage( 'chat-change-preferences' ); ?></a> </div> @@ -43,6 +43,7 @@ <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 0d1fbba..0d9ec65 100644 --- a/chat_users.sql +++ b/chat_users.sql @@ -1,4 +1,5 @@ CREATE TABLE /*_*/chat_users ( cu_user_id int(10), - cu_timestamp binary(12) + cu_timestamp binary(12), + cu_away tinyint(1) ) /*$wgDBTableOptions*/; \ No newline at end of file diff --git a/cu_away.sql b/cu_away.sql new file mode 100644 index 0000000..4388460 --- /dev/null +++ b/cu_away.sql @@ -0,0 +1 @@ +ALTER TABLE `chat_users` ADD cu_away boolean \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/117690 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I99675f26f00c517784b021ca69e0edd24496ba7d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MediaWikiChat Gerrit-Branch: master Gerrit-Owner: UltrasonicNXT <adamr_car...@btinternet.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits