<?php
/**
- * API for MediaWiki 1.8+
+ *
*
* Created on July 7, 2007
*
$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;
$this->addWhere( 'u1.user_name' . $db->buildLike( $this->keyToTitle( $params['prefix'] ), $db->anyString() ) );
}
+ if ( !is_null( $params['rights'] ) ) {
+ $groups = array();
+ foreach( $params['rights'] as $r ) {
+ $groups = array_merge( $groups, User::getGroupsWithPermission( $r ) );
+ }
+
+ $groups = array_diff( array_unique( $groups ), User::getImplicitGroups() );
+
+ if ( is_null( $params['group'] ) ) {
+ $params['group'] = $groups;
+ } else {
+ $params['group'] = array_unique( array_merge( $params['group'], $groups ) );
+ }
+ }
+
if ( !is_null( $params['group'] ) ) {
$useIndex = false;
// Filter only users that belong to a given group
$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() );
} else {
$sqlLimit = $limit + 1;
}
+
if ( $fld_blockinfo ) {
$this->addTables( 'ipblocks' );
$this->addTables( 'user', 'u2' );
$this->addOption( 'LIMIT', $sqlLimit );
- $this->addFields( 'u1.user_name' );
+ $this->addFields( array(
+ 'u1.user_name',
+ 'u1.user_id'
+ ) );
$this->addFieldsIf( 'u1.user_editcount', $fld_editcount );
$this->addFieldsIf( 'u1.user_registration', $fld_registration );
// The setContinue... is more complex because of this, and takes into account the higher sql limit
// to make sure all rows that belong to the same user are received.
- $row = $db->fetchObject( $res );
foreach ( $res as $row ) {
$count++;
if ( is_array( $lastUserData ) ) {
$fit = $result->addValue( array( 'query', $this->getModuleName() ),
null, $lastUserData );
+
+ $lastUserData = null;
+
if ( !$fit ) {
$this->setContinueEnumParameter( 'from',
$this->keyToTitle( $lastUserData['name'] ) );
// Record new user's data
$lastUser = $row->user_name;
- $lastUserData = array( 'name' => $lastUser );
+ $lastUserData = array(
+ 'name' => $lastUser,
+ 'userid' => $row->user_id,
+ );
if ( $fld_blockinfo && !is_null( $row->blocker_name ) ) {
$lastUserData['blockedby'] = $row->blocker_name;
$lastUserData['blockreason'] = $row->ipb_reason;
// Add user's group info
if ( $fld_groups && !is_null( $row->ug_group2 ) ) {
+ if ( !isset( $lastUserData['groups'] ) ) {
+ $lastUserData['groups'] = ApiQueryUsers::getAutoGroups( User::newFromName( $lastUser ) );
+ }
+
$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_unique( array_merge( $lastUserData['rights'],
+ User::getGroupPermissions( array( $row->ug_group2 ) ) ) );
+ $result->setIndexedTagName( $lastUserData['rights'], 'r' );
+ }
+ }
+
+ if ( is_array( $lastUserData ) ) {
+ $fit = $result->addValue( array( 'query', $this->getModuleName() ),
+ null, $lastUserData );
+ if ( !$fit ) {
+ $this->setContinueEnumParameter( 'from',
+ $this->keyToTitle( $lastUserData['name'] ) );
+ }
}
$result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'u' );
'to' => null,
'prefix' => null,
'group' => array(
- ApiBase::PARAM_TYPE => User::getAllGroups()
+ ApiBase::PARAM_TYPE => User::getAllGroups(),
+ ApiBase::PARAM_ISMULTI => true,
+ ),
+ 'rights' => array(
+ ApiBase::PARAM_TYPE => User::getAllRights(),
+ ApiBase::PARAM_ISMULTI => true,
),
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => array(
'blockinfo',
'groups',
+ 'rights',
'editcount',
'registration'
)
'from' => 'The user name to start enumerating from',
'to' => 'The user name to stop enumerating at',
'prefix' => 'Search for all users that begin with this value',
- 'group' => 'Limit users to a given group name',
+ 'group' => 'Limit users to given group name(s)',
+ 'rights' => 'Limit users to given right(s)',
'prop' => array(
'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',
+ ' groups - Lists groups that the user is in. This uses more server resources and may return fewer results than the limit',
+ ' rights - Lists rights that the user has',
' editcount - Adds the edit count of the user',
' registration - Adds the timestamp of when the user registered',
- '`groups` property uses more server resources and may return fewer results than the limit' ),
+ ),
'limit' => 'How many total user names to return',
'witheditsonly' => 'Only list users who have made edits',
);