Go to the documentation of this file.
57 parent::__construct( $query, $moduleName,
'us' );
68 if ( isset( $this->tokenFunctions ) ) {
78 $this->tokenFunctions = [
79 'userrights' => [ self::class,
'getUserrightsToken' ],
95 return $actingUser->
getEditToken( $targetUser->getName() );
103 if ( $params[
'prop'] !==
null ) {
104 $this->prop = array_flip( $params[
'prop'] );
108 $useNames = $params[
'users'] !==
null;
110 $users = (array)$params[
'users'];
111 $userids = (array)$params[
'userids'];
113 $goodNames = $done = [];
116 foreach ( $users as $u ) {
118 if ( $n ===
false || $n ===
'' ) {
119 $vals = [
'name' => $u,
'invalid' =>
true ];
120 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
124 implode(
'|', array_diff( $users, $done ) ) );
135 $parameters = &$goodNames;
137 $parameters = &$userids;
142 if ( count( $parameters ) ) {
144 $this->
addTables( $userQuery[
'tables'] );
145 $this->
addFields( $userQuery[
'fields'] );
160 if ( isset( $this->prop[
'groups'] ) || isset( $this->prop[
'rights'] ) ) {
171 $this->
addJoinConds( [
'user_groups' => [
'JOIN',
'ug_user=user_id' ] ] );
173 $this->
addFields( MediaWikiServices::getInstance()
174 ->getUserGroupManager()
175 ->getQueryInfo()[
'fields']
177 $this->
addWhere(
'ug_expiry IS NULL OR ug_expiry >= ' .
178 $db->addQuotes( $db->timestamp() ) );
179 $userGroupsRes = $this->
select( __METHOD__ );
181 foreach ( $userGroupsRes as $row ) {
182 $userGroups[$row->user_name][] = $row;
186 foreach (
$res as $row ) {
189 if ( !isset( $userGroups ) ) {
192 if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) {
193 $userGroups[$row->user_name] = [];
195 $user =
User::newFromRow( $row, [
'user_groups' => $userGroups[$row->user_name] ] );
198 $key = $user->getName();
200 $key = $user->getId();
202 $data[$key][
'userid'] = $user->getId();
203 $data[$key][
'name'] = $user->getName();
205 if ( isset( $this->prop[
'editcount'] ) ) {
206 $data[$key][
'editcount'] = $user->getEditCount();
209 if ( isset( $this->prop[
'registration'] ) ) {
210 $data[$key][
'registration'] =
wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
213 if ( isset( $this->prop[
'groups'] ) ) {
214 $data[$key][
'groups'] = $user->getEffectiveGroups();
217 if ( isset( $this->prop[
'groupmemberships'] ) ) {
218 $data[$key][
'groupmemberships'] = array_map(
function ( $ugm ) {
220 'group' => $ugm->getGroup(),
223 }, $user->getGroupMemberships() );
226 if ( isset( $this->prop[
'implicitgroups'] ) ) {
227 $data[$key][
'implicitgroups'] = $user->getAutomaticGroups();
230 if ( isset( $this->prop[
'rights'] ) ) {
232 ->getUserPermissions( $user );
234 if ( $row->ipb_deleted ) {
235 $data[$key][
'hidden'] =
true;
237 if ( isset( $this->prop[
'blockinfo'] ) && $row->ipb_by_text !==
null ) {
238 $data[$key] += $this->getBlockDetails( DatabaseBlock::newFromRow( $row ) );
241 if ( isset( $this->prop[
'emailable'] ) ) {
242 $data[$key][
'emailable'] = $user->canReceiveEmail();
245 if ( isset( $this->prop[
'gender'] ) ) {
246 $gender = $user->getOption(
'gender' );
247 if ( strval( $gender ) ===
'' ) {
250 $data[$key][
'gender'] = $gender;
253 if ( isset( $this->prop[
'centralids'] ) ) {
255 $this->
getConfig(), $user, $params[
'attachedwiki']
259 if ( $params[
'token'] !==
null ) {
261 foreach ( $params[
'token'] as
$t ) {
262 $val = call_user_func(
267 if ( $val ===
false ) {
268 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
270 $data[$key][
$t .
'token'] = $val;
279 foreach ( $parameters as $u ) {
280 if ( !isset( $data[$u] ) ) {
282 $data[$u] = [
'name' => $u ];
286 $iwUser = $urPage->fetchUser( $u );
289 $data[$u][
'interwiki'] =
true;
291 if ( $params[
'token'] !==
null ) {
294 foreach ( $params[
'token'] as
$t ) {
295 $val = call_user_func(
300 if ( $val ===
false ) {
301 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
303 $data[$u][
$t .
'token'] = $val;
308 $data[$u][
'missing'] =
true;
309 if ( isset( $this->prop[
'cancreate'] ) ) {
310 $status = MediaWikiServices::getInstance()->getAuthManager()
311 ->canCreateAccount( $u );
312 $data[$u][
'cancreate'] = $status->isGood();
313 if ( !$status->isGood() ) {
314 $data[$u][
'cancreateerror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
319 $data[$u] = [
'userid' => $u,
'missing' =>
true ];
323 if ( isset( $this->prop[
'groups'] ) && isset( $data[$u][
'groups'] ) ) {
327 if ( isset( $this->prop[
'groupmemberships'] ) && isset( $data[$u][
'groupmemberships'] ) ) {
331 if ( isset( $this->prop[
'implicitgroups'] ) && isset( $data[$u][
'implicitgroups'] ) ) {
335 if ( isset( $this->prop[
'rights'] ) && isset( $data[$u][
'rights'] ) ) {
341 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data[$u] );
345 implode(
'|', array_diff( $users, $done ) ) );
348 implode(
'|', array_diff( $userids, $done ) ) );
354 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'user' );
358 if ( isset( $params[
'token'] ) ) {
360 } elseif ( array_diff( (array)$params[
'prop'], static::$publicProps ) ) {
361 return 'anon-public-user-private';
388 'attachedwiki' =>
null,
406 'action=query&list=users&ususers=Example&usprop=groups|editcount|gender'
407 =>
'apihelp-query+users-example-simple',
412 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Users';
addFields( $value)
Add a set of fields to select to the internal array.
getContext()
Get the base IContextSource object.
This is the main query class.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Query module to get information about a list of users.
resetQueryParams()
Blank the internal arrays with query parameters.
getResult()
Get the result object.
Cut-down copy of User interface for local-interwiki-database user rights manipulation.
getUser()
Stable to override.
static newFromRow( $row, $data=null)
Create a new user object from a user row.
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
trait ApiQueryBlockInfoTrait
Special page to allow managing user group membership.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
This is a base class for all Query modules.
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
getDB()
Get the Query database connection (read-only) Stable to override.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getHelpUrls()
Return links to more detailed help pages about the module.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
__construct(ApiQuery $query, $moduleName)
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
getTokenFunctions()
Get an array mapping token names to their handler functions.
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
static getUserrightsToken(User $actingUser, $targetUser)
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getExamplesMessages()
Returns usage examples for this module.
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
setContext( $context)
Sets the context this SpecialPage is executed in.
getModuleName()
Get the name of the module being executed by this instance.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.
static array $publicProps
Properties whose contents does not depend on who is looking at them.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
static getCentralUserInfo(Config $config, User $user, $attachedWiki=null)
Get central user info.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
getEditToken( $salt='', $request=null)
Initialize (if necessary) and return a session token value which can be used in edit forms to show th...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getErrorFormatter()
Stable to override.
addBlockInfoToQuery( $showBlockInfo)
Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block in...