30 parent::__construct(
$query, $moduleName,
'au' );
40 return strtr( $name,
'_',
' ' );
47 $activeUserDays = $this->
getConfig()->get(
'ActiveUserDays' );
50 $commentStore = CommentStore::getStore();
53 if ( !is_null( $prop ) ) {
54 $prop = array_flip( $prop );
55 $fld_blockinfo = isset( $prop[
'blockinfo'] );
56 $fld_editcount = isset( $prop[
'editcount'] );
57 $fld_groups = isset( $prop[
'groups'] );
58 $fld_rights = isset( $prop[
'rights'] );
59 $fld_registration = isset( $prop[
'registration'] );
60 $fld_implicitgroups = isset( $prop[
'implicitgroups'] );
61 $fld_centralids = isset( $prop[
'centralids'] );
63 $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration =
64 $fld_rights = $fld_implicitgroups = $fld_centralids =
false;
71 $dir = (
$params[
'dir'] ==
'descending' ?
'older' :
'newer' );
75 # MySQL can't figure out that 'user_name' and 'qcc_title' are the same
76 # despite the JOIN condition, so manually sort on the correct one.
77 $userFieldToSort =
$params[
'activeusers'] ?
'qcc_title' :
'user_name';
79 # Some of these subtable joins are going to give us duplicate rows, so
80 # calculate the maximum number of duplicates we might see.
81 $maxDuplicateRows = 1;
85 if ( !is_null(
$params[
'prefix'] ) ) {
87 $db->buildLike( $this->getCanonicalUserName(
$params[
'prefix'] ), $db->anyString() ) );
90 if ( !is_null(
$params[
'rights'] ) && count(
$params[
'rights'] ) ) {
92 foreach (
$params[
'rights'] as $r ) {
97 if ( !count( $groups ) ) {
103 $groups = array_unique( $groups );
105 if ( is_null(
$params[
'group'] ) ) {
108 $params[
'group'] = array_unique( array_merge(
$params[
'group'], $groups ) );
114 if ( !is_null(
$params[
'group'] ) && count(
$params[
'group'] ) ) {
117 $this->
addTables(
'user_groups',
'ug1' );
122 'ug1.ug_user=user_id',
123 'ug1.ug_group' =>
$params[
'group'],
124 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
128 $maxDuplicateRows *= count(
$params[
'group'] );
131 if ( !is_null(
$params[
'excludegroup'] ) && count(
$params[
'excludegroup'] ) ) {
134 $this->
addTables(
'user_groups',
'ug1' );
136 if ( count(
$params[
'excludegroup'] ) == 1 ) {
137 $exclude = [
'ug1.ug_group' =>
$params[
'excludegroup'][0] ];
139 $exclude = [ $db->makeList(
140 [
'ug1.ug_group' =>
$params[
'excludegroup'] ],
146 'ug1.ug_user=user_id',
147 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
150 $this->
addWhere(
'ug1.ug_user IS NULL' );
153 if (
$params[
'witheditsonly'] ) {
154 $this->
addWhere(
'user_editcount > 0' );
159 if ( $fld_groups || $fld_rights ) {
161 $db->buildGroupConcatField(
'|',
'user_groups',
'ug_group', [
163 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
168 if (
$params[
'activeusers'] ) {
169 $activeUserSeconds = $activeUserDays * 86400;
176 'qcc_type' =>
'activeusers',
177 'qcc_namespace' => NS_USER,
178 'qcc_title=user_name',
186 $userCond =
'rc_user_text = user_name';
191 'rc_actor = actor_id'
194 $userCond =
'actor_user = user_id';
196 $userCond =
'actor_user = user_id OR (rc_actor = 0 AND rc_user_text = user_name)';
199 $timestamp = $db->timestamp(
wfTimestamp( TS_UNIX ) - $activeUserSeconds );
201 'recentactions' =>
'(' . $db->selectSQLText(
207 'rc_log_type IS NULL OR rc_log_type != ' . $db->addQuotes(
'newusers' ),
208 'rc_timestamp >= ' . $db->addQuotes( $timestamp ),
217 $sqlLimit = $limit + $maxDuplicateRows;
224 $this->
addFieldsIf(
'user_editcount', $fld_editcount );
225 $this->
addFieldsIf(
'user_registration', $fld_registration );
229 $countDuplicates = 0;
232 foreach (
$res as $row ) {
235 if ( $lastUser === $row->user_name ) {
240 if ( $countDuplicates == $maxDuplicateRows ) {
246 $countDuplicates = 0;
247 $lastUser = $row->user_name;
249 if ( $count > $limit ) {
256 if ( $count == $sqlLimit ) {
263 if (
$params[
'activeusers'] && $row->recentactions === 0 ) {
269 'userid' => (int)$row->user_id,
270 'name' => $row->user_name,
273 if ( $fld_centralids ) {
279 if ( $fld_blockinfo && !is_null( $row->ipb_by_text ) ) {
280 $data[
'blockid'] = (int)$row->ipb_id;
281 $data[
'blockedby'] = $row->ipb_by_text;
282 $data[
'blockedbyid'] = (int)$row->ipb_by;
283 $data[
'blockedtimestamp'] =
wfTimestamp( TS_ISO_8601, $row->ipb_timestamp );
284 $data[
'blockreason'] = $commentStore->getComment(
'ipb_reason', $row )->text;
285 $data[
'blockexpiry'] = $row->ipb_expiry;
287 if ( $row->ipb_deleted ) {
288 $data[
'hidden'] =
true;
290 if ( $fld_editcount ) {
291 $data[
'editcount'] = intval( $row->user_editcount );
293 if (
$params[
'activeusers'] ) {
294 $data[
'recentactions'] = intval( $row->recentactions );
296 $data[
'recenteditcount'] = $data[
'recentactions'];
298 if ( $fld_registration ) {
299 $data[
'registration'] = $row->user_registration ?
300 wfTimestamp( TS_ISO_8601, $row->user_registration ) :
'';
303 if ( $fld_implicitgroups || $fld_groups || $fld_rights ) {
304 $implicitGroups =
User::newFromId( $row->user_id )->getAutomaticGroups();
305 if ( isset( $row->groups ) && $row->groups !==
'' ) {
306 $groups = array_merge( $implicitGroups, explode(
'|', $row->groups ) );
308 $groups = $implicitGroups;
312 $data[
'groups'] = $groups;
317 if ( $fld_implicitgroups ) {
318 $data[
'implicitgroups'] = $implicitGroups;
330 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data );
337 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'u' );
341 return 'anon-public-user-private';
390 'witheditsonly' =>
false,
394 'apihelp-query+allusers-param-activeusers',
395 $this->
getConfig()->get(
'ActiveUserDays' )
398 'attachedwiki' =>
null,
404 'action=query&list=allusers&aufrom=Y'
405 =>
'apihelp-query+allusers-example-Y',
410 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allusers';
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
const LIMIT_BIG1
Fast query, standard limit.
getResult()
Get the result object.
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
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.
Query module to enumerate all registered users.
__construct(ApiQuery $query, $moduleName)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getCanonicalUserName( $name)
This function converts the user name to a canonical form which is stored in the database.
getHelpUrls()
Return links to more detailed help pages about the module.
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
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.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
getDB()
Get the Query database connection (read-only)
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
showHiddenUsersAddBlockInfo( $showBlockInfo)
Filters hidden users (where the user doesn't have the right to view them) Also adds relevant block in...
static getCentralUserInfo(Config $config, User $user, $attachedWiki=null)
Get central user info.
This is the main query class.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static getAllGroups()
Return the set of defined explicit groups.
static newFromId( $id)
Static factory method for creation from a given user ID.
static getGroupsWithPermission( $role)
Get all the groups who have a given permission.
static getGroupPermissions( $groups)
Get the permissions associated with a given list of groups.
static getAllRights()
Get a list of all available permissions.
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like select() and insert() are usually more convenient. They take care of things like table prefixes and escaping for you. If you really need to make your own SQL
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query