Patch from MaxSem re bug 15162 - handle throttling in the login API
[lhc/web/wiklou.git] / includes / api / ApiQueryWatchlist.php
index e5f2d03..17467e0 100644 (file)
@@ -31,8 +31,8 @@ if (!defined('MEDIAWIKI')) {
 /**
  * This query action allows clients to retrieve a list of recently modified pages
  * that are part of the logged-in user's watchlist.
- * 
- * @addtogroup API
+ *
+ * @ingroup API
  */
 class ApiQueryWatchlist extends ApiQueryGeneratorBase {
 
@@ -50,7 +50,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
 
        private $fld_ids = false, $fld_title = false, $fld_patrol = false, $fld_flags = false,
                        $fld_timestamp = false, $fld_user = false, $fld_comment = false, $fld_sizes = false;
-       
+
        private function run($resultPageSet = null) {
                global $wgUser, $wgDBtype;
 
@@ -59,7 +59,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                if (!$wgUser->isLoggedIn())
                        $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
 
-               $allrev = $start = $end = $namespace = $dir = $limit = $prop = null;
+               $allrev = $start = $end = $namespace = $dir = $limit = $prop = $show = null;
                extract($this->extractRequestParams());
 
                if (!is_null($prop) && is_null($resultPageSet)) {
@@ -122,7 +122,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                        'recentchanges'
                ));
 
-               $userId = $wgUser->getID();
+               $userId = $wgUser->getId();
                $this->addWhere(array (
                        'wl_namespace = rc_namespace',
                        'wl_title = rc_title',
@@ -134,8 +134,29 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                $this->addWhereRange('rc_timestamp', $dir, $start, $end);
                $this->addWhereFld('wl_namespace', $namespace);
                $this->addWhereIf('rc_this_oldid=page_latest', !$allrev);
-               
-               # This is a index optimization for mysql, as done in the Special:Watchlist page
+
+               if (!is_null($show)) {
+                       $show = array_flip($show);
+
+                       /* Check for conflicting parameters. */
+                       if ((isset ($show['minor']) && isset ($show['!minor']))
+                                       || (isset ($show['bot']) && isset ($show['!bot']))
+                                       || (isset ($show['anon']) && isset ($show['!anon']))) {
+
+                               $this->dieUsage("Incorrect parameter - mutually exclusive values may not be supplied", 'show');
+                       }
+
+                       /* Add additional conditions to query depending upon parameters. */
+                       $this->addWhereIf('rc_minor = 0', isset ($show['!minor']));
+                       $this->addWhereIf('rc_minor != 0', isset ($show['minor']));
+                       $this->addWhereIf('rc_bot = 0', isset ($show['!bot']));
+                       $this->addWhereIf('rc_bot != 0', isset ($show['bot']));
+                       $this->addWhereIf('rc_user = 0', isset ($show['anon']));
+                       $this->addWhereIf('rc_user != 0', isset ($show['!anon']));
+               }
+
+
+               # This is an index optimization for mysql, as done in the Special:Watchlist page
                $this->addWhereIf("rc_timestamp > ''", !isset ($start) && !isset ($end) && $wgDBtype == 'mysql');
 
                $this->addOption('LIMIT', $limit +1);
@@ -184,9 +205,9 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
 
                if ($this->fld_ids) {
                        $vals['pageid'] = intval($row->rc_cur_id);
-                       $vals['revid'] = intval($row->rc_this_oldid); 
+                       $vals['revid'] = intval($row->rc_this_oldid);
                }
-               
+
                if ($this->fld_title)
                        ApiQueryBase :: addTitleInfo($vals, Title :: makeTitle($row->rc_namespace, $row->rc_title));
 
@@ -222,7 +243,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                return $vals;
        }
 
-       protected function getAllowedParams() {
+       public function getAllowedParams() {
                return array (
                        'allrev' => false,
                        'start' => array (
@@ -262,24 +283,39 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                                        'patrol',
                                        'sizes',
                                )
+                       ),
+                       'show' => array (
+                               ApiBase :: PARAM_ISMULTI => true,
+                               ApiBase :: PARAM_TYPE => array (
+                                       'minor',
+                                       '!minor',
+                                       'bot',
+                                       '!bot',
+                                       'anon',
+                                       '!anon'
+                               )
                        )
                );
        }
 
-       protected function getParamDescription() {
+       public function getParamDescription() {
                return array (
                        'allrev' => 'Include multiple revisions of the same page within given timeframe.',
                        'start' => 'The timestamp to start enumerating from.',
                        'end' => 'The timestamp to end enumerating.',
                        'namespace' => 'Filter changes to only the given namespace(s).',
                        'dir' => 'In which direction to enumerate pages.',
-                       'limit' => 'How many total pages to return per request.',
-                       'prop' => 'Which additional items to get (non-generator mode only).'
+                       'limit' => 'How many total results to return per request.',
+                       'prop' => 'Which additional items to get (non-generator mode only).',
+                       'show' => array (
+                               'Show only items that meet this criteria.',
+                               'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
+                       )
                );
        }
 
-       protected function getDescription() {
-               return '';
+       public function getDescription() {
+               return "Get all recent changes to pages in the logged in user's watchlist";
        }
 
        protected function getExamples() {
@@ -296,4 +332,3 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                return __CLASS__ . ': $Id$';
        }
 }
-