summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryAllUsers.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryAllUsers.php')
-rw-r--r--includes/api/ApiQueryAllUsers.php103
1 files changed, 84 insertions, 19 deletions
diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php
index ac112ef9..7f50cbad 100644
--- a/includes/api/ApiQueryAllUsers.php
+++ b/includes/api/ApiQueryAllUsers.php
@@ -4,7 +4,7 @@
*
* Created on July 7, 2007
*
- * Copyright © 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2007 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -34,6 +34,16 @@ class ApiQueryAllUsers extends ApiQueryBase {
parent::__construct( $query, $moduleName, 'au' );
}
+ /**
+ * This function converts the user name to a canonical form
+ * which is stored in the database.
+ * @param String $name
+ * @return String
+ */
+ private function getCanonicalUserName( $name ) {
+ return str_replace( '_', ' ', $name );
+ }
+
public function execute() {
$db = $this->getDB();
$params = $this->extractRequestParams();
@@ -57,8 +67,8 @@ class ApiQueryAllUsers extends ApiQueryBase {
$useIndex = true;
$dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
- $from = is_null( $params['from'] ) ? null : $this->keyToTitle( $params['from'] );
- $to = is_null( $params['to'] ) ? null : $this->keyToTitle( $params['to'] );
+ $from = is_null( $params['from'] ) ? null : $this->getCanonicalUserName( $params['from'] );
+ $to = is_null( $params['to'] ) ? null : $this->getCanonicalUserName( $params['to'] );
# MySQL doesn't seem to use 'equality propagation' here, so like the
# ActiveUsers special page, we have to use rc_user_text for some cases.
@@ -68,7 +78,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
if ( !is_null( $params['prefix'] ) ) {
$this->addWhere( $userFieldToSort .
- $db->buildLike( $this->keyToTitle( $params['prefix'] ), $db->anyString() ) );
+ $db->buildLike( $this->getCanonicalUserName( $params['prefix'] ), $db->anyString() ) );
}
if ( !is_null( $params['rights'] ) ) {
@@ -142,11 +152,11 @@ class ApiQueryAllUsers extends ApiQueryBase {
'INNER JOIN', 'rc_user_text=user_name'
) ) );
- $this->addFields( 'COUNT(*) AS recentedits' );
+ $this->addFields( array( 'recentedits' => 'COUNT(*)' ) );
- $this->addWhere( "rc_log_type IS NULL OR rc_log_type != 'newusers'" );
+ $this->addWhere( 'rc_log_type IS NULL OR rc_log_type != ' . $db->addQuotes( 'newusers' ) );
$timestamp = $db->timestamp( wfTimestamp( TS_UNIX ) - $wgActiveUserDays*24*3600 );
- $this->addWhere( "rc_timestamp >= {$db->addQuotes( $timestamp )}" );
+ $this->addWhere( 'rc_timestamp >= ' . $db->addQuotes( $timestamp ) );
$this->addOption( 'GROUP BY', $userFieldToSort );
}
@@ -190,15 +200,14 @@ class ApiQueryAllUsers extends ApiQueryBase {
$lastUserData = null;
if ( !$fit ) {
- $this->setContinueEnumParameter( 'from',
- $this->keyToTitle( $lastUserData['name'] ) );
+ $this->setContinueEnumParameter( 'from', $lastUserData['name'] );
break;
}
}
if ( $count > $limit ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
- $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->user_name ) );
+ $this->setContinueEnumParameter( 'from', $row->user_name );
break;
}
@@ -209,7 +218,9 @@ class ApiQueryAllUsers extends ApiQueryBase {
'name' => $lastUser,
);
if ( $fld_blockinfo && !is_null( $row->ipb_by_text ) ) {
+ $lastUserData['blockid'] = $row->ipb_id;
$lastUserData['blockedby'] = $row->ipb_by_text;
+ $lastUserData['blockedbyid'] = $row->ipb_by;
$lastUserData['blockreason'] = $row->ipb_reason;
$lastUserData['blockexpiry'] = $row->ipb_expiry;
}
@@ -235,32 +246,45 @@ class ApiQueryAllUsers extends ApiQueryBase {
'MediaWiki configuration error: the database contains more user groups than known to User::getAllGroups() function' );
}
- $lastUserObj = User::newFromName( $lastUser );
+ $lastUserObj = User::newFromId( $row->user_id );
// Add user's group info
if ( $fld_groups ) {
- if ( !isset( $lastUserData['groups'] ) && $lastUserObj ) {
- $lastUserData['groups'] = ApiQueryUsers::getAutoGroups( $lastUserObj );
+ if ( !isset( $lastUserData['groups'] ) ) {
+ if ( $lastUserObj ) {
+ $lastUserData['groups'] = $lastUserObj->getAutomaticGroups();
+ } else {
+ // This should not normally happen
+ $lastUserData['groups'] = array();
+ }
}
if ( !is_null( $row->ug_group2 ) ) {
$lastUserData['groups'][] = $row->ug_group2;
}
+
$result->setIndexedTagName( $lastUserData['groups'], 'g' );
}
if ( $fld_implicitgroups && !isset( $lastUserData['implicitgroups'] ) && $lastUserObj ) {
- $lastUserData['implicitgroups'] = ApiQueryUsers::getAutoGroups( $lastUserObj );
+ $lastUserData['implicitgroups'] = $lastUserObj->getAutomaticGroups();
$result->setIndexedTagName( $lastUserData['implicitgroups'], 'g' );
}
if ( $fld_rights ) {
- if ( !isset( $lastUserData['rights'] ) && $lastUserObj ) {
- $lastUserData['rights'] = User::getGroupPermissions( $lastUserObj->getAutomaticGroups() );
+ if ( !isset( $lastUserData['rights'] ) ) {
+ if ( $lastUserObj ) {
+ $lastUserData['rights'] = User::getGroupPermissions( $lastUserObj->getAutomaticGroups() );
+ } else {
+ // This should not normally happen
+ $lastUserData['rights'] = array();
+ }
}
+
if ( !is_null( $row->ug_group2 ) ) {
$lastUserData['rights'] = array_unique( array_merge( $lastUserData['rights'],
User::getGroupPermissions( array( $row->ug_group2 ) ) ) );
}
+
$result->setIndexedTagName( $lastUserData['rights'], 'r' );
}
}
@@ -269,8 +293,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
$fit = $result->addValue( array( 'query', $this->getModuleName() ),
null, $lastUserData );
if ( !$fit ) {
- $this->setContinueEnumParameter( 'from',
- $this->keyToTitle( $lastUserData['name'] ) );
+ $this->setContinueEnumParameter( 'from', $lastUserData['name'] );
}
}
@@ -338,7 +361,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
'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)',
+ 'rights' => 'Limit users to given right(s) (does not include rights granted by implicit or auto-promoted groups like *, user, or autoconfirmed)',
'prop' => array(
'What pieces of information to include.',
' blockinfo - Adds the information about a current block on the user',
@@ -354,6 +377,48 @@ class ApiQueryAllUsers extends ApiQueryBase {
);
}
+ public function getResultProperties() {
+ return array(
+ '' => array(
+ 'userid' => 'integer',
+ 'name' => 'string',
+ 'recenteditcount' => array(
+ ApiBase::PROP_TYPE => 'integer',
+ ApiBase::PROP_NULLABLE => true
+ )
+ ),
+ 'blockinfo' => array(
+ 'blockid' => array(
+ ApiBase::PROP_TYPE => 'integer',
+ ApiBase::PROP_NULLABLE => true
+ ),
+ 'blockedby' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ ),
+ 'blockedbyid' => array(
+ ApiBase::PROP_TYPE => 'integer',
+ ApiBase::PROP_NULLABLE => true
+ ),
+ 'blockedreason' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ ),
+ 'blockedexpiry' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ ),
+ 'hidden' => 'boolean'
+ ),
+ 'editcount' => array(
+ 'editcount' => 'integer'
+ ),
+ 'registration' => array(
+ 'registration' => 'string'
+ )
+ );
+ }
+
public function getDescription() {
return 'Enumerate all registered users';
}