81 $activeUserDays = $this->
getConfig()->get( MainConfigNames::ActiveUserDays );
86 if ( $prop !==
null ) {
87 $prop = array_fill_keys( $prop,
true );
88 $fld_blockinfo = isset( $prop[
'blockinfo'] );
89 $fld_editcount = isset( $prop[
'editcount'] );
90 $fld_groups = isset( $prop[
'groups'] );
91 $fld_rights = isset( $prop[
'rights'] );
92 $fld_registration = isset( $prop[
'registration'] );
93 $fld_implicitgroups = isset( $prop[
'implicitgroups'] );
94 $fld_centralids = isset( $prop[
'centralids'] );
96 $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration =
97 $fld_rights = $fld_implicitgroups = $fld_centralids =
false;
104 $dir = (
$params[
'dir'] ==
'descending' ?
'older' :
'newer' );
105 $from =
$params[
'from'] ===
null ? null : $this->getCanonicalUserName(
$params[
'from'] );
106 $to =
$params[
'to'] ===
null ? null : $this->getCanonicalUserName(
$params[
'to'] );
108 # MySQL can't figure out that 'user_name' and 'qcc_title' are the same
109 # despite the JOIN condition, so manually sort on the correct one.
110 $userFieldToSort =
$params[
'activeusers'] ?
'qcc_title' :
'user_name';
112 # Some of these subtable joins are going to give us duplicate rows, so
113 # calculate the maximum number of duplicates we might see.
114 $maxDuplicateRows = 1;
118 if (
$params[
'prefix'] !==
null ) {
123 new LikeValue( $this->getCanonicalUserName(
$params[
'prefix'] ), $db->anyString() )
131 foreach (
$params[
'rights'] as $r ) {
135 $groups = array_merge(
137 $this->groupPermissionsLookup->getGroupsWithPermission( $r )
142 if ( $groups === [] ) {
149 $groups = array_unique( $groups );
150 if ( in_array(
'*', $groups,
true ) || in_array(
'user', $groups,
true ) ) {
155 if (
$params[
'group'] ===
null ) {
158 $params[
'group'] = array_unique( array_merge(
$params[
'group'], $groups ) );
167 $this->
addTables(
'user_groups',
'ug1' );
172 'ug1.ug_user=user_id',
173 'ug1.ug_group' =>
$params[
'group'],
174 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
178 $maxDuplicateRows *= count(
$params[
'group'] );
181 if (
$params[
'excludegroup'] !==
null && count(
$params[
'excludegroup'] ) ) {
184 $this->
addTables(
'user_groups',
'ug1' );
188 'ug1.ug_user=user_id',
189 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() ),
190 'ug1.ug_group' =>
$params[
'excludegroup'],
193 $this->
addWhere( [
'ug1.ug_user' =>
null ] );
196 if (
$params[
'witheditsonly'] ) {
197 $this->
addWhere(
'user_editcount > 0' );
200 $this->addDeletedUserFilter();
202 if ( $fld_groups || $fld_rights ) {
204 $db->buildGroupConcatField(
'|',
'user_groups',
'ug_group', [
206 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
211 if (
$params[
'activeusers'] ) {
212 $activeUserSeconds = $activeUserDays * 86400;
219 'qcc_type' =>
'activeusers',
221 'qcc_title=user_name',
226 $timestamp = $db->timestamp( (
int)
wfTimestamp( TS_UNIX ) - $activeUserSeconds );
227 $subqueryBuilder = $db->newSelectQueryBuilder()
228 ->select(
'COUNT(*)' )
229 ->from(
'recentchanges' )
230 ->join(
'actor',
null,
'rc_actor = actor_id' )
232 'actor_user = user_id',
234 $db->expr(
'rc_log_type',
'=',
null )
235 ->or(
'rc_log_type',
'!=',
'newusers' ),
236 $db->expr(
'rc_timestamp',
'>=', $timestamp ),
239 'recentactions' =>
'(' . $subqueryBuilder->caller( __METHOD__ )->getSQL() .
')'
243 $sqlLimit = $limit + $maxDuplicateRows;
250 $this->
addFieldsIf(
'user_editcount', $fld_editcount );
251 $this->
addFieldsIf(
'user_registration', $fld_registration );
253 $res = $this->
select( __METHOD__ );
255 $countDuplicates = 0;
258 $blockInfos = $fld_blockinfo ? $this->getBlockDetailsForRows( $res ) :
null;
259 foreach ( $res as $row ) {
262 if ( $lastUser === $row->user_name ) {
267 if ( $countDuplicates == $maxDuplicateRows ) {
273 $countDuplicates = 0;
274 $lastUser = $row->user_name;
276 if ( $count > $limit ) {
283 if ( $count == $sqlLimit ) {
290 if (
$params[
'activeusers'] && (
int)$row->recentactions === 0 ) {
296 'userid' => (int)$row->user_id,
297 'name' => $row->user_name,
300 if ( $fld_centralids ) {
302 $this->
getConfig(), $this->userFactory->newFromId( (
int)$row->user_id ),
$params[
'attachedwiki']
306 if ( $fld_blockinfo && isset( $blockInfos[$row->user_id] ) ) {
307 $data += $blockInfos[$row->user_id];
309 if ( $row->hu_deleted ) {
310 $data[
'hidden'] =
true;
312 if ( $fld_editcount ) {
313 $data[
'editcount'] = (int)$row->user_editcount;
315 if (
$params[
'activeusers'] ) {
316 $data[
'recentactions'] = (int)$row->recentactions;
318 if ( $fld_registration ) {
319 $data[
'registration'] = $row->user_registration ?
320 wfTimestamp( TS_ISO_8601, $row->user_registration ) :
'';
323 if ( $fld_implicitgroups || $fld_groups || $fld_rights ) {
324 $implicitGroups = $this->userGroupManager
325 ->getUserImplicitGroups( $this->userFactory->newFromId( (
int)$row->user_id ) );
326 if ( isset( $row->groups ) && $row->groups !==
'' ) {
327 $groups = array_merge( $implicitGroups, explode(
'|', $row->groups ) );
329 $groups = $implicitGroups;
333 $data[
'groups'] = $groups;
334 ApiResult::setIndexedTagName( $data[
'groups'],
'g' );
335 ApiResult::setArrayType( $data[
'groups'],
'array' );
338 if ( $fld_implicitgroups ) {
339 $data[
'implicitgroups'] = $implicitGroups;
340 ApiResult::setIndexedTagName( $data[
'implicitgroups'],
'g' );
341 ApiResult::setArrayType( $data[
'implicitgroups'],
'array' );
345 $user = $this->userFactory->newFromId( (
int)$row->user_id );
347 ApiResult::setIndexedTagName( $data[
'rights'],
'r' );
348 ApiResult::setArrayType( $data[
'rights'],
'array' );
352 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data );
359 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'u' );
367 $userGroups = $this->userGroupManager->listAllGroups();
378 ParamValidator::PARAM_DEFAULT =>
'ascending',
379 ParamValidator::PARAM_TYPE => [
385 ParamValidator::PARAM_TYPE => $userGroups,
386 ParamValidator::PARAM_ISMULTI =>
true,
389 ParamValidator::PARAM_TYPE => $userGroups,
390 ParamValidator::PARAM_ISMULTI =>
true,
393 ParamValidator::PARAM_TYPE => array_unique( array_merge(
397 ParamValidator::PARAM_ISMULTI =>
true,
400 ParamValidator::PARAM_ISMULTI =>
true,
401 ParamValidator::PARAM_TYPE => [
413 ParamValidator::PARAM_DEFAULT => 10,
414 ParamValidator::PARAM_TYPE =>
'limit',
415 IntegerDef::PARAM_MIN => 1,
419 'witheditsonly' =>
false,
421 ParamValidator::PARAM_DEFAULT =>
false,
423 'apihelp-query+allusers-param-activeusers',
424 $this->
getConfig()->get( MainConfigNames::ActiveUserDays )
427 'attachedwiki' =>
null,