r87180 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87179‎ | r87180 | r87181 >
Date:00:24, 1 May 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
* (bug 28225) Allow hiding of user groups in list=allusers

Yay, a LEFT OUTER JOIN
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllUsers.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllUsers.php
@@ -85,6 +85,10 @@
8686 }
8787 }
8888
 89+ if ( !is_null( $params['group'] ) && !is_null( $params['excludegroup'] ) ) {
 90+ $this->dieUsage( 'group and excludegroup cannot be used together', 'group-excludegroup' );
 91+ }
 92+
8993 if ( !is_null( $params['group'] ) && count( $params['group'] ) ) {
9094 $useIndex = false;
9195 // Filter only users that belong to a given group
@@ -93,6 +97,23 @@
9498 'ug1.ug_group' => $params['group'] ) ) ) );
9599 }
96100
 101+ if ( !is_null( $params['excludegroup'] ) && count( $params['excludegroup'] ) ) {
 102+ $useIndex = false;
 103+ // Filter only users don't belong to a given group
 104+ $this->addTables( 'user_groups', 'ug1' );
 105+
 106+ if ( count( $params['excludegroup'] ) == 1 ) {
 107+ $exclude = array( 'ug1.ug_group = ' . $db->addQuotes( $params['excludegroup'][0] ) );
 108+ } else {
 109+ $exclude = array( $db->makeList( array( 'ug1.ug_group' => $params['excludegroup'] ), LIST_OR ) );
 110+ }
 111+ $this->addJoinConds( array( 'ug1' => array( 'LEFT OUTER JOIN',
 112+ array_merge( array( 'ug1.ug_user=user_id' ), $exclude )
 113+ )
 114+ ) );
 115+ $this->addWhere( 'ug1.ug_user IS NULL' );
 116+ }
 117+
97118 if ( $params['witheditsonly'] ) {
98119 $this->addWhere( 'user_editcount > 0' );
99120 }
@@ -254,6 +275,7 @@
255276 }
256277
257278 public function getAllowedParams() {
 279+ $userGroups = User::getAllGroups();
258280 return array(
259281 'from' => null,
260282 'to' => null,
@@ -266,9 +288,13 @@
267289 ),
268290 ),
269291 'group' => array(
270 - ApiBase::PARAM_TYPE => User::getAllGroups(),
 292+ ApiBase::PARAM_TYPE => $userGroups,
271293 ApiBase::PARAM_ISMULTI => true,
272294 ),
 295+ 'excludegroup' => array(
 296+ ApiBase::PARAM_TYPE => $userGroups,
 297+ ApiBase::PARAM_ISMULTI => true,
 298+ ),
273299 'rights' => array(
274300 ApiBase::PARAM_TYPE => User::getAllRights(),
275301 ApiBase::PARAM_ISMULTI => true,
@@ -303,6 +329,7 @@
304330 'prefix' => 'Search for all users that begin with this value',
305331 'dir' => 'Direction to sort in',
306332 'group' => 'Limit users to given group name(s)',
 333+ 'excludegroup' => 'Exclude users in given group name(s)',
307334 'rights' => 'Limit users to given right(s)',
308335 'prop' => array(
309336 'What pieces of information to include.',
@@ -322,6 +349,12 @@
323350 return 'Enumerate all registered users';
324351 }
325352
 353+ public function getPossibleErrors() {
 354+ return array_merge( parent::getPossibleErrors(), array(
 355+ array( 'code' => 'group-excludegroup', 'info' => 'group and excludegroup cannot be used together' ),
 356+ ) );
 357+ }
 358+
326359 protected function getExamples() {
327360 return array(
328361 'api.php?action=query&list=allusers&aufrom=Y',
Index: trunk/phase3/RELEASE-NOTES
@@ -368,6 +368,7 @@
369369 * (bug 27179) API: List of extension tags through meta=siteinfo
370370 * Get a list of function hooks through meta=siteinfo
371371 * Get a list of all subscribed hooks, and those subscribers
 372+* (bug 28225) Allow hiding of user groups in list=allusers
372373
373374 === Languages updated in 1.18 ===
374375

Follow-up revisions

RevisionCommit summaryAuthorDate
r87183Remove unneeded manual quoting from r87180reedy11:20, 1 May 2011

Comments

#Comment by Catrope (talk | contribs)   08:23, 1 May 2011
+				$exclude = array( 'ug1.ug_group = ' . $db->addQuotes( $params['excludegroup'][0] ) );

Can't you use 'ug1.ug_group' => $params['excludegroup'][0] here?

#Comment by Reedy (talk | contribs)   11:18, 1 May 2011

Yup, was an artifact from when I was poking at it using != etc. Will clean it up

Status & tagging log