5 * Created on Sep 25, 2006
7 * API for MediaWiki 1.8+
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * http://www.gnu.org/copyleft/gpl.html
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ('ApiQueryBase.php');
32 class ApiQueryAllpages
extends ApiQueryGeneratorBase
{
34 public function __construct($query, $moduleName) {
35 parent
:: __construct($query, $moduleName, 'ap');
38 public function execute() {
42 public function executeGenerator($resultPageSet) {
43 if ($resultPageSet->isResolvingRedirects())
44 $this->dieUsage('Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator', 'params');
46 $this->run($resultPageSet);
49 private function run($resultPageSet = null) {
50 $limit = $from = $namespace = $filterredir = null;
51 extract($this->extractRequestParams());
56 'page_namespace' => $namespace
60 $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase
:: titleToKey($from));
63 if ($filterredir === 'redirects') {
64 $where['page_is_redirect'] = 1;
66 elseif ($filterredir === 'nonredirects') {
67 $where['page_is_redirect'] = 0;
70 if (is_null($resultPageSet)) {
77 $fields = $resultPageSet->getPageTableFields();
81 'USE INDEX' => 'name_title',
83 'ORDER BY' => 'page_namespace, page_title'
87 $res = $db->select('page', $fields, $where, __METHOD__
, $options);
88 $this->profileDBOut();
92 while ($row = $db->fetchObject($res)) {
93 if (++
$count > $limit) {
94 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
96 'continue' => $this->encodeParamName('from'
97 ) . '=' . ApiQueryBase
:: keyToTitle($row->page_title
));
98 $this->getResult()->addValue('query-status', 'allpages', $msg);
102 $title = Title
:: makeTitle($row->page_namespace
, $row->page_title
);
103 // skip any pages that user has no rights to read
104 if ($title->userCanRead()) {
106 if (is_null($resultPageSet)) {
107 $id = intval($row->page_id
);
110 'ns' => $title->getNamespace(),
111 'title' => $title->getPrefixedText());
113 $resultPageSet->processDbRow($row);
117 $db->freeResult($res);
119 if (is_null($resultPageSet)) {
120 ApiResult
:: setIndexedTagName($data, 'p');
121 $this->getResult()->addValue('query', 'allpages', $data);
125 protected function getAllowedParams() {
129 'namespace' => array (
130 ApiBase
:: PARAM_DFLT
=> 0,
131 ApiBase
:: PARAM_TYPE
=> $this->getQuery()->getValidNamespaces()),
132 'filterredir' => array (
133 ApiBase
:: PARAM_DFLT
=> 'all',
134 ApiBase
:: PARAM_TYPE
=> array (
140 ApiBase
:: PARAM_DFLT
=> 10,
141 ApiBase
:: PARAM_TYPE
=> 'limit',
142 ApiBase
:: PARAM_MIN
=> 1,
143 ApiBase
:: PARAM_MAX1
=> 500,
144 ApiBase
:: PARAM_MAX2
=> 5000
148 protected function getParamDescription() {
150 'from' => 'The page title to start enumerating from.',
151 'namespace' => 'The namespace to enumerate. Default 0 (Main).',
152 'filterredir' => 'Which pages to list: "all" (default), "redirects", or "nonredirects"',
153 'limit' => 'How many total pages to return'
157 protected function getDescription() {
158 return 'Enumerate all pages sequentially in a given namespace';
161 protected function getExamples() {
164 ' Show a list of pages starting at the letter "B"',
165 ' api.php?action=query&list=allpages&apfrom=B',
166 'Using as Generator',
167 ' Show info about 4 pages starting at the letter "T"',
168 ' api.php?action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info',
169 ' Show content of first 2 non-redirect pages begining at "Re"',
170 ' api.php?action=query&generator=allpages&gaplimit=2&gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content'
174 public function getVersion() {
175 return __CLASS__
. ': $Id$';