56 parent::__construct( $query, $moduleName,
'us' );
68 if ( isset( $this->tokenFunctions ) ) {
78 $this->tokenFunctions = [
79 'userrights' => [ self::class,
'getUserrightsToken' ],
81 Hooks::run(
'APIQueryUsersTokens', [ &$this->tokenFunctions ] );
96 return $wgUser->getEditToken( $user->getName() );
100 $db = $this->
getDB();
101 $commentStore = CommentStore::getStore();
106 if ( !is_null( $params[
'prop'] ) ) {
107 $this->prop = array_flip( $params[
'prop'] );
111 $useNames = !is_null( $params[
'users'] );
113 $users = (array)$params[
'users'];
114 $userids = (array)$params[
'userids'];
116 $goodNames = $done = [];
119 foreach ( $users as $u ) {
120 $n = User::getCanonicalName( $u );
121 if ( $n ===
false || $n ===
'' ) {
122 $vals = [
'name' => $u,
'invalid' =>
true ];
123 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
127 implode(
'|', array_diff( $users, $done ) ) );
138 $parameters = &$goodNames;
140 $parameters = &$userids;
145 if ( count( $parameters ) ) {
146 $userQuery = User::getQueryInfo();
147 $this->
addTables( $userQuery[
'tables'] );
148 $this->
addFields( $userQuery[
'fields'] );
163 if ( isset( $this->prop[
'groups'] ) || isset( $this->prop[
'rights'] ) ) {
174 $this->
addJoinConds( [
'user_groups' => [
'JOIN',
'ug_user=user_id' ] ] );
176 $this->
addFields( UserGroupMembership::selectFields() );
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 ) ) {
190 $user = User::newFromRow( $row );
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(),
221 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
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'] ) && !is_null( $row->ipb_by_text ) ) {
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 ( !is_null( $params[
'token'] ) ) {
261 foreach ( $params[
'token'] as
$t ) {
263 if ( $val ===
false ) {
264 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
266 $data[$key][
$t .
'token'] = $val;
275 foreach ( $parameters as $u ) {
276 if ( !isset( $data[$u] ) ) {
278 $data[$u] = [
'name' => $u ];
282 $iwUser = $urPage->fetchUser( $u );
285 $data[$u][
'interwiki'] =
true;
287 if ( !is_null( $params[
'token'] ) ) {
290 foreach ( $params[
'token'] as
$t ) {
292 if ( $val ===
false ) {
293 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
295 $data[$u][
$t .
'token'] = $val;
300 $data[$u][
'missing'] =
true;
301 if ( isset( $this->prop[
'cancreate'] ) ) {
302 $status = MediaWiki\Auth\AuthManager::singleton()->canCreateAccount( $u );
303 $data[$u][
'cancreate'] = $status->isGood();
304 if ( !$status->isGood() ) {
305 $data[$u][
'cancreateerror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
310 $data[$u] = [
'userid' => $u,
'missing' =>
true ];
314 if ( isset( $this->prop[
'groups'] ) && isset( $data[$u][
'groups'] ) ) {
315 ApiResult::setArrayType( $data[$u][
'groups'],
'array' );
316 ApiResult::setIndexedTagName( $data[$u][
'groups'],
'g' );
318 if ( isset( $this->prop[
'groupmemberships'] ) && isset( $data[$u][
'groupmemberships'] ) ) {
319 ApiResult::setArrayType( $data[$u][
'groupmemberships'],
'array' );
320 ApiResult::setIndexedTagName( $data[$u][
'groupmemberships'],
'groupmembership' );
322 if ( isset( $this->prop[
'implicitgroups'] ) && isset( $data[$u][
'implicitgroups'] ) ) {
323 ApiResult::setArrayType( $data[$u][
'implicitgroups'],
'array' );
324 ApiResult::setIndexedTagName( $data[$u][
'implicitgroups'],
'g' );
326 if ( isset( $this->prop[
'rights'] ) && isset( $data[$u][
'rights'] ) ) {
327 ApiResult::setArrayType( $data[$u][
'rights'],
'array' );
328 ApiResult::setIndexedTagName( $data[$u][
'rights'],
'r' );
332 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data[$u] );
336 implode(
'|', array_diff( $users, $done ) ) );
339 implode(
'|', array_diff( $userids, $done ) ) );
345 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'user' );
349 if ( isset( $params[
'token'] ) ) {
351 } elseif ( array_diff( (array)$params[
'prop'], static::$publicProps ) ) {
352 return 'anon-public-user-private';
379 'attachedwiki' =>
null,
397 'action=query&list=users&ususers=Example&usprop=groups|editcount|gender'
398 =>
'apihelp-query+users-example-simple',
403 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.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getErrorFormatter()
Get the error formatter.
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...
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
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)
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