MediaWiki
REL1_24
|
00001 <?php 00002 00032 class ApiPurge extends ApiBase { 00033 private $mPageSet; 00034 00038 public function execute() { 00039 $params = $this->extractRequestParams(); 00040 00041 $this->getResult()->beginContinuation( $params['continue'], array(), array() ); 00042 00043 $forceLinkUpdate = $params['forcelinkupdate']; 00044 $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate']; 00045 $pageSet = $this->getPageSet(); 00046 $pageSet->execute(); 00047 00048 $result = $pageSet->getInvalidTitlesAndRevisions(); 00049 00050 foreach ( $pageSet->getGoodTitles() as $title ) { 00051 $r = array(); 00052 ApiQueryBase::addTitleInfo( $r, $title ); 00053 $page = WikiPage::factory( $title ); 00054 $page->doPurge(); // Directly purge and skip the UI part of purge(). 00055 $r['purged'] = ''; 00056 00057 if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) { 00058 if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) { 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 $enableParserCache = $this->getConfig()->get( 'EnableParserCache' ); 00064 $p_result = $content->getParserOutput( 00065 $title, 00066 $page->getLatest(), 00067 $popts, 00068 $enableParserCache 00069 ); 00070 00071 # Update the links tables 00072 $updates = $content->getSecondaryDataUpdates( 00073 $title, null, $forceRecursiveLinkUpdate, $p_result ); 00074 DataUpdate::runUpdates( $updates ); 00075 00076 $r['linkupdate'] = ''; 00077 00078 if ( $enableParserCache ) { 00079 $pcache = ParserCache::singleton(); 00080 $pcache->save( $p_result, $page, $popts ); 00081 } 00082 } else { 00083 $error = $this->parseMsg( array( 'actionthrottledtext' ) ); 00084 $this->setWarning( $error['info'] ); 00085 $forceLinkUpdate = false; 00086 } 00087 } 00088 00089 $result[] = $r; 00090 } 00091 $apiResult = $this->getResult(); 00092 $apiResult->setIndexedTagName( $result, 'page' ); 00093 $apiResult->addValue( null, $this->getModuleName(), $result ); 00094 00095 $values = $pageSet->getNormalizedTitlesAsResult( $apiResult ); 00096 if ( $values ) { 00097 $apiResult->addValue( null, 'normalized', $values ); 00098 } 00099 $values = $pageSet->getConvertedTitlesAsResult( $apiResult ); 00100 if ( $values ) { 00101 $apiResult->addValue( null, 'converted', $values ); 00102 } 00103 $values = $pageSet->getRedirectTitlesAsResult( $apiResult ); 00104 if ( $values ) { 00105 $apiResult->addValue( null, 'redirects', $values ); 00106 } 00107 00108 $apiResult->endContinuation(); 00109 } 00110 00115 private function getPageSet() { 00116 if ( !isset( $this->mPageSet ) ) { 00117 $this->mPageSet = new ApiPageSet( $this ); 00118 } 00119 00120 return $this->mPageSet; 00121 } 00122 00123 public function isWriteMode() { 00124 return true; 00125 } 00126 00127 public function mustBePosted() { 00128 // Anonymous users are not allowed a non-POST request 00129 return !$this->getUser()->isAllowed( 'purge' ); 00130 } 00131 00132 public function getAllowedParams( $flags = 0 ) { 00133 $result = array( 00134 'forcelinkupdate' => false, 00135 'forcerecursivelinkupdate' => false, 00136 'continue' => '', 00137 ); 00138 if ( $flags ) { 00139 $result += $this->getPageSet()->getFinalParams( $flags ); 00140 } 00141 00142 return $result; 00143 } 00144 00145 public function getParamDescription() { 00146 return $this->getPageSet()->getFinalParamDescription() 00147 + array( 00148 'forcelinkupdate' => 'Update the links tables', 00149 'forcerecursivelinkupdate' => 'Update the links table, and update ' . 00150 'the links tables for any page that uses this page as a template', 00151 'continue' => 'When more results are available, use this to continue', 00152 ); 00153 } 00154 00155 public function getDescription() { 00156 return array( 'Purge the cache for the given titles.', 00157 'Requires a POST request if the user is not logged in.' 00158 ); 00159 } 00160 00161 public function getExamples() { 00162 return array( 00163 'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page', 00164 ); 00165 } 00166 00167 public function getHelpUrls() { 00168 return 'https://www.mediawiki.org/wiki/API:Purge'; 00169 } 00170 }