MediaWiki
REL1_23
|
00001 <?php 00002 00032 class ApiPurge extends ApiBase { 00033 private $mPageSet; 00034 00038 public function execute() { 00039 $params = $this->extractRequestParams(); 00040 00041 $forceLinkUpdate = $params['forcelinkupdate']; 00042 $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate']; 00043 $pageSet = $this->getPageSet(); 00044 $pageSet->execute(); 00045 00046 $result = $pageSet->getInvalidTitlesAndRevisions(); 00047 00048 foreach ( $pageSet->getGoodTitles() as $title ) { 00049 $r = array(); 00050 ApiQueryBase::addTitleInfo( $r, $title ); 00051 $page = WikiPage::factory( $title ); 00052 $page->doPurge(); // Directly purge and skip the UI part of purge(). 00053 $r['purged'] = ''; 00054 00055 if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) { 00056 if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) { 00057 global $wgEnableParserCache; 00058 00059 $popts = $page->makeParserOptions( 'canonical' ); 00060 00061 # Parse content; note that HTML generation is only needed if we want to cache the result. 00062 $content = $page->getContent( Revision::RAW ); 00063 $p_result = $content->getParserOutput( 00064 $title, 00065 $page->getLatest(), 00066 $popts, 00067 $wgEnableParserCache 00068 ); 00069 00070 # Update the links tables 00071 $updates = $content->getSecondaryDataUpdates( 00072 $title, null, $forceRecursiveLinkUpdate, $p_result ); 00073 DataUpdate::runUpdates( $updates ); 00074 00075 $r['linkupdate'] = ''; 00076 00077 if ( $wgEnableParserCache ) { 00078 $pcache = ParserCache::singleton(); 00079 $pcache->save( $p_result, $page, $popts ); 00080 } 00081 } else { 00082 $error = $this->parseMsg( array( 'actionthrottledtext' ) ); 00083 $this->setWarning( $error['info'] ); 00084 $forceLinkUpdate = false; 00085 } 00086 } 00087 00088 $result[] = $r; 00089 } 00090 $apiResult = $this->getResult(); 00091 $apiResult->setIndexedTagName( $result, 'page' ); 00092 $apiResult->addValue( null, $this->getModuleName(), $result ); 00093 00094 $values = $pageSet->getNormalizedTitlesAsResult( $apiResult ); 00095 if ( $values ) { 00096 $apiResult->addValue( null, 'normalized', $values ); 00097 } 00098 $values = $pageSet->getConvertedTitlesAsResult( $apiResult ); 00099 if ( $values ) { 00100 $apiResult->addValue( null, 'converted', $values ); 00101 } 00102 $values = $pageSet->getRedirectTitlesAsResult( $apiResult ); 00103 if ( $values ) { 00104 $apiResult->addValue( null, 'redirects', $values ); 00105 } 00106 } 00107 00112 private function getPageSet() { 00113 if ( !isset( $this->mPageSet ) ) { 00114 $this->mPageSet = new ApiPageSet( $this ); 00115 } 00116 00117 return $this->mPageSet; 00118 } 00119 00120 public function isWriteMode() { 00121 return true; 00122 } 00123 00124 public function mustBePosted() { 00125 // Anonymous users are not allowed a non-POST request 00126 return !$this->getUser()->isAllowed( 'purge' ); 00127 } 00128 00129 public function getAllowedParams( $flags = 0 ) { 00130 $result = array( 00131 'forcelinkupdate' => false, 00132 'forcerecursivelinkupdate' => false 00133 ); 00134 if ( $flags ) { 00135 $result += $this->getPageSet()->getFinalParams( $flags ); 00136 } 00137 00138 return $result; 00139 } 00140 00141 public function getParamDescription() { 00142 return $this->getPageSet()->getFinalParamDescription() 00143 + array( 00144 'forcelinkupdate' => 'Update the links tables', 00145 'forcerecursivelinkupdate' => 'Update the links table, and update ' . 00146 'the links tables for any page that uses this page as a template', 00147 ); 00148 } 00149 00150 public function getResultProperties() { 00151 return array( 00152 ApiBase::PROP_LIST => true, 00153 '' => array( 00154 'ns' => array( 00155 ApiBase::PROP_TYPE => 'namespace', 00156 ApiBase::PROP_NULLABLE => true 00157 ), 00158 'title' => array( 00159 ApiBase::PROP_TYPE => 'string', 00160 ApiBase::PROP_NULLABLE => true 00161 ), 00162 'pageid' => array( 00163 ApiBase::PROP_TYPE => 'integer', 00164 ApiBase::PROP_NULLABLE => true 00165 ), 00166 'revid' => array( 00167 ApiBase::PROP_TYPE => 'integer', 00168 ApiBase::PROP_NULLABLE => true 00169 ), 00170 'invalid' => 'boolean', 00171 'special' => 'boolean', 00172 'missing' => 'boolean', 00173 'purged' => 'boolean', 00174 'linkupdate' => 'boolean', 00175 'iw' => array( 00176 ApiBase::PROP_TYPE => 'string', 00177 ApiBase::PROP_NULLABLE => true 00178 ), 00179 ) 00180 ); 00181 } 00182 00183 public function getDescription() { 00184 return array( 'Purge the cache for the given titles.', 00185 'Requires a POST request if the user is not logged in.' 00186 ); 00187 } 00188 00189 public function getPossibleErrors() { 00190 return array_merge( 00191 parent::getPossibleErrors(), 00192 $this->getPageSet()->getFinalPossibleErrors() 00193 ); 00194 } 00195 00196 public function getExamples() { 00197 return array( 00198 'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page', 00199 ); 00200 } 00201 00202 public function getHelpUrls() { 00203 return 'https://www.mediawiki.org/wiki/API:Purge'; 00204 } 00205 }