87 $activeUserDays = $this->
getConfig()->get( MainConfigNames::ActiveUserDays );
91 $prop = $params[
'prop'];
92 if ( $prop !==
null ) {
93 $prop = array_fill_keys( $prop,
true );
94 $fld_blockinfo = isset( $prop[
'blockinfo'] );
95 $fld_editcount = isset( $prop[
'editcount'] );
96 $fld_groups = isset( $prop[
'groups'] );
97 $fld_rights = isset( $prop[
'rights'] );
98 $fld_registration = isset( $prop[
'registration'] );
99 $fld_implicitgroups = isset( $prop[
'implicitgroups'] );
100 $fld_centralids = isset( $prop[
'centralids'] );
102 $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration =
103 $fld_rights = $fld_implicitgroups = $fld_centralids =
false;
106 $limit = $params[
'limit'];
110 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
111 $from = $params[
'from'] ===
null ? null : $this->getCanonicalUserName( $params[
'from'] );
112 $to = $params[
'to'] ===
null ? null : $this->getCanonicalUserName( $params[
'to'] );
114 # MySQL can't figure out that 'user_name' and 'qcc_title' are the same
115 # despite the JOIN condition, so manually sort on the correct one.
116 $userFieldToSort = $params[
'activeusers'] ?
'qcc_title' :
'user_name';
118 # Some of these subtable joins are going to give us duplicate rows, so
119 # calculate the maximum number of duplicates we might see.
120 $maxDuplicateRows = 1;
124 if ( $params[
'prefix'] !==
null ) {
126 $db->buildLike( $this->getCanonicalUserName( $params[
'prefix'] ), $db->anyString() ) );
129 if ( $params[
'rights'] !==
null && count( $params[
'rights'] ) ) {
131 foreach ( $params[
'rights'] as $r ) {
132 $groups = array_merge( $groups, $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
136 if ( $groups === [] ) {
142 $groups = array_unique( $groups );
144 if ( $params[
'group'] ===
null ) {
145 $params[
'group'] = $groups;
147 $params[
'group'] = array_unique( array_merge( $params[
'group'], $groups ) );
153 if ( $params[
'group'] !==
null && count( $params[
'group'] ) ) {
156 $this->
addTables(
'user_groups',
'ug1' );
161 'ug1.ug_user=user_id',
162 'ug1.ug_group' => $params[
'group'],
163 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
167 $maxDuplicateRows *= count( $params[
'group'] );
170 if ( $params[
'excludegroup'] !==
null && count( $params[
'excludegroup'] ) ) {
173 $this->
addTables(
'user_groups',
'ug1' );
175 if ( count( $params[
'excludegroup'] ) == 1 ) {
176 $exclude = [
'ug1.ug_group' => $params[
'excludegroup'][0] ];
178 $exclude = [ $db->makeList(
179 [
'ug1.ug_group' => $params[
'excludegroup'] ],
185 'ug1.ug_user=user_id',
186 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
189 $this->
addWhere(
'ug1.ug_user IS NULL' );
192 if ( $params[
'witheditsonly'] ) {
193 $this->
addWhere(
'user_editcount > 0' );
196 $this->addBlockInfoToQuery( $fld_blockinfo );
198 if ( $fld_groups || $fld_rights ) {
200 $db->buildGroupConcatField(
'|',
'user_groups',
'ug_group', [
202 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
207 if ( $params[
'activeusers'] ) {
208 $activeUserSeconds = $activeUserDays * 86400;
215 'qcc_type' =>
'activeusers',
217 'qcc_title=user_name',
222 $tables = [
'recentchanges',
'actor' ];
224 'actor' => [
'JOIN',
'rc_actor = actor_id' ],
226 $timestamp = $db->timestamp( (
int)
wfTimestamp( TS_UNIX ) - $activeUserSeconds );
228 'recentactions' =>
'(' . $db->selectSQLText(
232 'actor_user = user_id',
234 'rc_log_type IS NULL OR rc_log_type != ' . $db->addQuotes(
'newusers' ),
235 'rc_timestamp >= ' . $db->addQuotes( $timestamp ),
244 $sqlLimit = $limit + $maxDuplicateRows;
251 $this->
addFieldsIf(
'user_editcount', $fld_editcount );
252 $this->
addFieldsIf(
'user_registration', $fld_registration );
256 $countDuplicates = 0;
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 && $row->ipb_id !==
null ) {
307 $data += $this->getBlockDetails( DatabaseBlock::newFromRow( $row ) );
309 if ( $row->ipb_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 $data[
'rights'] = $this->groupPermissionsLookup->getGroupPermissions( $groups );
346 ApiResult::setIndexedTagName( $data[
'rights'],
'r' );
347 ApiResult::setArrayType( $data[
'rights'],
'array' );
351 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data );
358 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'u' );
366 $userGroups = $this->userGroupManager->listAllGroups();
377 ParamValidator::PARAM_DEFAULT =>
'ascending',
378 ParamValidator::PARAM_TYPE => [
384 ParamValidator::PARAM_TYPE => $userGroups,
385 ParamValidator::PARAM_ISMULTI =>
true,
388 ParamValidator::PARAM_TYPE => $userGroups,
389 ParamValidator::PARAM_ISMULTI =>
true,
393 ParamValidator::PARAM_ISMULTI =>
true,
396 ParamValidator::PARAM_ISMULTI =>
true,
397 ParamValidator::PARAM_TYPE => [
409 ParamValidator::PARAM_DEFAULT => 10,
410 ParamValidator::PARAM_TYPE =>
'limit',
411 IntegerDef::PARAM_MIN => 1,
415 'witheditsonly' =>
false,
417 ParamValidator::PARAM_DEFAULT =>
false,
419 'apihelp-query+allusers-param-activeusers',
420 $this->
getConfig()->get( MainConfigNames::ActiveUserDays )
423 'attachedwiki' =>
null,