summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryUsers.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryUsers.php')
-rw-r--r--includes/api/ApiQueryUsers.php117
1 files changed, 38 insertions, 79 deletions
diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php
index dccfee67..2f5e4b4b 100644
--- a/includes/api/ApiQueryUsers.php
+++ b/includes/api/ApiQueryUsers.php
@@ -33,7 +33,24 @@ class ApiQueryUsers extends ApiQueryBase {
private $tokenFunctions, $prop;
- public function __construct( $query, $moduleName ) {
+ /**
+ * Properties whose contents does not depend on who is looking at them. If the usprops field
+ * contains anything not listed here, the cache mode will never be public for logged-in users.
+ * @var array
+ */
+ protected static $publicProps = array(
+ // everything except 'blockinfo' which might show hidden records if the user
+ // making the request has the appropriate permissions
+ 'groups',
+ 'implicitgroups',
+ 'rights',
+ 'editcount',
+ 'registration',
+ 'emailable',
+ 'gender',
+ );
+
+ public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'us' );
}
@@ -41,7 +58,8 @@ class ApiQueryUsers extends ApiQueryBase {
* Get an array mapping token names to their handler functions.
* The prototype for a token function is func($user)
* it should return a token or false (permission denied)
- * @return Array tokenname => function
+ * @deprecated since 1.24
+ * @return array Array of tokenname => function
*/
protected function getTokenFunctions() {
// Don't call the hooks twice
@@ -58,15 +76,18 @@ class ApiQueryUsers extends ApiQueryBase {
'userrights' => array( 'ApiQueryUsers', 'getUserrightsToken' ),
);
wfRunHooks( 'APIQueryUsersTokens', array( &$this->tokenFunctions ) );
+
return $this->tokenFunctions;
}
/**
- * @param $user User
- * @return String
+ * @deprecated since 1.24
+ * @param User $user
+ * @return string
*/
public static function getUserrightsToken( $user ) {
global $wgUser;
+
// Since the permissions check for userrights is non-trivial,
// don't bother with it here
return $wgUser->getEditToken( $user->getName() );
@@ -90,10 +111,10 @@ class ApiQueryUsers extends ApiQueryBase {
if ( $n === false || $n === '' ) {
$vals = array( 'name' => $u, 'invalid' => '' );
$fit = $result->addValue( array( 'query', $this->getModuleName() ),
- null, $vals );
+ null, $vals );
if ( !$fit ) {
$this->setContinueEnumParameter( 'users',
- implode( '|', array_diff( $users, $done ) ) );
+ implode( '|', array_diff( $users, $done ) ) );
$goodNames = array();
break;
}
@@ -174,6 +195,7 @@ class ApiQueryUsers extends ApiQueryBase {
$data[$name]['blockid'] = $row->ipb_id;
$data[$name]['blockedby'] = $row->ipb_by_text;
$data[$name]['blockedbyid'] = $row->ipb_by;
+ $data[$name]['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp );
$data[$name]['blockreason'] = $row->ipb_reason;
$data[$name]['blockexpiry'] = $row->ipb_expiry;
}
@@ -244,10 +266,10 @@ class ApiQueryUsers extends ApiQueryBase {
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ),
- null, $data[$u] );
+ null, $data[$u] );
if ( !$fit ) {
$this->setContinueEnumParameter( 'users',
- implode( '|', array_diff( $users, $done ) ) );
+ implode( '|', array_diff( $users, $done ) ) );
break;
}
$done[] = $u;
@@ -259,7 +281,7 @@ class ApiQueryUsers extends ApiQueryBase {
* Gets all the groups that a user is automatically a member of (implicit groups)
*
* @deprecated since 1.20; call User::getAutomaticGroups() directly.
- * @param $user User
+ * @param User $user
* @return array
*/
public static function getAutoGroups( $user ) {
@@ -271,8 +293,10 @@ class ApiQueryUsers extends ApiQueryBase {
public function getCacheMode( $params ) {
if ( isset( $params['token'] ) ) {
return 'private';
- } else {
+ } elseif ( array_diff( (array)$params['prop'], static::$publicProps ) ) {
return 'anon-public-user-private';
+ } else {
+ return 'public';
}
}
@@ -296,6 +320,7 @@ class ApiQueryUsers extends ApiQueryBase {
ApiBase::PARAM_ISMULTI => true
),
'token' => array(
+ ApiBase::PARAM_DEPRECATED => true,
ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
ApiBase::PARAM_ISMULTI => true
),
@@ -312,7 +337,8 @@ class ApiQueryUsers extends ApiQueryBase {
' rights - Lists all the rights the user(s) has',
' editcount - Adds the user\'s edit count',
' registration - Adds the user\'s registration timestamp',
- ' emailable - Tags if the user can and wants to receive email through [[Special:Emailuser]]',
+ ' emailable - Tags if the user can and wants to receive ' .
+ 'email through [[Special:Emailuser]]',
' gender - Tags the gender of the user. Returns "male", "female", or "unknown"',
),
'users' => 'A list of users to obtain the same information for',
@@ -320,75 +346,8 @@ class ApiQueryUsers extends ApiQueryBase {
);
}
- public function getResultProperties() {
- $props = array(
- '' => array(
- 'userid' => array(
- ApiBase::PROP_TYPE => 'integer',
- ApiBase::PROP_NULLABLE => true
- ),
- 'name' => 'string',
- 'invalid' => 'boolean',
- 'hidden' => 'boolean',
- 'interwiki' => 'boolean',
- 'missing' => 'boolean'
- ),
- 'editcount' => array(
- 'editcount' => array(
- ApiBase::PROP_TYPE => 'integer',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'registration' => array(
- 'registration' => array(
- ApiBase::PROP_TYPE => 'timestamp',
- 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 => 'timestamp',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'emailable' => array(
- 'emailable' => 'boolean'
- ),
- 'gender' => array(
- 'gender' => array(
- ApiBase::PROP_TYPE => array(
- 'male',
- 'female',
- 'unknown'
- ),
- ApiBase::PROP_NULLABLE => true
- )
- )
- );
-
- self::addTokenProperties( $props, $this->getTokenFunctions() );
-
- return $props;
- }
-
public function getDescription() {
- return 'Get information about a list of users';
+ return 'Get information about a list of users.';
}
public function getExamples() {