49 $activeUserDays = $this->
getConfig()->get(
'ActiveUserDays' );
53 $prop = $params[
'prop'];
54 if ( $prop !==
null ) {
55 $prop = array_flip( $prop );
56 $fld_blockinfo = isset( $prop[
'blockinfo'] );
57 $fld_editcount = isset( $prop[
'editcount'] );
58 $fld_groups = isset( $prop[
'groups'] );
59 $fld_rights = isset( $prop[
'rights'] );
60 $fld_registration = isset( $prop[
'registration'] );
61 $fld_implicitgroups = isset( $prop[
'implicitgroups'] );
62 $fld_centralids = isset( $prop[
'centralids'] );
64 $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration =
65 $fld_rights = $fld_implicitgroups = $fld_centralids =
false;
68 $limit = $params[
'limit'];
72 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
76 # MySQL can't figure out that 'user_name' and 'qcc_title' are the same
77 # despite the JOIN condition, so manually sort on the correct one.
78 $userFieldToSort = $params[
'activeusers'] ?
'qcc_title' :
'user_name';
80 # Some of these subtable joins are going to give us duplicate rows, so
81 # calculate the maximum number of duplicates we might see.
82 $maxDuplicateRows = 1;
86 if ( $params[
'prefix'] !==
null ) {
88 $db->buildLike( $this->getCanonicalUserName( $params[
'prefix'] ), $db->anyString() ) );
91 if ( $params[
'rights'] !==
null && count( $params[
'rights'] ) ) {
93 foreach ( $params[
'rights'] as $r ) {
95 ->getGroupsWithPermission( $r ) );
99 if ( $groups === [] ) {
105 $groups = array_unique( $groups );
107 if ( $params[
'group'] ===
null ) {
108 $params[
'group'] = $groups;
110 $params[
'group'] = array_unique( array_merge( $params[
'group'], $groups ) );
116 if ( $params[
'group'] !==
null && count( $params[
'group'] ) ) {
119 $this->
addTables(
'user_groups',
'ug1' );
124 'ug1.ug_user=user_id',
125 'ug1.ug_group' => $params[
'group'],
126 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
130 $maxDuplicateRows *= count( $params[
'group'] );
133 if ( $params[
'excludegroup'] !==
null && count( $params[
'excludegroup'] ) ) {
136 $this->
addTables(
'user_groups',
'ug1' );
138 if ( count( $params[
'excludegroup'] ) == 1 ) {
139 $exclude = [
'ug1.ug_group' => $params[
'excludegroup'][0] ];
141 $exclude = [ $db->makeList(
142 [
'ug1.ug_group' => $params[
'excludegroup'] ],
148 'ug1.ug_user=user_id',
149 'ug1.ug_expiry IS NULL OR ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
152 $this->
addWhere(
'ug1.ug_user IS NULL' );
155 if ( $params[
'witheditsonly'] ) {
156 $this->
addWhere(
'user_editcount > 0' );
161 if ( $fld_groups || $fld_rights ) {
163 $db->buildGroupConcatField(
'|',
'user_groups',
'ug_group', [
165 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
170 if ( $params[
'activeusers'] ) {
171 $activeUserSeconds = $activeUserDays * 86400;
178 'qcc_type' =>
'activeusers',
180 'qcc_title=user_name',
185 $tables = [
'recentchanges',
'actor' ];
187 'actor' => [
'JOIN',
'rc_actor = actor_id' ],
189 $timestamp = $db->timestamp( (
int)
wfTimestamp( TS_UNIX ) - $activeUserSeconds );
191 'recentactions' =>
'(' . $db->selectSQLText(
195 'actor_user = user_id',
197 'rc_log_type IS NULL OR rc_log_type != ' . $db->addQuotes(
'newusers' ),
198 'rc_timestamp >= ' . $db->addQuotes( $timestamp ),
207 $sqlLimit = $limit + $maxDuplicateRows;
214 $this->
addFieldsIf(
'user_editcount', $fld_editcount );
215 $this->
addFieldsIf(
'user_registration', $fld_registration );
219 $countDuplicates = 0;
222 foreach (
$res as $row ) {
225 if ( $lastUser === $row->user_name ) {
230 if ( $countDuplicates == $maxDuplicateRows ) {
236 $countDuplicates = 0;
237 $lastUser = $row->user_name;
239 if ( $count > $limit ) {
246 if ( $count == $sqlLimit ) {
253 if ( $params[
'activeusers'] && $row->recentactions === 0 ) {
259 'userid' => (int)$row->user_id,
260 'name' => $row->user_name,
263 if ( $fld_centralids ) {
269 if ( $fld_blockinfo && $row->ipb_id !==
null ) {
270 $data += $this->getBlockDetails( DatabaseBlock::newFromRow( $row ) );
272 if ( $row->ipb_deleted ) {
273 $data[
'hidden'] =
true;
275 if ( $fld_editcount ) {
276 $data[
'editcount'] = (int)$row->user_editcount;
278 if ( $params[
'activeusers'] ) {
279 $data[
'recentactions'] = (int)$row->recentactions;
281 if ( $fld_registration ) {
282 $data[
'registration'] = $row->user_registration ?
283 wfTimestamp( TS_ISO_8601, $row->user_registration ) :
'';
286 if ( $fld_implicitgroups || $fld_groups || $fld_rights ) {
287 $implicitGroups =
User::newFromId( $row->user_id )->getAutomaticGroups();
288 if ( isset( $row->groups ) && $row->groups !==
'' ) {
289 $groups = array_merge( $implicitGroups, explode(
'|', $row->groups ) );
291 $groups = $implicitGroups;
295 $data[
'groups'] = $groups;
296 ApiResult::setIndexedTagName( $data[
'groups'],
'g' );
297 ApiResult::setArrayType( $data[
'groups'],
'array' );
300 if ( $fld_implicitgroups ) {
301 $data[
'implicitgroups'] = $implicitGroups;
302 ApiResult::setIndexedTagName( $data[
'implicitgroups'],
'g' );
303 ApiResult::setArrayType( $data[
'implicitgroups'],
'array' );
308 ApiResult::setIndexedTagName( $data[
'rights'],
'r' );
309 ApiResult::setArrayType( $data[
'rights'],
'array' );
313 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data );
320 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'u' );