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();
$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.
+ $userFieldToSort = $params['activeusers'] ? 'rc_user_text' : 'user_name';
- $this->addWhereRange( 'user_name', $dir, $from, $to );
+ $this->addWhereRange( $userFieldToSort, $dir, $from, $to );
if ( !is_null( $params['prefix'] ) ) {
- $this->addWhere( 'user_name' . $db->buildLike( $this->keyToTitle( $params['prefix'] ), $db->anyString() ) );
+ $this->addWhere( $userFieldToSort .
+ $db->buildLike( $this->getCanonicalUserName( $params['prefix'] ), $db->anyString() ) );
}
if ( !is_null( $params['rights'] ) ) {
$this->addFields( 'COUNT(*) AS recentedits' );
- $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', 'user_name' );
+ $this->addOption( 'GROUP BY', $userFieldToSort );
}
$this->addOption( 'LIMIT', $sqlLimit );
$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;
}
'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;
}
ApiBase::dieDebug( __METHOD__,
'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'] = ApiQueryUsers::getAutoGroups( $lastUserObj );
+ } 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' );
}
$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' );
}
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ),
null, $lastUserData );
if ( !$fit ) {
- $this->setContinueEnumParameter( 'from',
- $this->keyToTitle( $lastUserData['name'] ) );
+ $this->setContinueEnumParameter( 'from', $lastUserData['name'] );
}
}
'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',
}
public function getHelpUrls() {
- return 'http://www.mediawiki.org/wiki/API:Allusers';
+ return 'https://www.mediawiki.org/wiki/API:Allusers';
}
public function getVersion() {