API: (bug 14200) Add user and excludeuser to list=recentchanges and list=watchlist...
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 19 Jun 2009 08:03:52 +0000 (08:03 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 19 Jun 2009 08:03:52 +0000 (08:03 +0000)
RELEASE-NOTES
includes/api/ApiQueryRecentChanges.php
includes/api/ApiQueryWatchlist.php

index 4ba479d..d153ff4 100644 (file)
@@ -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 ===
 
index 13e7375..3b7ae2c 100644 (file)
@@ -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
+}
index fa126f8..3d73175 100644 (file)
@@ -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
+}