Followup to r70460 and r70461: Use true instead of 1
[lhc/web/wiklou.git] / includes / api / ApiPurge.php
1 <?php
2
3 /**
4 * Created on Sep 2, 2008
5 *
6 * API for MediaWiki 1.14+
7 *
8 * Copyright © 2008 Chad Horohoe
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 */
25
26 if ( !defined( 'MEDIAWIKI' ) ) {
27 require_once( 'ApiBase.php' );
28 }
29
30 /**
31 * API interface for page purging
32 * @ingroup API
33 */
34 class ApiPurge extends ApiBase {
35
36 public function __construct( $main, $action ) {
37 parent::__construct( $main, $action );
38 }
39
40 /**
41 * Purges the cache of a page
42 */
43 public function execute() {
44 global $wgUser;
45 $params = $this->extractRequestParams();
46 if ( !$wgUser->isAllowed( 'purge' ) ) {
47 $this->dieUsageMsg( array( 'cantpurge' ) );
48 }
49 $result = array();
50 foreach ( $params['titles'] as $t ) {
51 $r = array();
52 $title = Title::newFromText( $t );
53 if ( !$title instanceof Title ) {
54 $r['title'] = $t;
55 $r['invalid'] = '';
56 $result[] = $r;
57 continue;
58 }
59 ApiQueryBase::addTitleInfo( $r, $title );
60 if ( !$title->exists() ) {
61 $r['missing'] = '';
62 $result[] = $r;
63 continue;
64 }
65 $article = MediaWiki::articleFromTitle( $title );
66 $article->doPurge(); // Directly purge and skip the UI part of purge().
67 $r['purged'] = '';
68 $result[] = $r;
69 }
70 $this->getResult()->setIndexedTagName( $result, 'page' );
71 $this->getResult()->addValue( null, $this->getModuleName(), $result );
72 }
73
74 public function mustBePosted() {
75 global $wgUser;
76 return $wgUser->isAnon();
77 }
78
79 public function isWriteMode() {
80 return true;
81 }
82
83 public function getAllowedParams() {
84 return array(
85 'titles' => array(
86 ApiBase::PARAM_ISMULTI => true,
87 ApiBase::PARAM_REQUIRED => true
88 )
89 );
90 }
91
92 public function getParamDescription() {
93 return array(
94 'titles' => 'A list of titles',
95 );
96 }
97
98 public function getDescription() {
99 return 'Purge the cache for the given titles';
100 }
101
102 public function getPossibleErrors() {
103 return array_merge( parent::getPossibleErrors(), array(
104 array( 'cantpurge' ),
105 array( 'missingparam', 'titles' ),
106 ) );
107 }
108
109 protected function getExamples() {
110 return array(
111 'api.php?action=purge&titles=Main_Page|API'
112 );
113 }
114
115 public function getVersion() {
116 return __CLASS__ . ': $Id$';
117 }
118 }