From 9262f69c0a234f6a55a5802be57e7bf5997f6509 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 14 Oct 2006 16:02:42 +0000 Subject: [PATCH] * API watchlist: Forced an index, enabled generator --- includes/api/ApiMain.php | 4 +- includes/api/ApiOpenSearch.php | 2 +- includes/api/ApiPageSet.php | 10 ++++ includes/api/ApiQueryWatchlist.php | 93 +++++++++++++++++------------- 4 files changed, 67 insertions(+), 42 deletions(-) diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 05eff56292..2c437f1320 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -46,8 +46,8 @@ class ApiMain extends ApiBase { private static $Modules = array ( 'help' => 'ApiHelp', 'login' => 'ApiLogin', - 'query' => 'ApiQuery', - 'opensearch' => 'ApiOpenSearch' + 'opensearch' => 'ApiOpenSearch', + 'query' => 'ApiQuery' ); /** diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index 8c24861df8..f86467ed23 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -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() { diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 5650be98ac..53cd59ad15 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -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 */ diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 9170e7f6b5..0033d5c56d 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -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' ); } -- 2.20.1