00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 = Mediawiki::articleFromTitle( $title );
00069 $article->doPurge();
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 public function getPossibleErrors() {
00107 return array_merge( parent::getPossibleErrors(), array(
00108 array( 'cantpurge' ),
00109 array( 'missingparam', 'titles' ),
00110 ) );
00111 }
00112
00113 protected function getExamples() {
00114 return array(
00115 'api.php?action=purge&titles=Main_Page|API'
00116 );
00117 }
00118
00119 public function getVersion() {
00120 return __CLASS__ . ': $Id: ApiPurge.php 69578 2010-07-20 02:46:20Z tstarling $';
00121 }
00122 }