From 4e63c68bb6949dcaabae1ef13b4ce77127ffa7f7 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 9 Aug 2007 08:41:58 +0000 Subject: [PATCH] API: * Added rvprop=size to prop=revisions. Can get the size of all the revisions. The size will not be shown if it is NULL in the database. * (Experimental) list=allpages now allows to filter by article min/max size and protection status (thanks to [[en:user:madman]] for the idea). The database performance of this addition might be so severe that I might have to remove or restrict it. Breaking change: * list=exturlusage XML element's tag is now 'eu' instead of 'p' to be more consistent with the other results. --- includes/api/ApiQueryAllpages.php | 58 ++++++++++++++++++++++++-- includes/api/ApiQueryExtLinksUsage.php | 2 +- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index 3719fe9e10..a76e4ea321 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -55,8 +55,8 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $db = $this->getDB(); $params = $this->extractRequestParams(); - - $this->addTables('page'); + + // Page filters if (!$this->addWhereIf('page_is_redirect = 1', $params['filterredir'] === 'redirects')) $this->addWhereIf('page_is_redirect = 0', $params['filterredir'] === 'nonredirects'); $this->addWhereFld('page_namespace', $params['namespace']); @@ -65,6 +65,39 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { if (isset ($params['prefix'])) $this->addWhere("page_title LIKE '" . $db->escapeLike(ApiQueryBase :: titleToKey($params['prefix'])) . "%'"); + $forceNameTitleIndex = true; + if (isset ($params['minsize'])) { + $this->addWhere('page_len>=' . intval($params['minsize'])); + $forceNameTitleIndex = false; + } + + if (isset ($params['maxsize'])) { + $this->addWhere('page_len<=' . intval($params['maxsize'])); + $forceNameTitleIndex = false; + } + + // Page protection filtering + if (isset ($params['prtype'])) { + $this->addTables('page_restrictions'); + $this->addWhere('page_id=pr_page'); + $this->addWhere('pr_expiry>' . $db->addQuotes($db->timestamp())); + $this->addWhereFld('pr_type', $params['prtype']); + + $prlevel = $params['prlevel']; + if (!is_null($prlevel) && $prlevel != '' && $prlevel != '*') + $this->addWhereFld('pr_level', $prlevel); + + $forceNameTitleIndex = false; + + } else if (isset ($params['prlevel'])) { + $this->dieUsage('prlevel may not be used without prtype', 'params'); + } + + $this->addTables('page'); + if ($forceNameTitleIndex) + $this->addOption('USE INDEX', 'name_title'); + + if (is_null($resultPageSet)) { $this->addFields(array ( 'page_id', @@ -75,7 +108,6 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $this->addFields($resultPageSet->getPageTableFields()); } - $this->addOption('USE INDEX', 'name_title'); $limit = $params['limit']; $this->addOption('LIMIT', $limit+1); $this->addOption('ORDER BY', 'page_namespace, page_title'); @@ -112,12 +144,14 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { } protected function getAllowedParams() { + global $wgRestrictionTypes, $wgRestrictionLevels; + return array ( 'from' => null, 'prefix' => null, 'namespace' => array ( ApiBase :: PARAM_DFLT => 0, - ApiBase :: PARAM_TYPE => 'namespace' + ApiBase :: PARAM_TYPE => 'namespace', ), 'filterredir' => array ( ApiBase :: PARAM_DFLT => 'all', @@ -127,6 +161,18 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { 'nonredirects' ) ), + 'minsize' => array ( + ApiBase :: PARAM_TYPE => 'integer', + ), + 'maxsize' => array ( + ApiBase :: PARAM_TYPE => 'integer', + ), + 'prtype' => array ( + ApiBase :: PARAM_TYPE => $wgRestrictionTypes, + ), + 'prlevel' => array ( + ApiBase :: PARAM_TYPE => $wgRestrictionLevels, + ), 'limit' => array ( ApiBase :: PARAM_DFLT => 10, ApiBase :: PARAM_TYPE => 'limit', @@ -143,6 +189,10 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { 'prefix' => 'Search for all page titles that begin with this value.', 'namespace' => 'The namespace to enumerate.', 'filterredir' => 'Which pages to list.', + 'minsize' => 'Limit to pages with at least this many bytes', + 'maxsize' => 'Limit to pages with at most this many bytes', + 'prtype' => 'Limit to protected pages only', + 'prlevel' => 'The protection level (must be used with apprtype= parameter)', 'limit' => 'How many total pages to return.' ); } diff --git a/includes/api/ApiQueryExtLinksUsage.php b/includes/api/ApiQueryExtLinksUsage.php index 7789451a6c..2e47a5750c 100644 --- a/includes/api/ApiQueryExtLinksUsage.php +++ b/includes/api/ApiQueryExtLinksUsage.php @@ -129,7 +129,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { if (is_null($resultPageSet)) { $result = $this->getResult(); - $result->setIndexedTagName($data, 'p'); + $result->setIndexedTagName($data, $this->getModulePrefix()); $result->addValue('query', $this->getModuleName(), $data); } } -- 2.20.1