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