From 5283490bddd9acbe18afcb7c75f43b019f719f37 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 1 May 2011 00:24:39 +0000 Subject: [PATCH] * (bug 28225) Allow hiding of user groups in list=allusers Yay, a LEFT OUTER JOIN --- RELEASE-NOTES | 1 + includes/api/ApiQueryAllUsers.php | 35 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 13e2a108dd..d990038ebc 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -368,6 +368,7 @@ PHP if you have not done so prior to upgrading MediaWiki. * (bug 27179) API: List of extension tags through meta=siteinfo * Get a list of function hooks through meta=siteinfo * Get a list of all subscribed hooks, and those subscribers +* (bug 28225) Allow hiding of user groups in list=allusers === Languages updated in 1.18 === diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index 7552da9815..5f1469fb0e 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -85,6 +85,10 @@ class ApiQueryAllUsers extends ApiQueryBase { } } + if ( !is_null( $params['group'] ) && !is_null( $params['excludegroup'] ) ) { + $this->dieUsage( 'group and excludegroup cannot be used together', 'group-excludegroup' ); + } + if ( !is_null( $params['group'] ) && count( $params['group'] ) ) { $useIndex = false; // Filter only users that belong to a given group @@ -93,6 +97,23 @@ class ApiQueryAllUsers extends ApiQueryBase { 'ug1.ug_group' => $params['group'] ) ) ) ); } + if ( !is_null( $params['excludegroup'] ) && count( $params['excludegroup'] ) ) { + $useIndex = false; + // Filter only users don't belong to a given group + $this->addTables( 'user_groups', 'ug1' ); + + if ( count( $params['excludegroup'] ) == 1 ) { + $exclude = array( 'ug1.ug_group = ' . $db->addQuotes( $params['excludegroup'][0] ) ); + } else { + $exclude = array( $db->makeList( array( 'ug1.ug_group' => $params['excludegroup'] ), LIST_OR ) ); + } + $this->addJoinConds( array( 'ug1' => array( 'LEFT OUTER JOIN', + array_merge( array( 'ug1.ug_user=user_id' ), $exclude ) + ) + ) ); + $this->addWhere( 'ug1.ug_user IS NULL' ); + } + if ( $params['witheditsonly'] ) { $this->addWhere( 'user_editcount > 0' ); } @@ -254,6 +275,7 @@ class ApiQueryAllUsers extends ApiQueryBase { } public function getAllowedParams() { + $userGroups = User::getAllGroups(); return array( 'from' => null, 'to' => null, @@ -266,7 +288,11 @@ class ApiQueryAllUsers extends ApiQueryBase { ), ), 'group' => array( - ApiBase::PARAM_TYPE => User::getAllGroups(), + ApiBase::PARAM_TYPE => $userGroups, + ApiBase::PARAM_ISMULTI => true, + ), + 'excludegroup' => array( + ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true, ), 'rights' => array( @@ -303,6 +329,7 @@ class ApiQueryAllUsers extends ApiQueryBase { 'prefix' => 'Search for all users that begin with this value', 'dir' => 'Direction to sort in', 'group' => 'Limit users to given group name(s)', + 'excludegroup' => 'Exclude users in given group name(s)', 'rights' => 'Limit users to given right(s)', 'prop' => array( 'What pieces of information to include.', @@ -322,6 +349,12 @@ class ApiQueryAllUsers extends ApiQueryBase { return 'Enumerate all registered users'; } + public function getPossibleErrors() { + return array_merge( parent::getPossibleErrors(), array( + array( 'code' => 'group-excludegroup', 'info' => 'group and excludegroup cannot be used together' ), + ) ); + } + protected function getExamples() { return array( 'api.php?action=query&list=allusers&aufrom=Y', -- 2.20.1