59 parent::__construct( $query, $moduleName,
'au' );
60 $this->userFactory = $userFactory;
61 $this->userGroupManager = $userGroupManager;
62 $this->groupPermissionsLookup = $groupPermissionsLookup;
63 $this->contentLanguage = $contentLanguage;
64 $this->tempUserConfig = $tempUserConfig;
73 private function getCanonicalUserName( $name ) {
74 $name = $this->contentLanguage->ucfirst( $name );
75 return strtr( $name,
'_',
' ' );
85 if ( $prop !==
null ) {
86 $prop = array_fill_keys( $prop,
true );
87 $fld_blockinfo = isset( $prop[
'blockinfo'] );
88 $fld_editcount = isset( $prop[
'editcount'] );
89 $fld_groups = isset( $prop[
'groups'] );
90 $fld_rights = isset( $prop[
'rights'] );
91 $fld_registration = isset( $prop[
'registration'] );
92 $fld_implicitgroups = isset( $prop[
'implicitgroups'] );
93 $fld_centralids = isset( $prop[
'centralids'] );
95 $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration =
96 $fld_rights = $fld_implicitgroups = $fld_centralids =
false;
103 $dir = (
$params[
'dir'] ==
'descending' ?
'older' :
'newer' );
104 $from =
$params[
'from'] ===
null ? null : $this->getCanonicalUserName(
$params[
'from'] );
105 $to =
$params[
'to'] ===
null ? null : $this->getCanonicalUserName(
$params[
'to'] );
107 # MySQL can't figure out that 'user_name' and 'qcc_title' are the same
108 # despite the JOIN condition, so manually sort on the correct one.
109 $userFieldToSort =
$params[
'activeusers'] ?
'qcc_title' :
'user_name';
111 # Some of these subtable joins are going to give us duplicate rows, so
112 # calculate the maximum number of duplicates we might see.
113 $maxDuplicateRows = 1;
117 if (
$params[
'prefix'] !==
null ) {
122 new LikeValue( $this->getCanonicalUserName(
$params[
'prefix'] ), $db->anyString() )
127 $excludeNamed =
$params[
'excludenamed'];
128 $excludeTemp =
$params[
'excludetemp'];
130 if ( $this->tempUserConfig->isKnown() ) {
131 if ( $excludeTemp ) {
133 $this->tempUserConfig->getMatchCondition( $db,
'user_name', IExpression::NOT_LIKE )
136 if ( $excludeNamed ) {
138 $this->tempUserConfig->getMatchCondition( $db,
'user_name', IExpression::LIKE )
146 foreach (
$params[
'rights'] as $r ) {
150 $groups = array_merge(
152 $this->groupPermissionsLookup->getGroupsWithPermission( $r )
157 if ( $groups === [] ) {
164 $groups = array_unique( $groups );
165 if ( in_array(
'*', $groups,
true ) || in_array(
'user', $groups,
true ) ) {
170 if (
$params[
'group'] ===
null ) {
173 $params[
'group'] = array_unique( array_merge(
$params[
'group'], $groups ) );
182 $this->
addTables(
'user_groups',
'ug1' );
187 'ug1.ug_user=user_id',
188 'ug1.ug_group' =>
$params[
'group'],
189 $db->expr(
'ug1.ug_expiry',
'=',
null )->or(
'ug1.ug_expiry',
'>=', $db->timestamp() ),
193 $maxDuplicateRows *= count(
$params[
'group'] );
196 if (
$params[
'excludegroup'] !==
null && count(
$params[
'excludegroup'] ) ) {
199 $this->
addTables(
'user_groups',
'ug1' );
203 'ug1.ug_user=user_id',
204 $db->expr(
'ug1.ug_expiry',
'=',
null )->or(
'ug1.ug_expiry',
'>=', $db->timestamp() ),
205 'ug1.ug_group' =>
$params[
'excludegroup'],
208 $this->
addWhere( [
'ug1.ug_user' =>
null ] );
211 if (
$params[
'witheditsonly'] ) {
212 $this->
addWhere( $db->expr(
'user_editcount',
'>', 0 ) );
215 $this->addDeletedUserFilter();
217 if ( $fld_groups || $fld_rights ) {
219 $db->newSelectQueryBuilder()
220 ->table(
'user_groups' )
221 ->field(
'ug_group' )
224 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
226 ->buildGroupConcatField(
'|' )
230 if (
$params[
'activeusers'] ) {
231 $activeUserSeconds = $activeUserDays * 86400;
238 'qcc_type' =>
'activeusers',
240 'qcc_title=user_name',
245 $timestamp = $db->timestamp( (
int)
wfTimestamp( TS_UNIX ) - $activeUserSeconds );
246 $subqueryBuilder = $db->newSelectQueryBuilder()
247 ->select(
'COUNT(*)' )
248 ->from(
'recentchanges' )
249 ->join(
'actor',
null,
'rc_actor = actor_id' )
251 'actor_user = user_id',
253 $db->expr(
'rc_log_type',
'=',
null )
254 ->or(
'rc_log_type',
'!=',
'newusers' ),
255 $db->expr(
'rc_timestamp',
'>=', $timestamp ),
258 'recentactions' =>
'(' . $subqueryBuilder->caller( __METHOD__ )->getSQL() .
')'
262 $sqlLimit = $limit + $maxDuplicateRows;
269 $this->
addFieldsIf(
'user_editcount', $fld_editcount );
270 $this->
addFieldsIf(
'user_registration', $fld_registration );
272 $res = $this->
select( __METHOD__ );
274 $countDuplicates = 0;
277 $blockInfos = $fld_blockinfo ? $this->getBlockDetailsForRows( $res ) :
null;
278 foreach ( $res as $row ) {
281 if ( $lastUser === $row->user_name ) {
286 if ( $countDuplicates == $maxDuplicateRows ) {
292 $countDuplicates = 0;
293 $lastUser = $row->user_name;
295 if ( $count > $limit ) {
302 if ( $count == $sqlLimit ) {
309 if (
$params[
'activeusers'] && (
int)$row->recentactions === 0 ) {
315 'userid' => (int)$row->user_id,
316 'name' => $row->user_name,
319 if ( $fld_centralids ) {
321 $this->
getConfig(), $this->userFactory->newFromId( (
int)$row->user_id ),
$params[
'attachedwiki']
325 if ( $fld_blockinfo && isset( $blockInfos[$row->user_id] ) ) {
326 $data += $blockInfos[$row->user_id];
328 if ( $row->hu_deleted ) {
329 $data[
'hidden'] =
true;
331 if ( $fld_editcount ) {
332 $data[
'editcount'] = (int)$row->user_editcount;
334 if (
$params[
'activeusers'] ) {
335 $data[
'recentactions'] = (int)$row->recentactions;
337 if ( $fld_registration ) {
338 $data[
'registration'] = $row->user_registration ?
339 wfTimestamp( TS_ISO_8601, $row->user_registration ) :
'';
342 if ( $fld_implicitgroups || $fld_groups || $fld_rights ) {
343 $implicitGroups = $this->userGroupManager
344 ->getUserImplicitGroups( $this->userFactory->newFromId( (
int)$row->user_id ) );
345 if ( isset( $row->groups ) && $row->groups !==
'' ) {
346 $groups = array_merge( $implicitGroups, explode(
'|', $row->groups ) );
348 $groups = $implicitGroups;
352 $data[
'groups'] = $groups;
357 if ( $fld_implicitgroups ) {
358 $data[
'implicitgroups'] = $implicitGroups;
364 $user = $this->userFactory->newFromId( (
int)$row->user_id );
371 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data );
378 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'u' );
382 return 'anon-public-user-private';
386 $userGroups = $this->userGroupManager->listAllGroups();
397 ParamValidator::PARAM_DEFAULT =>
'ascending',
398 ParamValidator::PARAM_TYPE => [
404 ParamValidator::PARAM_TYPE => $userGroups,
405 ParamValidator::PARAM_ISMULTI =>
true,
408 ParamValidator::PARAM_TYPE => $userGroups,
409 ParamValidator::PARAM_ISMULTI =>
true,
412 ParamValidator::PARAM_TYPE => array_unique( array_merge(
416 ParamValidator::PARAM_ISMULTI =>
true,
419 ParamValidator::PARAM_ISMULTI =>
true,
420 ParamValidator::PARAM_TYPE => [
432 ParamValidator::PARAM_DEFAULT => 10,
433 ParamValidator::PARAM_TYPE =>
'limit',
434 IntegerDef::PARAM_MIN => 1,
438 'witheditsonly' =>
false,
440 ParamValidator::PARAM_DEFAULT =>
false,
442 'apihelp-query+allusers-param-activeusers',
446 'attachedwiki' =>
null,
448 ParamValidator::PARAM_TYPE =>
'boolean',
451 ParamValidator::PARAM_TYPE =>
'boolean',
458 'action=query&list=allusers&aufrom=Y'
459 =>
'apihelp-query+allusers-example-y',
464 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allusers';
469class_alias( ApiQueryAllUsers::class,
'ApiQueryAllUsers' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
array $params
The job parameters.
A class containing constants representing the names of configuration variables.
const ActiveUserDays
Name constant for the ActiveUserDays setting, for use with Config::get()
trait ApiQueryBlockInfoTrait