00001 <?php 00002 00003 /* 00004 * Created on Sep 2, 2008 00005 * 00006 * API for MediaWiki 1.14+ 00007 * 00008 * Copyright (C) 2008 Chad Horohoe 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License along 00021 * with this program; if not, write to the Free Software Foundation, Inc., 00022 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 * http://www.gnu.org/copyleft/gpl.html 00024 */ 00025 00026 if (!defined('MEDIAWIKI')) { 00027 require_once ('ApiBase.php'); 00028 } 00029 00034 class ApiPurge extends ApiBase { 00035 00036 public function __construct($main, $action) { 00037 parent :: __construct($main, $action); 00038 } 00039 00043 public function execute() { 00044 global $wgUser; 00045 $params = $this->extractRequestParams(); 00046 if(!$wgUser->isAllowed('purge')) 00047 $this->dieUsageMsg(array('cantpurge')); 00048 if(!isset($params['titles'])) 00049 $this->dieUsageMsg(array('missingparam', 'titles')); 00050 $result = array(); 00051 foreach($params['titles'] as $t) { 00052 $r = array(); 00053 $title = Title::newFromText($t); 00054 if(!$title instanceof Title) 00055 { 00056 $r['title'] = $t; 00057 $r['invalid'] = ''; 00058 $result[] = $r; 00059 continue; 00060 } 00061 ApiQueryBase::addTitleInfo($r, $title); 00062 if(!$title->exists()) 00063 { 00064 $r['missing'] = ''; 00065 $result[] = $r; 00066 continue; 00067 } 00068 $article = new Article($title); 00069 $article->doPurge(); // Directly purge and skip the UI part of purge(). 00070 $r['purged'] = ''; 00071 $result[] = $r; 00072 } 00073 $this->getResult()->setIndexedTagName($result, 'page'); 00074 $this->getResult()->addValue(null, $this->getModuleName(), $result); 00075 } 00076 00077 public function mustBePosted() { 00078 global $wgUser; 00079 return $wgUser->isAnon(); 00080 } 00081 00082 public function isWriteMode() { 00083 return true; 00084 } 00085 00086 public function getAllowedParams() { 00087 return array ( 00088 'titles' => array( 00089 ApiBase :: PARAM_ISMULTI => true 00090 ) 00091 ); 00092 } 00093 00094 public function getParamDescription() { 00095 return array ( 00096 'titles' => 'A list of titles', 00097 ); 00098 } 00099 00100 public function getDescription() { 00101 return array ( 00102 'Purge the cache for the given titles.' 00103 ); 00104 } 00105 00106 protected function getExamples() { 00107 return array( 00108 'api.php?action=purge&titles=Main_Page|API' 00109 ); 00110 } 00111 00112 public function getVersion() { 00113 return __CLASS__ . ': $Id: ApiPurge.php 48091 2009-03-06 13:49:44Z catrope $'; 00114 } 00115 }