API: (bug 14200) Add user and excludeuser to list=recentchanges and list=watchlist...
[lhc/web/wiklou.git] / includes / api / ApiQueryRecentChanges.php
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
+}