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