* API watchlist: Forced an index, enabled generator
authorYuri Astrakhan <yurik@users.mediawiki.org>
Sat, 14 Oct 2006 16:02:42 +0000 (16:02 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Sat, 14 Oct 2006 16:02:42 +0000 (16:02 +0000)
includes/api/ApiMain.php
includes/api/ApiOpenSearch.php
includes/api/ApiPageSet.php
includes/api/ApiQueryWatchlist.php

index 05eff56..2c437f1 100644 (file)
@@ -46,8 +46,8 @@ class ApiMain extends ApiBase {
        private static $Modules = array (
                'help' => 'ApiHelp',
                'login' => 'ApiLogin',
-               'query' => 'ApiQuery',
-               'opensearch' => 'ApiOpenSearch'
+               'opensearch' => 'ApiOpenSearch',
+               'query' => 'ApiQuery'
        );
 
        /**
index 8c24861..f86467e 100644 (file)
@@ -34,7 +34,7 @@ class ApiOpenSearch extends ApiFormatBase {
        private $mResult = array();
        
        public function __construct($main, $action) {
-               parent :: __construct($main, 'opensearch');
+               parent :: __construct($main, $action);
        }
 
        public function getMimeType() {
index 5650be9..53cd59a 100644 (file)
@@ -229,6 +229,16 @@ class ApiPageSet extends ApiQueryBase {
                $this->profileOut();
        }
 
+       /**
+        * Initialize PageSet from a list of Revision IDs
+        */
+       public function populateFromRevisionIDs($revIDs) {
+               $this->profileIn();
+               $pageIDs = array_map('intval', $revIDs); // paranoia
+               $this->initFromRevIDs($revIDs);
+               $this->profileOut();
+       }
+
        /**
         * Extract all requested fields from the row received from the database
         */
index 9170e7f..0033d5c 100644 (file)
@@ -54,30 +54,52 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
 
                $db = $this->getDB();
 
+               $dirNewer = ($dir === 'newer');
+               $before = ($dirNewer ? '<=' : '>=');
+               $after = ($dirNewer ? '>=' : '<=');
+
                $tables = array (
                        'watchlist',
-                       'recentchanges',
-                       'page'
-               );
-               $fields = array (
-                       'rc_namespace AS page_namespace',
-                       'rc_title AS page_title',
-                       'rc_comment AS rev_comment',
-                       'rc_cur_id AS page_id',
-                       'rc_user AS rev_user',
-                       'rc_user_text AS rev_user_text',
-                       'rc_timestamp AS rev_timestamp',
-                       'rc_minor AS rev_minor_edit',
-                       'rc_this_oldid AS rev_id',
-                       'rc_last_oldid',
-                       'rc_id',
-//                     'rc_patrolled',
-                       'rc_new AS page_is_new'
+                       'page',
+                       'recentchanges'
                );
 
-               $dirNewer = ($dir === 'newer');
-               $before = ($dirNewer ? '<=' : '>=');
-               $after = ($dirNewer ? '>=' : '<=');
+               $options = array (
+                       'LIMIT' => $limit +1,
+                       'ORDER BY' => 'rc_timestamp' . ($dirNewer ? '' : ' DESC'),
+                       'USE INDEX' => 'rc_timestamp');
+
+               if (is_null($resultPageSet)) {
+                       $fields = array (
+                               'rc_namespace AS page_namespace',
+                               'rc_title AS page_title',
+                               'rc_comment AS rev_comment',
+                               'rc_cur_id AS page_id',
+                               'rc_user AS rev_user',
+                               'rc_user_text AS rev_user_text',
+                               'rc_timestamp AS rev_timestamp',
+                               'rc_minor AS rev_minor_edit',
+                               'rc_this_oldid AS rev_id',
+                               'rc_last_oldid',
+                               'rc_id',
+       //                      'rc_patrolled',
+                               'rc_new AS page_is_new'
+                       );
+               } elseif ($allrev) {
+                       $fields = array (
+                               'rc_this_oldid AS rev_id',
+                               'rc_namespace AS page_namespace',
+                               'rc_title AS page_title',
+                               'rc_timestamp AS rev_timestamp'
+                       );
+               } else {
+                       $fields = array (
+                               'rc_cur_id AS page_id',
+                               'rc_namespace AS page_namespace',
+                               'rc_title AS page_title',
+                               'rc_timestamp AS rev_timestamp'
+                       );
+               }
 
                $where = array (
                        'wl_namespace = rc_namespace',
@@ -94,21 +116,6 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                if (isset ($end))
                        $where[] = 'rev_timestamp' . $before . $db->addQuotes($end);
 
-               //              if (is_null($resultPageSet)) {
-               //                      $fields = array (
-               //                              'page_id',
-               //                              'page_namespace',
-               //                              'page_title'
-               //                      );
-               //              } else {
-               //                      $fields = $resultPageSet->getPageTableFields();
-               //              }
-
-               $options = array (
-                       'LIMIT' => $limit +1,
-                       'ORDER BY' => 'rc_timestamp' . ($dirNewer ? '' : ' DESC'
-               ));
-
                $this->profileDBIn();
                $res = $db->select($tables, $fields, $where, __METHOD__, $options);
                $this->profileDBOut();
@@ -147,9 +154,11 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
 //                                             'rc_patrolled' => $row->rc_patrolled,
                                                'isnew' => $row->page_is_new
                                        );
+                               } elseif ($allrev) {
+                                       $data[] = intval($row->rev_id);
                                } else {
-//                                     $resultPageSet->processDbRow($row);
-                               }
+                                       $data[] = intval($row->page_id);
+                               }                               
                        }
                }
                $db->freeResult($res);
@@ -157,7 +166,11 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                if (is_null($resultPageSet)) {
                        ApiResult :: setIndexedTagName($data, 'p');
                        $this->getResult()->addValue('query', 'watchlist', $data);
-               }
+               } elseif ($allrev) {
+                       $resultPageSet->populateFromRevisionIDs($data);
+               } else {
+                       $resultPageSet->populateFromPageIDs($data);
+               }                               
        }
 
        protected function getAllowedParams() {
@@ -209,7 +222,9 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
        protected function getExamples() {
                return array (
                        'api.php?action=query&list=watchlist',
-                       'api.php?action=query&list=watchlist&wlallrev'
+                       'api.php?action=query&list=watchlist&wlallrev',
+                       'api.php?action=query&generator=watchlist&prop=info',
+                       'api.php?action=query&generator=watchlist&gwlallrev&prop=revisions&rvprop=timestamp|user'
                );
        }