db7f9ef06785c83477be137d08f28b020e0dce98
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 ApiQueryBase
{
34 public function __construct($query, $moduleName, $generator = false) {
35 parent
:: __construct($query, $moduleName, $generator);
38 public function execute() {
39 $aplimit = $apfrom = $apnamespace = $apfilterredir = null;
40 extract($this->extractRequestParams());
44 'page_namespace' => $apnamespace
47 $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase
:: titleToKey($apfrom));
49 if ($apfilterredir === 'redirects')
50 $where['page_is_redirect'] = 1;
52 if ($apfilterredir === 'nonredirects')
53 $where['page_is_redirect'] = 0;
56 $res = $db->select('page', array (
60 ), $where, __CLASS__
. '::' . __METHOD__
, array (
61 'USE INDEX' => 'name_title',
62 'LIMIT' => $aplimit +
1,
63 'ORDER BY' => 'page_namespace, page_title'
65 $this->profileDBOut();
68 ApiResult
:: setIndexedTagName($data, 'p');
70 while ($row = $db->fetchObject($res)) {
71 if (++
$count > $aplimit) {
72 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
74 'continue' => 'apfrom=' . ApiQueryBase
:: keyToTitle($row->page_title
76 $this->getResult()->addValue('query-status', 'allpages', $msg);
80 $title = Title
:: makeTitle($row->page_namespace
, $row->page_title
);
81 // skip any pages that user has no rights to read
82 if ($title->userCanRead()) {
84 $id = intval($row->page_id
);
86 $pagedata['id'] = $id;
87 if ($title->getNamespace() !== 0)
88 $pagedata['ns'] = $title->getNamespace();
89 $pagedata['title'] = $title->getPrefixedText();
91 $data[$id] = $pagedata;
94 $db->freeResult($res);
95 $this->getResult()->addValue('query', 'allpages', $data);
98 protected function getAllowedParams() {
101 $validNamespaces = array ();
102 foreach (array_keys($wgContLang->getNamespaces()) as $ns) {
104 $validNamespaces[] = $ns; // strval($ns);
109 'apnamespace' => array (
110 ApiBase
::PARAM_DFLT
=> 0,
111 ApiBase
::PARAM_TYPE
=> $validNamespaces
113 'apfilterredir' => array (
114 ApiBase
::PARAM_DFLT
=> 'all',
115 ApiBase
::PARAM_TYPE
=> array (
122 ApiBase
::PARAM_DFLT
=> 10,
123 ApiBase
::PARAM_TYPE
=> 'limit',
124 ApiBase
::PARAM_MIN
=> 1,
125 ApiBase
::PARAM_MAX1
=> 500,
126 ApiBase
::PARAM_MAX2
=> 5000
131 protected function getParamDescription() {
135 protected function getDescription() {
136 return 'Enumerate all pages sequentially in a given namespace';
139 protected function getExamples() {
141 'api.php?action=query&list=allpages',
142 'api.php?action=query&list=allpages&apfrom=B&aplimit=5'
145 public function getCanGenerate() {