(bug 36812) SpecialActiveUsers: Use right instead of group for bots.
authorPlatonides <platonides@gmail.com>
Sun, 13 May 2012 13:51:28 +0000 (15:51 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Fri, 29 Jun 2012 03:35:22 +0000 (05:35 +0200)
Test with:
* $wgGroupPermissions['script'] = $wgGroupPermissions['bot'];
* Add a user to it that made an edit recently
* With this fix it will be hidden on SpecialActiveUsers?hidebots=1
  without it will remain visible.

Change-Id: Ie0b88d7982a3d111c6ba6c456cfc02229f1339df

RELEASE-NOTES-1.20
includes/specials/SpecialActiveusers.php

index 709f2ea..bc04a8d 100644 (file)
@@ -130,6 +130,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 37708) mw.Uri.clone() should make a deep copy.
 * (bug 38024) ResourceLoader should not create empty stylesheets for modules
   that don't have stylesheets.
+* (bug 36812) Special:ActiveUsers "Hide bots" should hide users from any group
+  having the "bot" user right, instead of just the default "bot" user group.
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
index 06a4694..156b5f2 100644 (file)
@@ -40,7 +40,12 @@ class ActiveUsersPager extends UsersPager {
        /**
         * @var Array
         */
-       protected $groups;
+       protected $hideGroups = array();
+
+       /**
+        * @var Array
+        */
+       protected $hideRights = array();
 
        /**
         * @param $context IContextSource
@@ -73,12 +78,11 @@ class ActiveUsersPager extends UsersPager {
 
                $this->opts->fetchValuesFromRequest( $this->getRequest() );
 
-               $this->groups = array();
                if ( $this->opts->getValue( 'hidebots' ) == 1 ) {
-                       $this->groups['bot'] = true;
+                       $this->hideRights[] = 'bot';
                }
                if ( $this->opts->getValue( 'hidesysops' ) == 1 ) {
-                       $this->groups['sysop'] = true;
+                       $this->hideGroups[] = 'sysop';
                }
        }
 
@@ -127,12 +131,30 @@ class ActiveUsersPager extends UsersPager {
                $lang = $this->getLanguage();
 
                $list = array();
-               foreach( self::getGroups( $row->user_id ) as $group ) {
-                       if ( isset( $this->groups[$group] ) ) {
+               $user = User::newFromId( $row->user_id );
+
+               // User right filter
+               foreach( $this->hideRights as $right ) {
+                       // Calling User::getRights() within the loop so that
+                       // if the hideRights() filter is empty, we don't have to
+                       // trigger the lazy-init of the big userrights array in the
+                       // User object
+                       if ( in_array( $right, $user->getRights() ) ) {
+                               return '';
+                       }
+               }
+
+               // User group filter
+               // Note: This is a different loop than for user rights,
+               // because we're reusing it to build the group links
+               // at the same time
+               foreach( $user->getGroups() as $group ) {
+                       if ( in_array( $group, $this->hideGroups ) ) {
                                return '';
                        }
                        $list[] = self::buildGroupLink( $group, $userName );
                }
+
                $groups = $lang->commaList( $list );
 
                $item = $lang->specialList( $ulinks, $groups );