Tweaks for r40686, r40687:
[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 (C) 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 */
25
26 if (!defined('MEDIAWIKI')) {
27 require_once ('ApiBase.php');
28 }
29
30 class ApiPurge extends ApiBase {
31
32 public function __construct($main, $action) {
33 parent :: __construct($main, $action);
34 }
35
36 /**
37 * Purges the cache of a page
38 */
39 public function execute() {
40 global $wgUser;
41 $params = $this->extractRequestParams();
42 if(!$wgUser->isAllowed('purge'))
43 $this->dieUsageMsg(array('cantpurge'));
44 if(!isset($params['titles']))
45 $this->dieUsageMsg(array('missingparam', 'titles'));
46 $result = array();
47 foreach($params['titles'] as $t) {
48 $r = array();
49 $title = Title::newFromText($t);
50 if(!$title instanceof Title)
51 {
52 $r['title'] = $t;
53 $r['invalid'] = '';
54 $result[] = $r;
55 continue;
56 }
57 ApiQueryBase::addTitleInfo($r, $title);
58 if(!$title->exists())
59 {
60 $r['missing'] = '';
61 $result[] = $r;
62 continue;
63 }
64 $article = new Article($title);
65 $article->doPurge(); // Directly purge and skip the UI part of purge().
66 $r['purged'] = '';
67 $result[] = $r;
68 }
69 $this->getResult()->setIndexedTagName($result, 'page');
70 $this->getResult()->addValue(null, $this->getModuleName(), $result);
71 }
72
73 public function getAllowedParams() {
74 return array (
75 'titles' => array(
76 ApiBase :: PARAM_ISMULTI => true
77 )
78 );
79 }
80
81 public function getParamDescription() {
82 return array (
83 'titles' => 'A list of titles',
84 );
85 }
86
87 public function getDescription() {
88 return array (
89 'Purge the cache for the given titles.'
90 );
91 }
92
93 protected function getExamples() {
94 return array(
95 'api.php?action=purge&titles=Main_Page|API'
96 );
97 }
98
99 public function getVersion() {
100 return __CLASS__ . ': $Id$';
101 }
102 }