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
28 * Query module to enumerate all create-protected pages.
32 class ApiQueryProtectedTitles
extends ApiQueryGeneratorBase
{
34 public function __construct( $query, $moduleName ) {
35 parent
::__construct( $query, $moduleName, 'pt' );
38 public function execute() {
42 public function executeGenerator( $resultPageSet ) {
43 $this->run( $resultPageSet );
47 * @param $resultPageSet ApiPageSet
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',
74 $this->addOption( 'LIMIT', $params['limit'] +
1 );
75 $res = $this->select( __METHOD__
);
78 $result = $this->getResult();
82 foreach ( $res as $row ) {
83 if ( ++
$count > $params['limit'] ) {
84 // We've reached the one extra which shows that there are
85 // additional pages to be had. Stop here...
86 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601
, $row->pt_timestamp
) );
90 $title = Title
::makeTitle( $row->pt_namespace
, $row->pt_title
);
91 if ( is_null( $resultPageSet ) ) {
93 ApiQueryBase
::addTitleInfo( $vals, $title );
94 if ( isset( $prop['timestamp'] ) ) {
95 $vals['timestamp'] = wfTimestamp( TS_ISO_8601
, $row->pt_timestamp
);
98 if ( isset( $prop['user'] ) && !is_null( $row->user_name
) ) {
99 $vals['user'] = $row->user_name
;
102 if ( isset( $prop['userid'] ) ||
/*B/C*/isset( $prop['user'] ) ) {
103 $vals['userid'] = $row->pt_user
;
106 if ( isset( $prop['comment'] ) ) {
107 $vals['comment'] = $row->pt_reason
;
110 if ( isset( $prop['parsedcomment'] ) ) {
111 $vals['parsedcomment'] = Linker
::formatComment( $row->pt_reason
, $title );
114 if ( isset( $prop['expiry'] ) ) {
116 $vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
);
119 if ( isset( $prop['level'] ) ) {
120 $vals['level'] = $row->pt_create_perm
;
123 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
125 $this->setContinueEnumParameter( 'start',
126 wfTimestamp( TS_ISO_8601
, $row->pt_timestamp
) );
134 if ( is_null( $resultPageSet ) ) {
135 $result->setIndexedTagName_internal(
136 array( 'query', $this->getModuleName() ),
137 $this->getModulePrefix()
140 $resultPageSet->populateFromTitles( $titles );
144 public function getCacheMode( $params ) {
145 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
146 // formatComment() calls wfMessage() among other things
147 return 'anon-public-user-private';
153 public function getAllowedParams() {
154 global $wgRestrictionLevels;
157 'namespace' => array(
158 ApiBase
::PARAM_ISMULTI
=> true,
159 ApiBase
::PARAM_TYPE
=> 'namespace',
162 ApiBase
::PARAM_ISMULTI
=> true,
163 ApiBase
::PARAM_TYPE
=> array_diff( $wgRestrictionLevels, array( '' ) )
166 ApiBase
::PARAM_DFLT
=> 10,
167 ApiBase
::PARAM_TYPE
=> 'limit',
168 ApiBase
::PARAM_MIN
=> 1,
169 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
170 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
173 ApiBase
::PARAM_DFLT
=> 'older',
174 ApiBase
::PARAM_TYPE
=> array(
180 ApiBase
::PARAM_TYPE
=> 'timestamp'
183 ApiBase
::PARAM_TYPE
=> 'timestamp'
186 ApiBase
::PARAM_ISMULTI
=> true,
187 ApiBase
::PARAM_DFLT
=> 'timestamp|level',
188 ApiBase
::PARAM_TYPE
=> array(
201 public function getParamDescription() {
203 'namespace' => 'Only list titles in these namespaces',
204 'start' => 'Start listing at this protection timestamp',
205 'end' => 'Stop listing at this protection timestamp',
206 'dir' => $this->getDirectionDescription( $this->getModulePrefix() ),
207 'limit' => 'How many total pages to return',
209 'Which properties to get',
210 ' timestamp - Adds the timestamp of when protection was added',
211 ' user - Adds the user that added the protection',
212 ' userid - Adds the user id that added the protection',
213 ' comment - Adds the comment for the protection',
214 ' parsedcomment - Adds the parsed comment for the protection',
215 ' expiry - Adds the timestamp of when the protection will be lifted',
216 ' level - Adds the protection level',
218 'level' => 'Only list titles with these protection levels',
222 public function getResultProperties() {
223 global $wgRestrictionLevels;
230 'timestamp' => array(
231 'timestamp' => 'timestamp'
235 ApiBase
::PROP_TYPE
=> 'string',
236 ApiBase
::PROP_NULLABLE
=> true
238 'userid' => 'integer'
241 'userid' => 'integer'
244 'comment' => 'string'
246 'parsedcomment' => array(
247 'parsedcomment' => 'string'
250 'expiry' => 'timestamp'
254 ApiBase
::PROP_TYPE
=> array_diff( $wgRestrictionLevels, array( '' ) )
260 public function getDescription() {
261 return 'List all titles protected from creation.';
264 public function getExamples() {
266 'api.php?action=query&list=protectedtitles',
270 public function getHelpUrls() {
271 return 'https://www.mediawiki.org/wiki/API:Protectedtitles';