From 6d8d92d33333dcbfcb78d429958c2848a7d018d9 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 19 Jun 2009 08:03:52 +0000 Subject: [PATCH] API: (bug 14200) Add user and excludeuser to list=recentchanges and list=watchlist. Requires the rc_user_text index, which was finally added on all servers with the recent schema changes. --- RELEASE-NOTES | 2 ++ includes/api/ApiQueryRecentChanges.php | 28 +++++++++++++++++++++++--- includes/api/ApiQueryWatchlist.php | 17 +++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 4ba479d2fa..d153ff4b43 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -223,6 +223,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Made deleting file description pages without files possible * (bug 18773) Add content flag to siprop=namespaces output * (bug 18785) Add siprop=languages to meta=siteinfo +* (bug 14200) Added user and excludeuser parameters to list=watchlist and + list=recentchanges === Languages updated in 1.16 === diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 13e7375f08..3b7ae2cede 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -95,7 +95,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { */ $db = $this->getDB(); $this->addTables('recentchanges'); - $this->addOption('USE INDEX', array('recentchanges' => 'rc_timestamp')); + $index = 'rc_timestamp'; // May change $this->addWhereRange('rc_timestamp', $params['dir'], $params['start'], $params['end']); $this->addWhereFld('rc_namespace', $params['namespace']); $this->addWhereFld('rc_deleted', 0); @@ -134,8 +134,21 @@ class ApiQueryRecentChanges extends ApiQueryBase { // Don't throw log entries out the window here $this->addWhereIf('page_is_redirect = 0 OR page_is_redirect IS NULL', isset ($show['!redirect'])); } + + if(!is_null($params['user']) && !is_null($param['excludeuser'])) + $this->dieUsage('user and excludeuser cannot be used together', 'user-excludeuser'); + if(!is_null($params['user'])) + { + $this->addWhereFld('rc_user_text', $params['user']); + $index = 'rc_user_text'; + } + if(!is_null($params['excludeuser'])) + // We don't use the rc_user_text index here because + // * it would require us to sort by rc_user_text before rc_timestamp + // * the != condition doesn't throw out too many rows anyway + $this->addWhere('rc_user_text != ' . $this->getDB()->addQuotes($params['excludeuser'])); - /* Add the fields we're concerned with to out query. */ + /* Add the fields we're concerned with to our query. */ $this->addFields(array ( 'rc_timestamp', 'rc_namespace', @@ -192,6 +205,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { } $this->token = $params['token']; $this->addOption('LIMIT', $params['limit'] +1); + $this->addOption('USE INDEX', array('recentchanges' => $index)); $count = 0; /* Perform the actual query. */ @@ -374,6 +388,12 @@ class ApiQueryRecentChanges extends ApiQueryBase { ApiBase :: PARAM_ISMULTI => true, ApiBase :: PARAM_TYPE => 'namespace' ), + 'user' => array( + ApiBase :: PARAM_TYPE => 'user' + ), + 'excludeuser' => array( + ApiBase :: PARAM_TYPE => 'user' + ), 'prop' => array ( ApiBase :: PARAM_ISMULTI => true, ApiBase :: PARAM_DFLT => 'title|timestamp|ids', @@ -433,6 +453,8 @@ class ApiQueryRecentChanges extends ApiQueryBase { 'end' => 'The timestamp to end enumerating.', 'dir' => 'In which direction to enumerate.', 'namespace' => 'Filter log entries to only this namespace(s)', + 'user' => 'Only list changes by this user', + 'excludeuser' => 'Don\'t list changes by this user', 'prop' => 'Include additional pieces of information', 'token' => 'Which tokens to obtain for each change', 'show' => array ( @@ -457,4 +479,4 @@ class ApiQueryRecentChanges extends ApiQueryBase { public function getVersion() { return __CLASS__ . ': $Id$'; } -} \ No newline at end of file +} diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index fa126f865d..3d731758c2 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -162,6 +162,13 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $this->addWhereIf('rc_patrolled = 0', isset($show['!patrolled'])); $this->addWhereIf('rc_patrolled != 0', isset($show['patrolled'])); } + + if(!is_null($params['user']) && !is_null($params['excludeuser'])) + $this->dieUsage('user and excludeuser cannot be used together', 'user-excludeuser'); + if(!is_null($params['user'])) + $this->addWhereFld('rc_user_text', $params['user']); + if(!is_null($params['excludeuser'])) + $this->addWhere('rc_user_text != ' . $this->getDB()->addQuotes($params['excludeuser'])); # This is an index optimization for mysql, as done in the Special:Watchlist page @@ -268,6 +275,12 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { ApiBase :: PARAM_ISMULTI => true, ApiBase :: PARAM_TYPE => 'namespace' ), + 'user' => array( + ApiBase :: PARAM_TYPE => 'user', + ), + 'excludeuser' => array( + ApiBase :: PARAM_TYPE => 'user', + ), 'dir' => array ( ApiBase :: PARAM_DFLT => 'older', ApiBase :: PARAM_TYPE => array ( @@ -318,6 +331,8 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { 'start' => 'The timestamp to start enumerating from.', 'end' => 'The timestamp to end enumerating.', 'namespace' => 'Filter changes to only the given namespace(s).', + 'user' => 'Only list changes by this user', + 'excludeuser' => 'Don\'t list changes by this user', 'dir' => 'In which direction to enumerate pages.', 'limit' => 'How many total results to return per request.', 'prop' => 'Which additional items to get (non-generator mode only).', @@ -345,4 +360,4 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { public function getVersion() { return __CLASS__ . ': $Id$'; } -} \ No newline at end of file +} -- 2.20.1