Merge "Whitelist the <wbr> element."
[mediawiki.git] / includes / api / ApiQueryProtectedTitles.php
blob222ad0741aa7e285d71389567f18a315fcfbeb6e
1 <?php
2 /**
5 * Created on Feb 13, 2009
7 * Copyright © 2009 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
27 /**
28 * Query module to enumerate all create-protected pages.
30 * @ingroup API
32 class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
34 public function __construct( $query, $moduleName ) {
35 parent::__construct( $query, $moduleName, 'pt' );
38 public function execute() {
39 $this->run();
42 public function executeGenerator( $resultPageSet ) {
43 $this->run( $resultPageSet );
46 /**
47 * @param $resultPageSet ApiPageSet
48 * @return void
50 private function run( $resultPageSet = null ) {
51 $params = $this->extractRequestParams();
53 $this->addTables( 'protected_titles' );
54 $this->addFields( array( 'pt_namespace', 'pt_title', 'pt_timestamp' ) );
56 $prop = array_flip( $params['prop'] );
57 $this->addFieldsIf( 'pt_user', isset( $prop['user'] ) || isset( $prop['userid'] ) );
58 $this->addFieldsIf( 'pt_reason', isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) );
59 $this->addFieldsIf( 'pt_expiry', isset( $prop['expiry'] ) );
60 $this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) );
62 $this->addTimestampWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] );
63 $this->addWhereFld( 'pt_namespace', $params['namespace'] );
64 $this->addWhereFld( 'pt_create_perm', $params['level'] );
66 if ( isset( $prop['user'] ) ) {
67 $this->addTables( 'user' );
68 $this->addFields( 'user_name' );
69 $this->addJoinConds( array( 'user' => array( 'LEFT JOIN',
70 'user_id=pt_user'
71 ) ) );
74 $this->addOption( 'LIMIT', $params['limit'] + 1 );
75 $res = $this->select( __METHOD__ );
77 $count = 0;
78 $result = $this->getResult();
80 $titles = array();
82 foreach ( $res as $row ) {
83 if ( ++ $count > $params['limit'] ) {
84 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
85 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) );
86 break;
89 $title = Title::makeTitle( $row->pt_namespace, $row->pt_title );
90 if ( is_null( $resultPageSet ) ) {
91 $vals = array();
92 ApiQueryBase::addTitleInfo( $vals, $title );
93 if ( isset( $prop['timestamp'] ) ) {
94 $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;
101 if ( isset( $prop['userid'] ) || /*B/C*/isset( $prop['user'] ) ) {
102 $vals['userid'] = $row->pt_user;
105 if ( isset( $prop['comment'] ) ) {
106 $vals['comment'] = $row->pt_reason;
109 if ( isset( $prop['parsedcomment'] ) ) {
110 $vals['parsedcomment'] = Linker::formatComment( $row->pt_reason, $title );
113 if ( isset( $prop['expiry'] ) ) {
114 global $wgContLang;
115 $vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry, TS_ISO_8601 );
118 if ( isset( $prop['level'] ) ) {
119 $vals['level'] = $row->pt_create_perm;
122 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
123 if ( !$fit ) {
124 $this->setContinueEnumParameter( 'start',
125 wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) );
126 break;
128 } else {
129 $titles[] = $title;
133 if ( is_null( $resultPageSet ) ) {
134 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $this->getModulePrefix() );
135 } else {
136 $resultPageSet->populateFromTitles( $titles );
140 public function getCacheMode( $params ) {
141 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
142 // formatComment() calls wfMessage() among other things
143 return 'anon-public-user-private';
144 } else {
145 return 'public';
149 public function getAllowedParams() {
150 global $wgRestrictionLevels;
151 return array(
152 'namespace' => array(
153 ApiBase::PARAM_ISMULTI => true,
154 ApiBase::PARAM_TYPE => 'namespace',
156 'level' => array(
157 ApiBase::PARAM_ISMULTI => true,
158 ApiBase::PARAM_TYPE => array_diff( $wgRestrictionLevels, array( '' ) )
160 'limit' => array(
161 ApiBase::PARAM_DFLT => 10,
162 ApiBase::PARAM_TYPE => 'limit',
163 ApiBase::PARAM_MIN => 1,
164 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
165 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
167 'dir' => array(
168 ApiBase::PARAM_DFLT => 'older',
169 ApiBase::PARAM_TYPE => array(
170 'newer',
171 'older'
174 'start' => array(
175 ApiBase::PARAM_TYPE => 'timestamp'
177 'end' => array(
178 ApiBase::PARAM_TYPE => 'timestamp'
180 'prop' => array(
181 ApiBase::PARAM_ISMULTI => true,
182 ApiBase::PARAM_DFLT => 'timestamp|level',
183 ApiBase::PARAM_TYPE => array(
184 'timestamp',
185 'user',
186 'userid',
187 'comment',
188 'parsedcomment',
189 'expiry',
190 'level'
196 public function getParamDescription() {
197 return array(
198 'namespace' => 'Only list titles in these namespaces',
199 'start' => 'Start listing at this protection timestamp',
200 'end' => 'Stop listing at this protection timestamp',
201 'dir' => $this->getDirectionDescription( $this->getModulePrefix() ),
202 'limit' => 'How many total pages to return',
203 'prop' => array(
204 'Which properties to get',
205 ' timestamp - Adds the timestamp of when protection was added',
206 ' user - Adds the user that added the protection',
207 ' userid - Adds the user id that added the protection',
208 ' comment - Adds the comment for the protection',
209 ' parsedcomment - Adds the parsed comment for the protection',
210 ' expiry - Adds the timestamp of when the protection will be lifted',
211 ' level - Adds the protection level',
213 'level' => 'Only list titles with these protection levels',
217 public function getResultProperties() {
218 global $wgRestrictionLevels;
219 return array(
220 '' => array(
221 'ns' => 'namespace',
222 'title' => 'string'
224 'timestamp' => array(
225 'timestamp' => 'timestamp'
227 'user' => array(
228 'user' => array(
229 ApiBase::PROP_TYPE => 'string',
230 ApiBase::PROP_NULLABLE => true
232 'userid' => 'integer'
234 'userid' => array(
235 'userid' => 'integer'
237 'comment' => array(
238 'comment' => 'string'
240 'parsedcomment' => array(
241 'parsedcomment' => 'string'
243 'expiry' => array(
244 'expiry' => 'timestamp'
246 'level' => array(
247 'level' => array(
248 ApiBase::PROP_TYPE => array_diff( $wgRestrictionLevels, array( '' ) )
254 public function getDescription() {
255 return 'List all titles protected from creation';
258 public function getExamples() {
259 return array(
260 'api.php?action=query&list=protectedtitles',
264 public function getHelpUrls() {
265 return 'https://www.mediawiki.org/wiki/API:Protectedtitles';