Fix leftover doc comment in ApiQueryProtectedTitles
[lhc/web/wiklou.git] / includes / api / ApiQueryProtectedTitles.php
1 <?php
2
3 /*
4 * Created on Feb 13, 2009
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 */
25
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
29 }
30
31 /**
32 * Query module to enumerate all create-protected pages.
33 *
34 * @ingroup API
35 */
36 class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
37
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'pt');
40 }
41
42 public function execute() {
43 $this->run();
44 }
45
46 public function executeGenerator($resultPageSet) {
47 if ($resultPageSet->isResolvingRedirects())
48 $this->dieUsage('Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator', 'params');
49
50 $this->run($resultPageSet);
51 }
52
53 private function run($resultPageSet = null) {
54 $db = $this->getDB();
55 $params = $this->extractRequestParams();
56
57 $this->addTables('protected_titles');
58 $this->addFields(array('pt_namespace', 'pt_title', 'pt_timestamp'));
59
60 $prop = array_flip($params['prop']);
61 $this->addFieldsIf('pt_user', isset($prop['user']));
62 $this->addFieldsIf('pt_reason', isset($prop['comment']));
63 $this->addFieldsIf('pt_expiry', isset($prop['expiry']));
64 $this->addFieldsIf('pt_create_perm', isset($prop['level']));
65
66 $this->addWhereRange('pt_timestamp', $params['dir'], $params['start'], $params['end']);
67 $this->addWhereFld('pt_namespace', $params['namespace']);
68 $this->addWhereFld('pt_create_perm', $params['level']);
69
70 if(isset($prop['user']))
71 {
72 $this->addTables('user');
73 $this->addFields('user_name');
74 $this->addJoinConds(array('user' => array('LEFT JOIN',
75 'user_id=pt_user'
76 )));
77 }
78
79 $this->addOption('LIMIT', $params['limit'] + 1);
80 $res = $this->select(__METHOD__);
81
82 $count = 0;
83 $result = $this->getResult();
84 while ($row = $db->fetchObject($res)) {
85 if (++ $count > $params['limit']) {
86 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
87 $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->pt_timestamp));
88 break;
89 }
90
91 $title = Title::makeTitle($row->pt_namespace, $row->pt_title);
92 if (is_null($resultPageSet)) {
93 $vals = array();
94 ApiQueryBase::addTitleInfo($vals, $title);
95 if(isset($prop['timestamp']))
96 $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->pt_timestamp);
97 if(isset($prop['user']) && !is_null($row->user_name))
98 $vals['user'] = $row->user_name;
99 if(isset($prop['comment']))
100 $vals['comment'] = $row->pt_reason;
101 if(isset($prop['expiry']))
102 $vals['expiry'] = Block::decodeExpiry($row->pt_expiry, TS_ISO_8601);
103 if(isset($prop['level']))
104 $vals['level'] = $row->pt_create_perm;
105
106 $fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
107 if(!$fit)
108 {
109 $this->setContinueEnumParameter('start',
110 wfTimestamp(TS_ISO_8601, $row->pt_timestamp));
111 break;
112 }
113 } else {
114 $titles[] = $title;
115 }
116 }
117 $db->freeResult($res);
118 if(is_null($resultPageSet))
119 $result->setIndexedTagName_internal(array('query', $this->getModuleName()), $this->getModulePrefix());
120 else
121 $resultPageSet->populateFromTitles($titles);
122 }
123
124 public function getAllowedParams() {
125 global $wgRestrictionLevels;
126 return array (
127 'namespace' => array (
128 ApiBase :: PARAM_ISMULTI => true,
129 ApiBase :: PARAM_TYPE => 'namespace',
130 ),
131 'level' => array(
132 ApiBase :: PARAM_ISMULTI => true,
133 ApiBase :: PARAM_TYPE => array_diff($wgRestrictionLevels, array(''))
134 ),
135 'limit' => array (
136 ApiBase :: PARAM_DFLT => 10,
137 ApiBase :: PARAM_TYPE => 'limit',
138 ApiBase :: PARAM_MIN => 1,
139 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
140 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
141 ),
142 'dir' => array (
143 ApiBase :: PARAM_DFLT => 'ascending',
144 ApiBase :: PARAM_TYPE => array (
145 'ascending',
146 'descending'
147 )
148 ),
149 'start' => array(
150 ApiBase :: PARAM_TYPE => 'timestamp'
151 ),
152 'end' => array(
153 ApiBase :: PARAM_TYPE => 'timestamp'
154 ),
155 'prop' => array(
156 ApiBase :: PARAM_ISMULTI => true,
157 ApiBase :: PARAM_DFLT => 'timestamp|level',
158 ApiBase :: PARAM_TYPE => array(
159 'timestamp',
160 'user',
161 'comment',
162 'expiry',
163 'level'
164 )
165 ),
166 );
167 }
168
169 public function getParamDescription() {
170 return array (
171 'namespace' => 'Only list titles in these namespaces',
172 'start' => 'Start listing at this protection timestamp',
173 'end' => 'Stop listing at this protection timestamp',
174 'dir' => 'The direction in which to list',
175 'limit' => 'How many total pages to return.',
176 'prop' => 'Which properties to get',
177 );
178 }
179
180 public function getDescription() {
181 return 'List all titles protected from creation';
182 }
183
184 protected function getExamples() {
185 return array (
186 'api.php?action=query&list=protectedtitles',
187 );
188 }
189
190 public function getVersion() {
191 return __CLASS__ . ': $Id$';
192 }
193 }