From 9537e2dea795d65a79306fbe9855ce4e096c8836 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 16 Jul 2008 15:42:55 +0000 Subject: [PATCH] (bug 14020) Added an API interface to Special:Unwatchedpages in the form of the apfilterwatched parameter to list=allpages. If $wgMiserMode is true or if the user doesn't have the 'unwatchedpages' right, apfilterwatched is ignored and a warning is output. --- RELEASE-NOTES | 1 + includes/api/ApiQueryAllpages.php | 35 +++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 6db1ed51e4..6c18eaa37b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -530,6 +530,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Added flag "top" to list=usercontribs if the user is the last contributor to the page * list=exturlusage in "list all links" mode can now filter by protocol +* (bug 14020) Added apfilterwatched parameter to list=allpages === Languages updated in 1.13 === diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index c4ac486cf6..3176a87019 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -51,7 +51,6 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { } private function run($resultPageSet = null) { - $db = $this->getDB(); $params = $this->extractRequestParams(); @@ -97,6 +96,29 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $this->dieUsage('prlevel may not be used without prtype', 'params'); } + // Only allow watched page filtering if the user has the 'unwatchedpages' permission + // $wgMiserMode disables this + global $wgUser, $wgMiserMode; + if ($wgUser->isAllowed('unwatchedpages') && !$wgMiserMode) { + if($params['filterwatched'] != 'all') { + $this->addTables('watchlist'); + $this->addJoinConds(array('watchlist' => array('LEFT JOIN', array( + 'wl_namespace = page_namespace', + 'wl_title = page_title')))); + } + if($params['filterwatched'] == 'unwatched') { + $this->addWhere('wl_title IS NULL'); + } + else if ($params['filterwatched'] == 'watched') { + $this->addWhere('wl_title IS NOT NULL'); + } + } + else if($params['filterwatched'] != 'all') { + if($wgMiserMode) + $this->setWarning('apfilterwatched is disabled on this wiki for performance reasons'); + else + $this->setWarning('You don\'t have permission to filter by watched status'); + } if($params['filterlanglinks'] == 'withoutlanglinks') { $this->addTables('langlinks'); $this->addJoinConds(array('langlinks' => array('LEFT JOIN', 'page_id=ll_from'))); @@ -108,7 +130,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $forceNameTitleIndex = false; } if ($forceNameTitleIndex) - $this->addOption('USE INDEX', 'name_title'); + $this->addOption('USE INDEX', array('page' => 'name_title')); if (is_null($resultPageSet)) { $this->addFields(array ( @@ -206,6 +228,14 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { 'all' ), ApiBase :: PARAM_DFLT => 'all' + ), + 'filterwatched' => array( + ApiBase :: PARAM_TYPE => array( + 'watched', + 'unwatched', + 'all' + ), + ApiBase :: PARAM_DFLT => 'all' ) ); } @@ -222,6 +252,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { 'prtype' => 'Limit to protected pages only', 'prlevel' => 'The protection level (must be used with apprtype= parameter)', 'filterlanglinks' => 'Filter based on whether a page has langlinks', + 'filterwatched' => 'Filter based on whther a page is watched (requires \'unwatchedpages\' right)', 'limit' => 'How many total pages to return.' ); } -- 2.20.1