Bug 31199 - Fix notification of implicit groups so it doesn't massively change json...
authorSam Reed <reedy@users.mediawiki.org>
Wed, 28 Sep 2011 16:36:17 +0000 (16:36 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Wed, 28 Sep 2011 16:36:17 +0000 (16:36 +0000)
Needs merging to 1.18, 1.18wmf1 and pushing to site

includes/api/ApiQueryAllUsers.php
includes/api/ApiQueryUsers.php

index 6f67dc9..6e0092b 100644 (file)
@@ -51,8 +51,9 @@ class ApiQueryAllUsers extends ApiQueryBase {
                        $fld_groups = isset( $prop['groups'] );
                        $fld_rights = isset( $prop['rights'] );
                        $fld_registration = isset( $prop['registration'] );
+                   $fld_implicitgroups = isset( $prop['implicitgroups'] );
                } else {
-                       $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration = $fld_rights = false;
+                       $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration = $fld_rights = $fld_implicitgroups = false;
                }
 
                $limit = $params['limit'];
@@ -246,6 +247,10 @@ class ApiQueryAllUsers extends ApiQueryBase {
                                $result->setIndexedTagName( $lastUserData['groups'], 'g' );
                        }
 
+                       if ( $fld_implicitgroups && !isset( $lastUserData['implicitgroups'] ) ) {
+                               $lastUserData['implicitgroups'] = ApiQueryUsers::getAutoGroups( User::newFromName( $lastUser ) );
+                               $result->setIndexedTagName( $lastUserData['implicitgroups'], 'g' );
+                       }
                        if ( $fld_rights ) {
                                if ( !isset( $lastUserData['rights'] ) ) {
                                        $lastUserData['rights'] =  User::getGroupPermissions( User::newFromName( $lastUser )->getAutomaticGroups() );
@@ -304,6 +309,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
                                ApiBase::PARAM_TYPE => array(
                                        'blockinfo',
                                        'groups',
+                                       'implicitgroups',
                                        'rights',
                                        'editcount',
                                        'registration'
@@ -333,11 +339,12 @@ class ApiQueryAllUsers extends ApiQueryBase {
                        'rights' => 'Limit users to given right(s)',
                        'prop' => array(
                                'What pieces of information to include.',
-                               ' blockinfo     - Adds the information about a current block on the user',
-                               ' groups        - Lists groups that the user is in. This uses more server resources and may return fewer results than the limit',
-                               ' rights        - Lists rights that the user has',
-                               ' editcount     - Adds the edit count of the user',
-                               ' registration  - Adds the timestamp of when the user registered if available (may be blank)',
+                               ' blockinfo      - Adds the information about a current block on the user',
+                               ' groups         - Lists groups that the user is in. This uses more server resources and may return fewer results than the limit',
+                               ' implicitgroups - Lists all the groups the user is automatically in',
+                               ' rights         - Lists rights that the user has',
+                               ' editcount      - Adds the edit count of the user',
+                               ' registration   - Adds the timestamp of when the user registered if available (may be blank)',
                                ),
                        'limit' => 'How many total user names to return',
                        'witheditsonly' => 'Only list users who have made edits',
index f54f01d..a76bfed 100644 (file)
@@ -152,6 +152,10 @@ class ApiQueryUsers extends ApiQueryBase {
                                        }
                                }
 
+                               if ( isset( $this->prop['implicitgroups'] ) && !isset( $data[$name]['implicitgroups'] ) ) {
+                                       $data[$name]['implicitgroups'] =  self::getAutoGroups( $user );
+                               }
+
                                if ( isset( $this->prop['rights'] ) ) {
                                        if ( !isset( $data[$name]['rights'] ) ) {
                                                $data[$name]['rights'] = User::getGroupPermissions( $user->getAutomaticGroups() );
@@ -226,6 +230,9 @@ class ApiQueryUsers extends ApiQueryBase {
                                if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) ) {
                                        $result->setIndexedTagName( $data[$u]['groups'], 'g' );
                                }
+                               if ( isset( $this->prop['implicitgroups'] ) && isset( $data[$u]['implicitgroups'] ) ) {
+                                       $result->setIndexedTagName( $data[$u]['implicitgroups'], 'g' );
+                               }
                                if ( isset( $this->prop['rights'] ) && isset( $data[$u]['rights'] ) ) {
                                        $result->setIndexedTagName( $data[$u]['rights'], 'r' );
                                }
@@ -256,12 +263,7 @@ class ApiQueryUsers extends ApiQueryBase {
                        $groups[] = 'user';
                }
 
-               $builtGroups = array();
-               foreach( array_merge( $groups, Autopromote::getAutopromoteGroups( $user ) ) as $i => $group ) {
-                       $builtGroups[$i] = array( 'implicit' => '' );
-                       ApiResult::setContent( $builtGroups[$i], $group );
-               }
-               return $builtGroups;
+               return array_merge( $groups, Autopromote::getAutopromoteGroups( $user ) );
        }
 
        public function getCacheMode( $params ) {
@@ -280,6 +282,7 @@ class ApiQueryUsers extends ApiQueryBase {
                                ApiBase::PARAM_TYPE => array(
                                        'blockinfo',
                                        'groups',
+                                       'implicitgroups',
                                        'rights',
                                        'editcount',
                                        'registration',
@@ -301,13 +304,14 @@ class ApiQueryUsers extends ApiQueryBase {
                return array(
                        'prop' => array(
                                'What pieces of information to include',
-                               '  blockinfo    - Tags if the user is blocked, by whom, and for what reason',
-                               '  groups       - Lists all the groups the user(s) belongs to',
-                               '  rights       - Lists all the rights the user(s) has',
-                               '  editcount    - Adds the user\'s edit count',
-                               '  registration - Adds the user\'s registration timestamp',
-                               '  emailable    - Tags if the user can and wants to receive e-mail through [[Special:Emailuser]]',
-                               '  gender       - Tags the gender of the user. Returns "male", "female", or "unknown"',
+                               '  blockinfo      - Tags if the user is blocked, by whom, and for what reason',
+                               '  groups         - Lists all the groups the user(s) belongs to',
+                               '  implicitgroups - Lists all the groups a user is automatically a member of',
+                               '  rights         - Lists all the rights the user(s) has',
+                               '  editcount      - Adds the user\'s edit count',
+                               '  registration   - Adds the user\'s registration timestamp',
+                               '  emailable      - Tags if the user can and wants to receive e-mail through [[Special:Emailuser]]',
+                               '  gender         - Tags the gender of the user. Returns "male", "female", or "unknown"',
                        ),
                        'users' => 'A list of users to obtain the same information for',
                        'token' => 'Which tokens to obtain for each user',