MediaWiki
REL1_20
|
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 = $page->makeParserOptions( 'canonical' ); 00092 $p_result = $wgParser->parse( $page->getRawText(), $title, $popts, 00093 true, true, $page->getLatest() ); 00094 00095 # Update the links tables 00096 $updates = $p_result->getSecondaryDataUpdates( $title ); 00097 DataUpdate::runUpdates( $updates ); 00098 00099 $r['linkupdate'] = ''; 00100 00101 if ( $wgEnableParserCache ) { 00102 $pcache = ParserCache::singleton(); 00103 $pcache->save( $p_result, $page, $popts ); 00104 } 00105 } else { 00106 $error = $this->parseMsg( array( 'actionthrottledtext' ) ); 00107 $this->setWarning( $error['info'] ); 00108 $forceLinkUpdate = false; 00109 } 00110 } 00111 00112 $result[] = $r; 00113 } 00114 $apiResult = $this->getResult(); 00115 $apiResult->setIndexedTagName( $result, 'page' ); 00116 $apiResult->addValue( null, $this->getModuleName(), $result ); 00117 } 00118 00119 public function isWriteMode() { 00120 return true; 00121 } 00122 00123 public function getAllowedParams() { 00124 $psModule = new ApiPageSet( $this ); 00125 return $psModule->getAllowedParams() + array( 00126 'forcelinkupdate' => false, 00127 ); 00128 } 00129 00130 public function getParamDescription() { 00131 $psModule = new ApiPageSet( $this ); 00132 return $psModule->getParamDescription() + array( 00133 'forcelinkupdate' => 'Update the links tables', 00134 ); 00135 } 00136 00137 public function getResultProperties() { 00138 return array( 00139 ApiBase::PROP_LIST => true, 00140 '' => array( 00141 'ns' => array( 00142 ApiBase::PROP_TYPE => 'namespace', 00143 ApiBase::PROP_NULLABLE => true 00144 ), 00145 'title' => array( 00146 ApiBase::PROP_TYPE => 'string', 00147 ApiBase::PROP_NULLABLE => true 00148 ), 00149 'pageid' => array( 00150 ApiBase::PROP_TYPE => 'integer', 00151 ApiBase::PROP_NULLABLE => true 00152 ), 00153 'revid' => array( 00154 ApiBase::PROP_TYPE => 'integer', 00155 ApiBase::PROP_NULLABLE => true 00156 ), 00157 'invalid' => 'boolean', 00158 'missing' => 'boolean', 00159 'purged' => 'boolean', 00160 'linkupdate' => 'boolean' 00161 ) 00162 ); 00163 } 00164 00165 public function getDescription() { 00166 return array( 'Purge the cache for the given titles.', 00167 'Requires a POST request if the user is not logged in.' 00168 ); 00169 } 00170 00171 public function getPossibleErrors() { 00172 $psModule = new ApiPageSet( $this ); 00173 return array_merge( 00174 parent::getPossibleErrors(), 00175 $psModule->getPossibleErrors() 00176 ); 00177 } 00178 00179 public function getExamples() { 00180 return array( 00181 'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page', 00182 ); 00183 } 00184 00185 public function getHelpUrls() { 00186 return 'https://www.mediawiki.org/wiki/API:Purge'; 00187 } 00188 00189 public function getVersion() { 00190 return __CLASS__ . ': $Id$'; 00191 } 00192 }