[MediaWiki-commits] [Gerrit] Add users being away - change (mediawiki...MediaWikiChat)

2014-03-09 Thread UltrasonicNXT (Code Review)
UltrasonicNXT has submitted this change and it was merged.

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
Bump version
Change online users format

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, 146 insertions(+), 14 deletions(-)

Approvals:
  UltrasonicNXT: Verified; Looks good to me, approved



diff --git a/Away.api.php b/Away.api.php
new file mode 100644
index 000..7033855
--- /dev/null
+++ b/Away.api.php
@@ -0,0 +1,58 @@
+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 ) ) {
  

[MediaWiki-commits] [Gerrit] Add users being away - change (mediawiki...MediaWikiChat)

2014-03-09 Thread UltrasonicNXT (Code Review)
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 000..7033855
--- /dev/null
+++ b/Away.api.php
@@ -0,0 +1,58 @@
+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_