API * Added rudimentary RC list
[lhc/web/wiklou.git] / includes / api / ApiQueryAllpages.php
1 <?php
2
3
4 /*
5 * Created on Sep 25, 2006
6 *
7 * API for MediaWiki 1.8+
8 *
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
10 *
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.
15 *
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.
20 *
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
25 */
26
27 if (!defined('MEDIAWIKI')) {
28 // Eclipse helper - will be ignored in production
29 require_once ('ApiQueryBase.php');
30 }
31
32 class ApiQueryAllpages extends ApiQueryGeneratorBase {
33
34 public function __construct($query, $moduleName) {
35 parent :: __construct($query, $moduleName, 'ap');
36 }
37
38 public function execute() {
39 $this->run();
40 }
41
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');
45
46 $this->run($resultPageSet);
47 }
48
49 private function run($resultPageSet = null) {
50 $limit = $from = $namespace = $filterredir = null;
51 extract($this->extractRequestParams());
52
53 $db = $this->getDB();
54
55 $this->addTables('page');
56 $this->addWhereIf('page_is_redirect = 1', $filterredir === 'redirects');
57 $this->addWhereIf('page_is_redirect = 0', $filterredir === 'nonredirects');
58 $this->addWhereFld('page_namespace', $namespace);
59 if (isset ($from))
60 $this->addWhere('page_title>=' . $db->addQuotes(ApiQueryBase :: titleToKey($from)));
61 if (isset ($prefix))
62 $this->addWhere("page_title LIKE '{$db->strencode(ApiQueryBase :: titleToKey($prefix))}%'");
63
64 if (is_null($resultPageSet)) {
65 $this->addFields( array (
66 'page_id',
67 'page_namespace',
68 'page_title'
69 ));
70 } else {
71 $this->addFields( $resultPageSet->getPageTableFields());
72 }
73
74 $this->addOption( 'USE INDEX', 'name_title');
75 $this->addOption( 'LIMIT', $limit +1);
76 $this->addOption( 'ORDER BY', 'page_namespace, page_title');
77
78 $data = array ();
79 $count = 0;
80 $res = $this->select(__METHOD__);
81 while ($row = $db->fetchObject($res)) {
82 if (++ $count > $limit) {
83 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
84 $this->setContinueEnumParameter('from', ApiQueryBase :: keyToTitle($row->page_title));
85 break;
86 }
87
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
92 if (is_null($resultPageSet)) {
93 $id = intval($row->page_id);
94 $data[$id] = array (
95 'id' => $id,
96 'ns' => $title->getNamespace(), 'title' => $title->getPrefixedText());
97 } else {
98 $resultPageSet->processDbRow($row);
99 }
100 }
101 }
102 $db->freeResult($res);
103
104 if (is_null($resultPageSet)) {
105 $result = $this->getResult();
106 $result->setIndexedTagName($data, 'p');
107 $result->addValue('query', $this->getModuleName(), $data);
108 }
109 }
110
111 protected function getAllowedParams() {
112 $namespaces = $this->getQuery()->getValidNamespaces();
113 return array (
114 'from' => null,
115 'prefix' => null,
116 'namespace' => array (
117 ApiBase :: PARAM_DFLT => 0,
118 ApiBase :: PARAM_TYPE => $namespaces
119 ),
120 'filterredir' => array (
121 ApiBase :: PARAM_DFLT => 'all',
122 ApiBase :: PARAM_TYPE => array (
123 'all',
124 'redirects',
125 'nonredirects'
126 )
127 ),
128 'limit' => array (
129 ApiBase :: PARAM_DFLT => 10,
130 ApiBase :: PARAM_TYPE => 'limit',
131 ApiBase :: PARAM_MIN => 1,
132 ApiBase :: PARAM_MAX1 => ApiBase :: LIMIT_BIG1,
133 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
134 )
135 );
136 }
137
138 protected function getParamDescription() {
139 return array (
140 'from' => 'The page title to start enumerating from.',
141 'prefix' => 'Search for all page titles that begin with this value.',
142 'namespace' => 'The namespace to enumerate.',
143 'filterredir' => 'Which pages to list.',
144 'limit' => 'How many total pages to return.'
145 );
146 }
147
148 protected function getDescription() {
149 return 'Enumerate all pages sequentially in a given namespace';
150 }
151
152 protected function getExamples() {
153 return array (
154 'Simple Use',
155 ' Show a list of pages starting at the letter "B"',
156 ' api.php?action=query&list=allpages&apfrom=B',
157 'Using as Generator',
158 ' Show info about 4 pages starting at the letter "T"',
159 ' api.php?action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info',
160 ' Show content of first 2 non-redirect pages begining at "Re"',
161 ' api.php?action=query&generator=allpages&gaplimit=2&gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content'
162 );
163 }
164
165 public function getVersion() {
166 return __CLASS__ . ': $Id$';
167 }
168 }
169 ?>