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 $this->run($resultPageSet);
46 private function run($resultPageSet = null) {
47 $limit = $from = $namespace = $filterredir = null;
48 extract($this->extractRequestParams());
53 'page_namespace' => $namespace
56 $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase
:: titleToKey($from));
58 if ($filterredir === 'redirects') {
59 $where['page_is_redirect'] = 1;
61 elseif ($filterredir === 'nonredirects') {
62 $where['page_is_redirect'] = 0;
66 $res = $db->select('page', array (
70 ), $where, __CLASS__
. '::' . __METHOD__
, array (
71 'USE INDEX' => 'name_title',
73 'ORDER BY' => 'page_namespace, page_title'
75 $this->profileDBOut();
79 while ($row = $db->fetchObject($res)) {
80 if (++
$count > $limit) {
81 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
83 'continue' => $this->encodeParamName('from') . '='. ApiQueryBase
:: keyToTitle($row->page_title
));
84 $this->getResult()->addValue('query-status', 'allpages', $msg);
88 $title = Title
:: makeTitle($row->page_namespace
, $row->page_title
);
89 // skip any pages that user has no rights to read
90 if ($title->userCanRead()) {
91 $id = intval($row->page_id
);
93 if (is_null($resultPageSet)) {
95 $pagedata['id'] = $id;
96 if ($title->getNamespace() !== 0)
97 $pagedata['ns'] = $title->getNamespace();
98 $pagedata['title'] = $title->getPrefixedText();
100 $data[$id] = $pagedata;
102 $data[] = $id; // in generator mode, just assemble a list of page IDs.
106 $db->freeResult($res);
108 if (is_null($resultPageSet)) {
109 ApiResult
:: setIndexedTagName($data, 'p');
110 $this->getResult()->addValue('query', 'allpages', $data);
112 $resultPageSet->executeForPageIDs($data);
116 protected function getAllowedParams() {
119 $validNamespaces = array ();
120 foreach (array_keys($wgContLang->getNamespaces()) as $ns) {
122 $validNamespaces[] = $ns; // strval($ns);
127 'namespace' => array (
128 ApiBase
:: PARAM_DFLT
=> 0,
129 ApiBase
:: PARAM_TYPE
=> $validNamespaces
131 'filterredir' => array (
132 ApiBase
:: PARAM_DFLT
=> 'all',
133 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
149 protected function getParamDescription() {
151 'from' => 'The page title to start enumerating from.',
152 'namespace' => 'The namespace to enumerate. Default 0 (Main).',
153 'filterredir' => 'Which pages to list: "all" (default), "redirects", or "nonredirects"',
154 'limit' => 'How many total pages to return'
158 protected function getDescription() {
159 return 'Enumerate all pages sequentially in a given namespace';
162 protected function getExamples() {
164 'api.php?action=query&list=allpages',
165 'api.php?action=query&list=allpages&apfrom=B&aplimit=5',
166 'api.php?action=query&generator=allpages&gaplimit=4&prop=info (generator)'
170 public function getVersion() {
171 return __CLASS__
. ': $Id$';