From 237eb87db4be74b26dbf239bac87c419f2672a54 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sun, 13 Mar 2011 19:07:22 +0000 Subject: [PATCH] * (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 --- RELEASE-NOTES | 1 + includes/api/ApiQueryAllUsers.php | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c97dfd7d3a..5cb268b66a 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -252,6 +252,7 @@ PHP if you have not done so prior to upgrading MediaWiki. * (bug 27342) Add audir param to list=allusers * (bug 27203) add fato param to list=filearchive * (bug 27341) Add drto param to list=deletedrevs +* (bug 26630) Add api for Special:ActiveUsers === Languages updated in 1.18 === diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index 650c50cc3a..12ec64459f 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -56,6 +56,7 @@ class ApiQueryAllUsers extends ApiQueryBase { } $limit = $params['limit']; + $this->addTables( 'user' ); $useIndex = true; @@ -97,6 +98,8 @@ class ApiQueryAllUsers extends ApiQueryBase { $this->addWhere( 'user_editcount > 0' ); } + $this->showHiddenUsersAddBlockInfo( $fld_blockinfo ); + if ( $fld_groups || $fld_rights ) { // Show the groups the given users belong to // request more than needed to avoid not getting all rows that belong to one user @@ -111,7 +114,20 @@ class ApiQueryAllUsers extends ApiQueryBase { $sqlLimit = $limit + 1; } - $this->showHiddenUsersAddBlockInfo( $fld_blockinfo ); + if ( $params['activeusers'] ) { + global $wgActiveUserDays; + $this->addTables( 'recentchanges' ); + + $this->addJoinConds( array( 'recentchanges' => array( + 'INNER JOIN', 'rc_user=user_id' + ) ) ); + + $this->addFields( 'COUNT(*) AS recentedits' ); + + $this->addWhere( "rc_log_type IS NULL OR rc_log_type != 'newusers'" ); + $timestamp = $db->timestamp( wfTimestamp( TS_UNIX ) - $wgActiveUserDays*24*3600 ); + $this->addWhere( "rc_timestamp >= {$db->addQuotes( $timestamp )}" ); + } $this->addOption( 'LIMIT', $sqlLimit ); @@ -181,11 +197,13 @@ class ApiQueryAllUsers extends ApiQueryBase { if ( $fld_editcount ) { $lastUserData['editcount'] = intval( $row->user_editcount ); } + if ( $params['activeusers'] ) { + $lastUserData['recenteditcount'] = intval( $row->recentedits ); + } if ( $fld_registration ) { $lastUserData['registration'] = $row->user_registration ? wfTimestamp( TS_ISO_8601, $row->user_registration ) : ''; } - } if ( $sqlLimit == $count ) { @@ -270,10 +288,12 @@ class ApiQueryAllUsers extends ApiQueryBase { ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 ), 'witheditsonly' => false, + 'activeusers' => false, ); } public function getParamDescription() { + global $wgActiveUserDays; return array( 'from' => 'The user name to start enumerating from', 'to' => 'The user name to stop enumerating at', @@ -291,6 +311,7 @@ class ApiQueryAllUsers extends ApiQueryBase { ), 'limit' => 'How many total user names to return', 'witheditsonly' => 'Only list users who have made edits', + 'activeusers' => "Only list users active in the last {$wgActiveUserDays} days(s)" ); } -- 2.20.1