*
* @file
*/
+use MediaWiki\Logger\LoggerFactory;
/**
* API interface for page purging
public function execute() {
$params = $this->extractRequestParams();
- $continuationManager = new ApiContinuationManager( $this, array(), array() );
+ $continuationManager = new ApiContinuationManager( $this, [], [] );
$this->setContinuationManager( $continuationManager );
$forceLinkUpdate = $params['forcelinkupdate'];
$pageSet->execute();
$result = $pageSet->getInvalidTitlesAndRevisions();
+ $user = $this->getUser();
foreach ( $pageSet->getGoodTitles() as $title ) {
- $r = array();
+ $r = [];
ApiQueryBase::addTitleInfo( $r, $title );
$page = WikiPage::factory( $title );
- $page->doPurge(); // Directly purge and skip the UI part of purge().
- $r['purged'] = '';
+ if ( !$user->pingLimiter( 'purge' ) ) {
+ $page->doPurge(); // Directly purge and skip the UI part of purge().
+ $r['purged'] = true;
+ } else {
+ $error = $this->parseMsg( [ 'actionthrottledtext' ] );
+ $this->setWarning( $error['info'] );
+ }
if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) {
- if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) {
+ if ( !$user->pingLimiter( 'linkpurge' ) ) {
$popts = $page->makeParserOptions( 'canonical' );
# Parse content; note that HTML generation is only needed if we want to cache the result.
$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()
+ ]
+ );
+ }
+
# Update the links tables
$updates = $content->getSecondaryDataUpdates(
$title, null, $forceRecursiveLinkUpdate, $p_result );
DataUpdate::runUpdates( $updates );
- $r['linkupdate'] = '';
+ $r['linkupdate'] = true;
if ( $enableParserCache ) {
$pcache = ParserCache::singleton();
$pcache->save( $p_result, $page, $popts );
}
} else {
- $error = $this->parseMsg( array( 'actionthrottledtext' ) );
+ $error = $this->parseMsg( [ 'actionthrottledtext' ] );
$this->setWarning( $error['info'] );
$forceLinkUpdate = false;
}
}
public function getAllowedParams( $flags = 0 ) {
- $result = array(
+ $result = [
'forcelinkupdate' => false,
'forcerecursivelinkupdate' => false,
- 'continue' => array(
+ 'continue' => [
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
- ),
- );
+ ],
+ ];
if ( $flags ) {
$result += $this->getPageSet()->getFinalParams( $flags );
}
}
protected function getExamplesMessages() {
- return array(
+ return [
'action=purge&titles=Main_Page|API'
=> 'apihelp-purge-example-simple',
'action=purge&generator=allpages&gapnamespace=0&gaplimit=10'
=> 'apihelp-purge-example-generator',
- );
+ ];
}
public function getHelpUrls() {