MediaWiki
REL1_19
|
00001 <?php 00002 00032 class ApiPurge extends ApiBase { 00033 00034 public function __construct( $main, $action ) { 00035 parent::__construct( $main, $action ); 00036 } 00037 00041 public function execute() { 00042 $user = $this->getUser(); 00043 $params = $this->extractRequestParams(); 00044 if ( !$user->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() && 00045 !$this->getRequest()->wasPosted() ) { 00046 $this->dieUsageMsg( array( 'mustbeposted', $this->getModuleName() ) ); 00047 } 00048 00049 $forceLinkUpdate = $params['forcelinkupdate']; 00050 $pageSet = new ApiPageSet( $this ); 00051 $pageSet->execute(); 00052 00053 $result = array(); 00054 foreach( $pageSet->getInvalidTitles() as $title ) { 00055 $r = array(); 00056 $r['title'] = $title; 00057 $r['invalid'] = ''; 00058 $result[] = $r; 00059 } 00060 foreach( $pageSet->getMissingPageIDs() as $p ) { 00061 $page = array(); 00062 $page['pageid'] = $p; 00063 $page['missing'] = ''; 00064 $result[] = $page; 00065 } 00066 foreach( $pageSet->getMissingRevisionIDs() as $r ) { 00067 $rev = array(); 00068 $rev['revid'] = $r; 00069 $rev['missing'] = ''; 00070 $result[] = $rev; 00071 } 00072 00073 foreach ( $pageSet->getTitles() as $title ) { 00074 $r = array(); 00075 00076 ApiQueryBase::addTitleInfo( $r, $title ); 00077 if ( !$title->exists() ) { 00078 $r['missing'] = ''; 00079 $result[] = $r; 00080 continue; 00081 } 00082 00083 $page = WikiPage::factory( $title ); 00084 $page->doPurge(); // Directly purge and skip the UI part of purge(). 00085 $r['purged'] = ''; 00086 00087 if( $forceLinkUpdate ) { 00088 if ( !$user->pingLimiter() ) { 00089 global $wgParser, $wgEnableParserCache; 00090 00091 $popts = ParserOptions::newFromContext( $this->getContext() ); 00092 $p_result = $wgParser->parse( $page->getRawText(), $title, $popts, 00093 true, true, $page->getLatest() ); 00094 00095 # Update the links tables 00096 $u = new LinksUpdate( $title, $p_result ); 00097 $u->doUpdate(); 00098 00099 $r['linkupdate'] = ''; 00100 00101 if ( $wgEnableParserCache ) { 00102 $pcache = ParserCache::singleton(); 00103 $pcache->save( $p_result, $page, $popts ); 00104 } 00105 } else { 00106 $this->setWarning( $this->parseMsg( array( 'actionthrottledtext' ) ) ); 00107 $forceLinkUpdate = false; 00108 } 00109 } 00110 00111 $result[] = $r; 00112 } 00113 $apiResult = $this->getResult(); 00114 $apiResult->setIndexedTagName( $result, 'page' ); 00115 $apiResult->addValue( null, $this->getModuleName(), $result ); 00116 } 00117 00118 public function isWriteMode() { 00119 return true; 00120 } 00121 00122 public function getAllowedParams() { 00123 $psModule = new ApiPageSet( $this ); 00124 return $psModule->getAllowedParams() + array( 00125 'forcelinkupdate' => false, 00126 ); 00127 } 00128 00129 public function getParamDescription() { 00130 $psModule = new ApiPageSet( $this ); 00131 return $psModule->getParamDescription() + array( 00132 'forcelinkupdate' => 'Update the links tables', 00133 ); 00134 } 00135 00136 public function getDescription() { 00137 return array( 'Purge the cache for the given titles.', 00138 'Requires a POST request if the user is not logged in.' 00139 ); 00140 } 00141 00142 public function getPossibleErrors() { 00143 $psModule = new ApiPageSet( $this ); 00144 return array_merge( 00145 parent::getPossibleErrors(), 00146 array( array( 'cantpurge' ), ), 00147 $psModule->getPossibleErrors() 00148 ); 00149 } 00150 00151 public function getExamples() { 00152 return array( 00153 'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page', 00154 ); 00155 } 00156 00157 public function getHelpUrls() { 00158 return 'https://www.mediawiki.org/wiki/API:Purge'; 00159 } 00160 00161 public function getVersion() { 00162 return __CLASS__ . ': $Id$'; 00163 } 00164 }