57 parent::__construct( $query, $moduleName,
'us' );
69 if ( isset( $this->tokenFunctions ) ) {
79 $this->tokenFunctions = [
80 'userrights' => [ self::class,
'getUserrightsToken' ],
82 $this->
getHookRunner()->onAPIQueryUsersTokens( $this->tokenFunctions );
97 return $wgUser->getEditToken( $user->getName() );
101 $db = $this->
getDB();
105 if ( $params[
'prop'] !==
null ) {
106 $this->prop = array_flip( $params[
'prop'] );
110 $useNames = $params[
'users'] !==
null;
112 $users = (array)$params[
'users'];
113 $userids = (array)$params[
'userids'];
115 $goodNames = $done = [];
118 foreach ( $users as $u ) {
119 $n = User::getCanonicalName( $u );
120 if ( $n ===
false || $n ===
'' ) {
121 $vals = [
'name' => $u,
'invalid' =>
true ];
122 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
126 implode(
'|', array_diff( $users, $done ) ) );
137 $parameters = &$goodNames;
139 $parameters = &$userids;
144 if ( count( $parameters ) ) {
145 $userQuery = User::getQueryInfo();
146 $this->
addTables( $userQuery[
'tables'] );
147 $this->
addFields( $userQuery[
'fields'] );
162 if ( isset( $this->prop[
'groups'] ) || isset( $this->prop[
'rights'] ) ) {
173 $this->
addJoinConds( [
'user_groups' => [
'JOIN',
'ug_user=user_id' ] ] );
175 $this->
addFields( MediaWikiServices::getInstance()
176 ->getUserGroupManager()
177 ->getQueryInfo()[
'fields']
179 $this->
addWhere(
'ug_expiry IS NULL OR ug_expiry >= ' .
180 $db->addQuotes( $db->timestamp() ) );
181 $userGroupsRes = $this->
select( __METHOD__ );
183 foreach ( $userGroupsRes as $row ) {
184 $userGroups[$row->user_name][] = $row;
188 foreach (
$res as $row ) {
191 if ( !isset( $userGroups ) ) {
192 $user = User::newFromRow( $row );
194 if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) {
195 $userGroups[$row->user_name] = [];
197 $user = User::newFromRow( $row, [
'user_groups' => $userGroups[$row->user_name] ] );
200 $key = $user->getName();
202 $key = $user->getId();
204 $data[$key][
'userid'] = $user->getId();
205 $data[$key][
'name'] = $user->getName();
207 if ( isset( $this->prop[
'editcount'] ) ) {
208 $data[$key][
'editcount'] = $user->getEditCount();
211 if ( isset( $this->prop[
'registration'] ) ) {
212 $data[$key][
'registration'] =
wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
215 if ( isset( $this->prop[
'groups'] ) ) {
216 $data[$key][
'groups'] = $user->getEffectiveGroups();
219 if ( isset( $this->prop[
'groupmemberships'] ) ) {
220 $data[$key][
'groupmemberships'] = array_map(
function ( $ugm ) {
222 'group' => $ugm->getGroup(),
223 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
225 }, $user->getGroupMemberships() );
228 if ( isset( $this->prop[
'implicitgroups'] ) ) {
229 $data[$key][
'implicitgroups'] = $user->getAutomaticGroups();
232 if ( isset( $this->prop[
'rights'] ) ) {
234 ->getUserPermissions( $user );
236 if ( $row->ipb_deleted ) {
237 $data[$key][
'hidden'] =
true;
239 if ( isset( $this->prop[
'blockinfo'] ) && $row->ipb_by_text !==
null ) {
240 $data[$key] += $this->getBlockDetails( DatabaseBlock::newFromRow( $row ) );
243 if ( isset( $this->prop[
'emailable'] ) ) {
244 $data[$key][
'emailable'] = $user->canReceiveEmail();
247 if ( isset( $this->prop[
'gender'] ) ) {
248 $gender = $user->getOption(
'gender' );
249 if ( strval( $gender ) ===
'' ) {
252 $data[$key][
'gender'] = $gender;
255 if ( isset( $this->prop[
'centralids'] ) ) {
257 $this->
getConfig(), $user, $params[
'attachedwiki']
261 if ( $params[
'token'] !==
null ) {
263 foreach ( $params[
'token'] as
$t ) {
265 if ( $val ===
false ) {
266 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
268 $data[$key][
$t .
'token'] = $val;
277 foreach ( $parameters as $u ) {
278 if ( !isset( $data[$u] ) ) {
280 $data[$u] = [
'name' => $u ];
284 $iwUser = $urPage->fetchUser( $u );
287 $data[$u][
'interwiki'] =
true;
289 if ( $params[
'token'] !==
null ) {
292 foreach ( $params[
'token'] as
$t ) {
294 if ( $val ===
false ) {
295 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
297 $data[$u][
$t .
'token'] = $val;
302 $data[$u][
'missing'] =
true;
303 if ( isset( $this->prop[
'cancreate'] ) ) {
304 $status = MediaWikiServices::getInstance()->getAuthManager()
305 ->canCreateAccount( $u );
306 $data[$u][
'cancreate'] = $status->isGood();
307 if ( !$status->isGood() ) {
308 $data[$u][
'cancreateerror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
313 $data[$u] = [
'userid' => $u,
'missing' =>
true ];
317 if ( isset( $this->prop[
'groups'] ) && isset( $data[$u][
'groups'] ) ) {
318 ApiResult::setArrayType( $data[$u][
'groups'],
'array' );
319 ApiResult::setIndexedTagName( $data[$u][
'groups'],
'g' );
321 if ( isset( $this->prop[
'groupmemberships'] ) && isset( $data[$u][
'groupmemberships'] ) ) {
322 ApiResult::setArrayType( $data[$u][
'groupmemberships'],
'array' );
323 ApiResult::setIndexedTagName( $data[$u][
'groupmemberships'],
'groupmembership' );
325 if ( isset( $this->prop[
'implicitgroups'] ) && isset( $data[$u][
'implicitgroups'] ) ) {
326 ApiResult::setArrayType( $data[$u][
'implicitgroups'],
'array' );
327 ApiResult::setIndexedTagName( $data[$u][
'implicitgroups'],
'g' );
329 if ( isset( $this->prop[
'rights'] ) && isset( $data[$u][
'rights'] ) ) {
330 ApiResult::setArrayType( $data[$u][
'rights'],
'array' );
331 ApiResult::setIndexedTagName( $data[$u][
'rights'],
'r' );
335 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data[$u] );
339 implode(
'|', array_diff( $users, $done ) ) );
342 implode(
'|', array_diff( $userids, $done ) ) );
348 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'user' );
352 if ( isset( $params[
'token'] ) ) {
354 } elseif ( array_diff( (array)$params[
'prop'], static::$publicProps ) ) {
355 return 'anon-public-user-private';
382 'attachedwiki' =>
null,
400 'action=query&list=users&ususers=Example&usprop=groups|editcount|gender'
401 =>
'apihelp-query+users-example-simple',
406 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Users';
addBlockInfoToQuery( $showBlockInfo)
Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block in...
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
getErrorFormatter()
Get the error formatter Stable to override.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
getModuleName()
Get the name of the module being executed by this instance.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
resetQueryParams()
Blank the internal arrays with query parameters.
addFields( $value)
Add a set of fields to select to the internal array.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
getDB()
Get the Query database connection (read-only) Stable to override.
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
static getCentralUserInfo(Config $config, User $user, $attachedWiki=null)
Get central user info.
Query module to get information about a list of users.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
static getUserrightsToken( $user)
static array $publicProps
Properties whose contents does not depend on who is looking at them.
getHelpUrls()
Return links to more detailed help pages about the module.
getTokenFunctions()
Get an array mapping token names to their handler functions.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
__construct(ApiQuery $query, $moduleName)
This is the main query class.
getContext()
Get the base IContextSource object.
setContext( $context)
Sets the context this SpecialPage is executed in.
Cut-down copy of User interface for local-interwiki-database user rights manipulation.
Special page to allow managing user group membership.
trait ApiQueryBlockInfoTrait