extractRequestParams(); $this->getResult()->beginContinuation( $params['continue'], array(), array() ); $forceLinkUpdate = $params['forcelinkupdate']; $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate']; $pageSet = $this->getPageSet(); $pageSet->execute(); $result = $pageSet->getInvalidTitlesAndRevisions(); foreach ( $pageSet->getGoodTitles() as $title ) { $r = array(); ApiQueryBase::addTitleInfo( $r, $title ); $page = WikiPage::factory( $title ); $page->doPurge(); // Directly purge and skip the UI part of purge(). $r['purged'] = ''; if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) { if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) { $popts = $page->makeParserOptions( 'canonical' ); # Parse content; note that HTML generation is only needed if we want to cache the result. $content = $page->getContent( Revision::RAW ); $enableParserCache = $this->getConfig()->get( 'EnableParserCache' ); $p_result = $content->getParserOutput( $title, $page->getLatest(), $popts, $enableParserCache ); # Update the links tables $updates = $content->getSecondaryDataUpdates( $title, null, $forceRecursiveLinkUpdate, $p_result ); DataUpdate::runUpdates( $updates ); $r['linkupdate'] = ''; if ( $enableParserCache ) { $pcache = ParserCache::singleton(); $pcache->save( $p_result, $page, $popts ); } } else { $error = $this->parseMsg( array( 'actionthrottledtext' ) ); $this->setWarning( $error['info'] ); $forceLinkUpdate = false; } } $result[] = $r; } $apiResult = $this->getResult(); $apiResult->setIndexedTagName( $result, 'page' ); $apiResult->addValue( null, $this->getModuleName(), $result ); $values = $pageSet->getNormalizedTitlesAsResult( $apiResult ); if ( $values ) { $apiResult->addValue( null, 'normalized', $values ); } $values = $pageSet->getConvertedTitlesAsResult( $apiResult ); if ( $values ) { $apiResult->addValue( null, 'converted', $values ); } $values = $pageSet->getRedirectTitlesAsResult( $apiResult ); if ( $values ) { $apiResult->addValue( null, 'redirects', $values ); } $apiResult->endContinuation(); } /** * Get a cached instance of an ApiPageSet object * @return ApiPageSet */ private function getPageSet() { if ( !isset( $this->mPageSet ) ) { $this->mPageSet = new ApiPageSet( $this ); } return $this->mPageSet; } public function isWriteMode() { return true; } public function mustBePosted() { // Anonymous users are not allowed a non-POST request return !$this->getUser()->isAllowed( 'purge' ); } public function getAllowedParams( $flags = 0 ) { $result = array( 'forcelinkupdate' => false, 'forcerecursivelinkupdate' => false, 'continue' => '', ); if ( $flags ) { $result += $this->getPageSet()->getFinalParams( $flags ); } return $result; } public function getParamDescription() { return $this->getPageSet()->getFinalParamDescription() + array( 'forcelinkupdate' => 'Update the links tables', 'forcerecursivelinkupdate' => 'Update the links table, and update ' . 'the links tables for any page that uses this page as a template', 'continue' => 'When more results are available, use this to continue', ); } public function getDescription() { return array( 'Purge the cache for the given titles.', 'Requires a POST request if the user is not logged in.' ); } public function getExamples() { return array( 'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page', ); } public function getHelpUrls() { return 'https://www.mediawiki.org/wiki/API:Purge'; } }