* (bug 28225) Allow hiding of user groups in list=allusers
authorSam Reed <reedy@users.mediawiki.org>
Sun, 1 May 2011 00:24:39 +0000 (00:24 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 1 May 2011 00:24:39 +0000 (00:24 +0000)
Yay, a LEFT OUTER JOIN

RELEASE-NOTES
includes/api/ApiQueryAllUsers.php

index 13e2a10..d990038 100644 (file)
@@ -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 ===
 
index 7552da9..5f1469f 100644 (file)
@@ -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',