r83849 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83848‎ | r83849 | r83850 >
Date:19:07, 13 March 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
* (bug 26630) Add api for Special:ActiveUsers

Not sure if this would be better having been done as list=activeusers or something...

Meh, done! :P
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllUsers.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES
@@ -252,6 +252,7 @@
253253 * (bug 27342) Add audir param to list=allusers
254254 * (bug 27203) add fato param to list=filearchive
255255 * (bug 27341) Add drto param to list=deletedrevs
 256+* (bug 26630) Add api for Special:ActiveUsers
256257
257258 === Languages updated in 1.18 ===
258259
Index: trunk/phase3/includes/api/ApiQueryAllUsers.php
@@ -56,6 +56,7 @@
5757 }
5858
5959 $limit = $params['limit'];
 60+
6061 $this->addTables( 'user' );
6162 $useIndex = true;
6263
@@ -97,6 +98,8 @@
9899 $this->addWhere( 'user_editcount > 0' );
99100 }
100101
 102+ $this->showHiddenUsersAddBlockInfo( $fld_blockinfo );
 103+
101104 if ( $fld_groups || $fld_rights ) {
102105 // Show the groups the given users belong to
103106 // request more than needed to avoid not getting all rows that belong to one user
@@ -111,8 +114,21 @@
112115 $sqlLimit = $limit + 1;
113116 }
114117
115 - $this->showHiddenUsersAddBlockInfo( $fld_blockinfo );
 118+ if ( $params['activeusers'] ) {
 119+ global $wgActiveUserDays;
 120+ $this->addTables( 'recentchanges' );
116121
 122+ $this->addJoinConds( array( 'recentchanges' => array(
 123+ 'INNER JOIN', 'rc_user=user_id'
 124+ ) ) );
 125+
 126+ $this->addFields( 'COUNT(*) AS recentedits' );
 127+
 128+ $this->addWhere( "rc_log_type IS NULL OR rc_log_type != 'newusers'" );
 129+ $timestamp = $db->timestamp( wfTimestamp( TS_UNIX ) - $wgActiveUserDays*24*3600 );
 130+ $this->addWhere( "rc_timestamp >= {$db->addQuotes( $timestamp )}" );
 131+ }
 132+
117133 $this->addOption( 'LIMIT', $sqlLimit );
118134
119135 $this->addFields( array(
@@ -181,11 +197,13 @@
182198 if ( $fld_editcount ) {
183199 $lastUserData['editcount'] = intval( $row->user_editcount );
184200 }
 201+ if ( $params['activeusers'] ) {
 202+ $lastUserData['recenteditcount'] = intval( $row->recentedits );
 203+ }
185204 if ( $fld_registration ) {
186205 $lastUserData['registration'] = $row->user_registration ?
187206 wfTimestamp( TS_ISO_8601, $row->user_registration ) : '';
188207 }
189 -
190208 }
191209
192210 if ( $sqlLimit == $count ) {
@@ -270,10 +288,12 @@
271289 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
272290 ),
273291 'witheditsonly' => false,
 292+ 'activeusers' => false,
274293 );
275294 }
276295
277296 public function getParamDescription() {
 297+ global $wgActiveUserDays;
278298 return array(
279299 'from' => 'The user name to start enumerating from',
280300 'to' => 'The user name to stop enumerating at',
@@ -291,6 +311,7 @@
292312 ),
293313 'limit' => 'How many total user names to return',
294314 'witheditsonly' => 'Only list users who have made edits',
 315+ 'activeusers' => "Only list users active in the last {$wgActiveUserDays} days(s)"
295316 );
296317 }
297318

Follow-up revisions

RevisionCommit summaryAuthorDate
r83851Add missing group by from r83849 per Bryanreedy19:35, 13 March 2011
r83883Followup r83849, fix join to be on indexed user_namereedy11:07, 14 March 2011

Comments

#Comment by Bryan (talk | contribs)   19:23, 13 March 2011

Missing a GROUP BY?

#Comment by Reedy (talk | contribs)   19:24, 13 March 2011
mysql> SELECT /* ApiQueryAllUsers::execute 192.168.0.25 */  COUNT(*) AS recentedits,ipb_deleted,user_name,user_id,user_editcount  FROM `mw_user` FORCE INDEX (user_name) INNER JOIN `mw_recentchanges` ON ((rc_user=user_id)) LEFT JOIN `mw_ipblocks` ON ((ipb_user=user_id))  WHERE (rc_log_type IS NULL OR rc_log_type != 'newusers') AND (rc_timestamp >= '20110211190445') AND (ipb_deleted = 0 OR ipb_deleted IS NULL)  ORDER BY user_name LIMIT 11
    -> ;
+-------------+-------------+-----------+---------+----------------+
| recentedits | ipb_deleted | user_name | user_id | user_editcount |
+-------------+-------------+-----------+---------+----------------+
|          23 |        NULL | Reedy     |       1 |             27 |
+-------------+-------------+-----------+---------+----------------+
1 row in set (0.00 sec)
#Comment by Catrope (talk | contribs)   09:22, 14 March 2011

Join should be on user text, not user ID, see r83845 CR.

#Comment by Aaron Schulz (talk | contribs)   19:29, 16 June 2011

+ showHiddenUsersAddBlockInfo

Is adding that filter a serious bug fix (mergable)? Also, I that function has a confusing name.

Status & tagging log