X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiPurge.php;h=5d1352ce3fa070037df0e5967189bb38727173eb;hb=ce079cf6ad79ca8d3360817f809b219d166f9153;hp=64bb9ba10110b1dd1dce5208f8ec0eee232d2937;hpb=e3bd13db0c285f312e31bb1b7271af4628cca80c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index 64bb9ba101..324d030fdb 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -37,6 +37,11 @@ class ApiPurge extends ApiBase { * Purges the cache of a page */ public function execute() { + $main = $this->getMain(); + if ( !$main->isInternalMode() && !$main->getRequest()->wasPosted() ) { + $this->addDeprecation( 'apiwarn-deprecation-purge-get', 'purge-via-GET' ); + } + $params = $this->extractRequestParams(); $continuationManager = new ApiContinuationManager( $this, [], [] ); @@ -55,11 +60,15 @@ class ApiPurge extends ApiBase { ApiQueryBase::addTitleInfo( $r, $title ); $page = WikiPage::factory( $title ); if ( !$user->pingLimiter( 'purge' ) ) { - $page->doPurge(); // Directly purge and skip the UI part of purge(). + $flags = WikiPage::PURGE_ALL; + if ( !$this->getRequest()->wasPosted() ) { + $flags ^= WikiPage::PURGE_GLOBAL_PCACHE; // skip DB_MASTER write + } + // Directly purge and skip the UI part of purge() + $page->doPurge( $flags ); $r['purged'] = true; } else { - $error = $this->parseMsg( [ 'actionthrottledtext' ] ); - $this->setWarning( $error['info'] ); + $this->addWarning( 'apierror-ratelimited' ); } if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) { @@ -68,39 +77,42 @@ class ApiPurge extends ApiBase { # 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 - ); - - # Logging to better see expensive usage patterns - if ( $forceRecursiveLinkUpdate ) { - LoggerFactory::getInstance( 'RecursiveLinkPurge' )->info( - "Recursive link purge enqueued for {title}", - [ - 'user' => $this->getUser()->getName(), - 'title' => $title->getPrefixedText() - ] + if ( $content ) { + $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'] = true; - if ( $enableParserCache ) { - $pcache = ParserCache::singleton(); - $pcache->save( $p_result, $page, $popts ); + # Logging to better see expensive usage patterns + if ( $forceRecursiveLinkUpdate ) { + LoggerFactory::getInstance( 'RecursiveLinkPurge' )->info( + "Recursive link purge enqueued for {title}", + [ + 'user' => $this->getUser()->getName(), + 'title' => $title->getPrefixedText() + ] + ); + } + + # Update the links tables + $updates = $content->getSecondaryDataUpdates( + $title, null, $forceRecursiveLinkUpdate, $p_result ); + foreach ( $updates as $update ) { + DeferredUpdates::addUpdate( $update, DeferredUpdates::PRESEND ); + } + + $r['linkupdate'] = true; + + if ( $enableParserCache ) { + $pcache = ParserCache::singleton(); + $pcache->save( $p_result, $page, $popts ); + } } } else { - $error = $this->parseMsg( [ 'actionthrottledtext' ] ); - $this->setWarning( $error['info'] ); + $this->addWarning( 'apierror-ratelimited' ); $forceLinkUpdate = false; } } @@ -149,6 +161,18 @@ class ApiPurge extends ApiBase { return !$this->getUser()->isAllowed( 'purge' ); } + protected function getHelpFlags() { + $flags = parent::getHelpFlags(); + + // Claim that we must be posted for the purposes of help and paraminfo. + // @todo Remove this when self::mustBePosted() is updated for T145649 + if ( !in_array( 'mustbeposted', $flags, true ) ) { + $flags[] = 'mustbeposted'; + } + + return $flags; + } + public function getAllowedParams( $flags = 0 ) { $result = [ 'forcelinkupdate' => false,