* (bug 25767) Add userrights properties to allusers and users query lists
authorSam Reed <reedy@users.mediawiki.org>
Tue, 4 Jan 2011 01:39:02 +0000 (01:39 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Tue, 4 Jan 2011 01:39:02 +0000 (01:39 +0000)
First part of this bug. Listing of all rights that users have

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

index 2a6fa1d..aee4212 100644 (file)
@@ -50,6 +50,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
                        $fld_blockinfo = isset( $prop['blockinfo'] );
                        $fld_editcount = isset( $prop['editcount'] );
                        $fld_groups = isset( $prop['groups'] );
+                       $fld_rights = isset( $prop['rights'] );
                        $fld_registration = isset( $prop['registration'] );
                } else {
                        $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration = false;
@@ -83,7 +84,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
                        $this->addWhere( 'u1.user_editcount > 0' );
                }
 
-               if ( $fld_groups ) {
+               if ( $fld_groups || $fld_rights ) {
                        // Show the groups the given users belong to
                        // request more than needed to avoid not getting all rows that belong to one user
                        $groupCount = count( User::getAllGroups() );
@@ -188,6 +189,15 @@ class ApiQueryAllUsers extends ApiQueryBase {
                                $lastUserData['groups'][] = $row->ug_group2;
                                $result->setIndexedTagName( $lastUserData['groups'], 'g' );
                        }
+
+                   if ( $fld_rights && !is_null( $row->ug_group2 ) ) {
+                               if ( !isset( $lastUserData['rights'] ) ) {
+                                       $lastUserData['rights'] = User::getGroupPermissions( User::getImplicitGroups() );
+                           }
+
+                       $lastUserData['rights'] = array_merge( $lastUserData['rights'], User::getGroupPermissions( array( $row->ug_group2 ) ) );
+                       $result->setIndexedTagName( $lastUserData['rights'], 'r' );
+                   }
                }
 
                if ( is_array( $lastUserData ) ) {
@@ -244,6 +254,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
                                '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 groups that the user has',
                                ' editcount     - Adds the edit count of the user',
                                ' registration  - Adds the timestamp of when the user registered',
                                ),
index 112fbb3..a664331 100644 (file)
@@ -101,11 +101,9 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        $vals['options'] = $wgUser->getOptions();
                }
 
-               if (
-                       isset( $this->prop['preferencestoken'] ) &&
+               if ( isset( $this->prop['preferencestoken'] ) &&
                        is_null( $this->getMain()->getRequest()->getVal( 'callback' ) )
-               )
-               {
+               ) {
                        $vals['preferencestoken'] = $wgUser->editToken();
                }
 
index 3432d15..fa90c38 100644 (file)
@@ -144,6 +144,12 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                                        $data[$name]['groups'][] = $row->ug_group;
                                }
 
+                               if ( isset( $this->prop['rights'] ) && !isset( $data[$name]['rights'] ) ) {
+                                       // User::getRights() may return duplicate values, strip them
+                                       $data[$name]['rights'] = array_values( array_unique( $user->getRights() ) );
+                                       $result->setIndexedTagName( $data[$name]['rights'], 'r' );      // even if empty
+                               }
+
                                if ( isset( $this->prop['blockinfo'] ) && !is_null( $row->blocker_name ) ) {
                                        $data[$name]['blockedby'] = $row->blocker_name;
                                        $data[$name]['blockreason'] = $row->ipb_reason;
@@ -251,6 +257,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                                ApiBase::PARAM_TYPE => array(
                                        'blockinfo',
                                        'groups',
+                                       'rights',
                                        'editcount',
                                        'registration',
                                        'emailable',
@@ -273,7 +280,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                                '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',
+                               '  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]]',