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
27 if ( !defined( 'MEDIAWIKI' ) ) {
28 // Eclipse helper - will be ignored in production
29 require_once( 'ApiQueryBase.php' );
33 * Query module to enumerate all create-protected pages.
37 class ApiQueryProtectedTitles
extends ApiQueryGeneratorBase
{
39 public function __construct( $query, $moduleName ) {
40 parent
::__construct( $query, $moduleName, 'pt' );
43 public function execute() {
47 public function executeGenerator( $resultPageSet ) {
48 $this->run( $resultPageSet );
52 * @param $resultPageSet ApiPageSet
55 private function run( $resultPageSet = null ) {
56 $params = $this->extractRequestParams();
58 $this->addTables( 'protected_titles' );
59 $this->addFields( array( 'pt_namespace', 'pt_title', 'pt_timestamp' ) );
61 $prop = array_flip( $params['prop'] );
62 $this->addFieldsIf( 'pt_user', isset( $prop['user'] ) ||
isset( $prop['userid'] ) );
63 $this->addFieldsIf( 'pt_reason', isset( $prop['comment'] ) ||
isset( $prop['parsedcomment'] ) );
64 $this->addFieldsIf( 'pt_expiry', isset( $prop['expiry'] ) );
65 $this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) );
67 $this->addWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] );
68 $this->addWhereFld( 'pt_namespace', $params['namespace'] );
69 $this->addWhereFld( 'pt_create_perm', $params['level'] );
71 if ( isset( $prop['user'] ) ) {
72 $this->addTables( 'user' );
73 $this->addFields( 'user_name' );
74 $this->addJoinConds( array( 'user' => array( 'LEFT JOIN',
79 $this->addOption( 'LIMIT', $params['limit'] +
1 );
80 $res = $this->select( __METHOD__
);
83 $result = $this->getResult();
87 foreach ( $res as $row ) {
88 if ( ++
$count > $params['limit'] ) {
89 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
90 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601
, $row->pt_timestamp
) );
94 $title = Title
::makeTitle( $row->pt_namespace
, $row->pt_title
);
95 if ( is_null( $resultPageSet ) ) {
97 ApiQueryBase
::addTitleInfo( $vals, $title );
98 if ( isset( $prop['timestamp'] ) ) {
99 $vals['timestamp'] = wfTimestamp( TS_ISO_8601
, $row->pt_timestamp
);
102 if ( isset( $prop['user'] ) && !is_null( $row->user_name
) ) {
103 $vals['user'] = $row->user_name
;
106 if ( isset( $prop['user'] ) ) {
107 $vals['userid'] = $row->pt_user
;
110 if ( isset( $prop['comment'] ) ) {
111 $vals['comment'] = $row->pt_reason
;
114 if ( isset( $prop['parsedcomment'] ) ) {
116 $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->pt_reason
, $title );
119 if ( isset( $prop['expiry'] ) ) {
121 $vals['expiry'] = $wgContLang->formatExpiry( $row->pt_expiry
, TS_ISO_8601
);
124 if ( isset( $prop['level'] ) ) {
125 $vals['level'] = $row->pt_create_perm
;
128 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
130 $this->setContinueEnumParameter( 'start',
131 wfTimestamp( TS_ISO_8601
, $row->pt_timestamp
) );
139 if ( is_null( $resultPageSet ) ) {
140 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $this->getModulePrefix() );
142 $resultPageSet->populateFromTitles( $titles );
146 public function getCacheMode( $params ) {
147 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
148 // formatComment() calls wfMsg() among other things
149 return 'anon-public-user-private';
155 public function getAllowedParams() {
156 global $wgRestrictionLevels;
158 'namespace' => array(
159 ApiBase
::PARAM_ISMULTI
=> true,
160 ApiBase
::PARAM_TYPE
=> 'namespace',
163 ApiBase
::PARAM_ISMULTI
=> true,
164 ApiBase
::PARAM_TYPE
=> array_diff( $wgRestrictionLevels, array( '' ) )
167 ApiBase
::PARAM_DFLT
=> 10,
168 ApiBase
::PARAM_TYPE
=> 'limit',
169 ApiBase
::PARAM_MIN
=> 1,
170 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
171 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
174 ApiBase
::PARAM_DFLT
=> 'older',
175 ApiBase
::PARAM_TYPE
=> array(
181 ApiBase
::PARAM_TYPE
=> 'timestamp'
184 ApiBase
::PARAM_TYPE
=> 'timestamp'
187 ApiBase
::PARAM_ISMULTI
=> true,
188 ApiBase
::PARAM_DFLT
=> 'timestamp|level',
189 ApiBase
::PARAM_TYPE
=> array(
202 public function getParamDescription() {
204 'namespace' => 'Only list titles in these namespaces',
205 'start' => 'Start listing at this protection timestamp',
206 'end' => 'Stop listing at this protection timestamp',
207 'dir' => $this->getDirectionDescription( $this->getModulePrefix() ),
208 'limit' => 'How many total pages to return',
210 'Which properties to get',
211 ' timestamp - Adds the timestamp of when protection was added',
212 ' user - Adds the user that added the protection',
213 ' userid - Adds the user id that added the protection',
214 ' comment - Adds the comment for the protection',
215 ' parsedcomment - Adds the parsed comment for the protection',
216 ' expiry - Adds the timestamp of when the protection will be lifted',
217 ' level - Adds the protection level',
219 'level' => 'Only list titles with these protection levels',
223 public function getDescription() {
224 return 'List all titles protected from creation';
227 protected function getExamples() {
229 'api.php?action=query&list=protectedtitles',
233 public function getVersion() {
234 return __CLASS__
. ': $Id$';