Go to the documentation of this file.
34 parent::__construct( $query, $moduleName,
'au' );
44 return strtr( $name,
'_',
' ' );
49 $activeUserDays = $this->
getConfig()->get(
'ActiveUserDays' );
54 $prop = $params[
'prop'];
55 if ( !is_null( $prop ) ) {
56 $prop = array_flip( $prop );
57 $fld_blockinfo = isset( $prop[
'blockinfo'] );
58 $fld_editcount = isset( $prop[
'editcount'] );
59 $fld_groups = isset( $prop[
'groups'] );
60 $fld_rights = isset( $prop[
'rights'] );
61 $fld_registration = isset( $prop[
'registration'] );
62 $fld_implicitgroups = isset( $prop[
'implicitgroups'] );
63 $fld_centralids = isset( $prop[
'centralids'] );
65 $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration =
66 $fld_rights = $fld_implicitgroups = $fld_centralids =
false;
69 $limit = $params[
'limit'];
73 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
77 # MySQL can't figure out that 'user_name' and 'qcc_title' are the same
78 # despite the JOIN condition, so manually sort on the correct one.
79 $userFieldToSort = $params[
'activeusers'] ?
'qcc_title' :
'user_name';
81 # Some of these subtable joins are going to give us duplicate rows, so
82 # calculate the maximum number of duplicates we might see.
83 $maxDuplicateRows = 1;
87 if ( !is_null( $params[
'prefix'] ) ) {
89 $db->buildLike( $this->getCanonicalUserName( $params[
'prefix'] ), $db->anyString() ) );
92 if ( !is_null( $params[
'rights'] ) && count( $params[
'rights'] ) ) {
94 foreach ( $params[
'rights'] as $r ) {
96 ->getGroupsWithPermission( $r ) );
100 if ( $groups === [] ) {
106 $groups = array_unique( $groups );
108 if ( is_null( $params[
'group'] ) ) {
109 $params[
'group'] = $groups;
111 $params[
'group'] = array_unique( array_merge( $params[
'group'], $groups ) );
117 if ( !is_null( $params[
'group'] ) && count( $params[
'group'] ) ) {
120 $this->
addTables(
'user_groups',
'ug1' );
125 'ug1.ug_user=user_id',
126 'ug1.ug_group' => $params[
'group'],
127 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
131 $maxDuplicateRows *= count( $params[
'group'] );
134 if ( !is_null( $params[
'excludegroup'] ) && count( $params[
'excludegroup'] ) ) {
137 $this->
addTables(
'user_groups',
'ug1' );
139 if ( count( $params[
'excludegroup'] ) == 1 ) {
140 $exclude = [
'ug1.ug_group' => $params[
'excludegroup'][0] ];
142 $exclude = [ $db->makeList(
143 [
'ug1.ug_group' => $params[
'excludegroup'] ],
149 'ug1.ug_user=user_id',
150 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
153 $this->
addWhere(
'ug1.ug_user IS NULL' );
156 if ( $params[
'witheditsonly'] ) {
157 $this->
addWhere(
'user_editcount > 0' );
162 if ( $fld_groups || $fld_rights ) {
164 $db->buildGroupConcatField(
'|',
'user_groups',
'ug_group', [
166 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
171 if ( $params[
'activeusers'] ) {
172 $activeUserSeconds = $activeUserDays * 86400;
179 'qcc_type' =>
'activeusers',
181 'qcc_title=user_name',
186 $tables = [
'recentchanges',
'actor' ];
188 'actor' => [
'JOIN',
'rc_actor = actor_id' ],
190 $timestamp = $db->timestamp(
wfTimestamp( TS_UNIX ) - $activeUserSeconds );
192 'recentactions' =>
'(' . $db->selectSQLText(
196 'actor_user = user_id',
198 'rc_log_type IS NULL OR rc_log_type != ' . $db->addQuotes(
'newusers' ),
199 'rc_timestamp >= ' . $db->addQuotes( $timestamp ),
208 $sqlLimit = $limit + $maxDuplicateRows;
215 $this->
addFieldsIf(
'user_editcount', $fld_editcount );
216 $this->
addFieldsIf(
'user_registration', $fld_registration );
220 $countDuplicates = 0;
223 foreach (
$res as $row ) {
226 if ( $lastUser === $row->user_name ) {
231 if ( $countDuplicates == $maxDuplicateRows ) {
237 $countDuplicates = 0;
238 $lastUser = $row->user_name;
240 if ( $count > $limit ) {
247 if ( $count == $sqlLimit ) {
254 if ( $params[
'activeusers'] && $row->recentactions === 0 ) {
260 'userid' => (int)$row->user_id,
261 'name' => $row->user_name,
264 if ( $fld_centralids ) {
270 if ( $fld_blockinfo && !is_null( $row->ipb_id ) ) {
271 $data += $this->getBlockDetails( DatabaseBlock::newFromRow( $row ) );
273 if ( $row->ipb_deleted ) {
274 $data[
'hidden'] =
true;
276 if ( $fld_editcount ) {
277 $data[
'editcount'] = (int)$row->user_editcount;
279 if ( $params[
'activeusers'] ) {
280 $data[
'recentactions'] = (int)$row->recentactions;
282 if ( $fld_registration ) {
283 $data[
'registration'] = $row->user_registration ?
284 wfTimestamp( TS_ISO_8601, $row->user_registration ) :
'';
287 if ( $fld_implicitgroups || $fld_groups || $fld_rights ) {
288 $implicitGroups =
User::newFromId( $row->user_id )->getAutomaticGroups();
289 if ( isset( $row->groups ) && $row->groups !==
'' ) {
290 $groups = array_merge( $implicitGroups, explode(
'|', $row->groups ) );
292 $groups = $implicitGroups;
296 $data[
'groups'] = $groups;
301 if ( $fld_implicitgroups ) {
302 $data[
'implicitgroups'] = $implicitGroups;
314 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data );
321 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'u' );
325 return 'anon-public-user-private';
352 ApiBase::PARAM_ISMULTI =>
true,
374 'witheditsonly' =>
false,
378 'apihelp-query+allusers-param-activeusers',
379 $this->
getConfig()->get(
'ActiveUserDays' )
382 'attachedwiki' =>
null,
388 'action=query&list=allusers&aufrom=Y'
389 =>
'apihelp-query+allusers-example-y',
394 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allusers';
static newFromId( $id)
Static factory method for creation from a given user ID.
addFields( $value)
Add a set of fields to select to the internal array.
This is the main query class.
getExamplesMessages()
Returns usage examples for this module.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
trait ApiQueryBlockInfoTrait
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
getCanonicalUserName( $name)
This function converts the user name to a canonical form which is stored in the database.
This is a base class for all Query modules.
const LIMIT_BIG1
Fast query, standard limit.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getDB()
Get the Query database connection (read-only)
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
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,...
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
static getAllGroups()
Return the set of defined explicit groups.
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
const LIMIT_BIG2
Fast query, apihighlimits limit.
Query module to enumerate all registered users.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
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.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
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.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName)
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
addBlockInfoToQuery( $showBlockInfo)
Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block in...