From e1bcab1ab8ac648eef18e68e0cfd6d8c09a2ae21 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Tue, 4 Jan 2011 01:39:02 +0000 Subject: [PATCH] * (bug 25767) Add userrights properties to allusers and users query lists First part of this bug. Listing of all rights that users have --- includes/api/ApiQueryAllUsers.php | 13 ++++++++++++- includes/api/ApiQueryUserInfo.php | 6 ++---- includes/api/ApiQueryUsers.php | 9 ++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index 2a6fa1db83..aee4212fd1 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -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', ), diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index 112fbb339a..a6643319b0 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -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(); } diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index 3432d15b73..fa90c389a2 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -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]]', -- 2.20.1