MediaWiki REL1_34
ApiPurge.php
Go to the documentation of this file.
1<?php
22
27class ApiPurge extends ApiBase {
28 private $mPageSet = null;
29
33 public function execute() {
34 $params = $this->extractRequestParams();
35
36 $continuationManager = new ApiContinuationManager( $this, [], [] );
37 $this->setContinuationManager( $continuationManager );
38
39 $forceLinkUpdate = $params['forcelinkupdate'];
40 $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate'];
41 $pageSet = $this->getPageSet();
42 $pageSet->execute();
43
44 $result = $pageSet->getInvalidTitlesAndRevisions();
45 $user = $this->getUser();
46
47 foreach ( $pageSet->getGoodTitles() as $title ) {
48 $r = [];
50 $page = WikiPage::factory( $title );
51 if ( !$user->pingLimiter( 'purge' ) ) {
52 // Directly purge and skip the UI part of purge()
53 $page->doPurge();
54 $r['purged'] = true;
55 } else {
56 $this->addWarning( 'apierror-ratelimited' );
57 }
58
59 if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) {
60 if ( !$user->pingLimiter( 'linkpurge' ) ) {
61 # Logging to better see expensive usage patterns
62 if ( $forceRecursiveLinkUpdate ) {
63 LoggerFactory::getInstance( 'RecursiveLinkPurge' )->info(
64 "Recursive link purge enqueued for {title}",
65 [
66 'user' => $this->getUser()->getName(),
67 'title' => $title->getPrefixedText()
68 ]
69 );
70 }
71
72 $page->updateParserCache( [
73 'causeAction' => 'api-purge',
74 'causeAgent' => $this->getUser()->getName(),
75 ] );
76 $page->doSecondaryDataUpdates( [
77 'recursive' => $forceRecursiveLinkUpdate,
78 'causeAction' => 'api-purge',
79 'causeAgent' => $this->getUser()->getName(),
80 'defer' => DeferredUpdates::PRESEND,
81 ] );
82 $r['linkupdate'] = true;
83 } else {
84 $this->addWarning( 'apierror-ratelimited' );
85 $forceLinkUpdate = false;
86 }
87 }
88
89 $result[] = $r;
90 }
91 $apiResult = $this->getResult();
92 ApiResult::setIndexedTagName( $result, 'page' );
93 $apiResult->addValue( null, $this->getModuleName(), $result );
94
95 $values = $pageSet->getNormalizedTitlesAsResult( $apiResult );
96 if ( $values ) {
97 $apiResult->addValue( null, 'normalized', $values );
98 }
99 $values = $pageSet->getConvertedTitlesAsResult( $apiResult );
100 if ( $values ) {
101 $apiResult->addValue( null, 'converted', $values );
102 }
103 $values = $pageSet->getRedirectTitlesAsResult( $apiResult );
104 if ( $values ) {
105 $apiResult->addValue( null, 'redirects', $values );
106 }
107
108 $this->setContinuationManager( null );
109 $continuationManager->setContinuationIntoResult( $apiResult );
110 }
111
116 private function getPageSet() {
117 if ( $this->mPageSet === null ) {
118 $this->mPageSet = new ApiPageSet( $this );
119 }
120
121 return $this->mPageSet;
122 }
123
124 public function isWriteMode() {
125 return true;
126 }
127
128 public function mustBePosted() {
129 return true;
130 }
131
132 public function getAllowedParams( $flags = 0 ) {
133 $result = [
134 'forcelinkupdate' => false,
135 'forcerecursivelinkupdate' => false,
136 'continue' => [
137 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
138 ],
139 ];
140 if ( $flags ) {
141 $result += $this->getPageSet()->getFinalParams( $flags );
142 }
143
144 return $result;
145 }
146
147 protected function getExamplesMessages() {
148 return [
149 'action=purge&titles=Main_Page|API'
150 => 'apihelp-purge-example-simple',
151 'action=purge&generator=allpages&gapnamespace=0&gaplimit=10'
152 => 'apihelp-purge-example-generator',
153 ];
154 }
155
156 public function getHelpUrls() {
157 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Purge';
158 }
159}
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:42
setContinuationManager(ApiContinuationManager $manager=null)
Set the continuation manager.
Definition ApiBase.php:694
getResult()
Get the result object.
Definition ApiBase.php:640
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:761
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:131
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition ApiBase.php:1933
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:520
This manages continuation state.
This class contains a list of pages that the client has requested.
API interface for page purging.
Definition ApiPurge.php:27
getAllowedParams( $flags=0)
Definition ApiPurge.php:132
getExamplesMessages()
Returns usage examples for this module.
Definition ApiPurge.php:147
getPageSet()
Get a cached instance of an ApiPageSet object.
Definition ApiPurge.php:116
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition ApiPurge.php:128
execute()
Purges the cache of a page.
Definition ApiPurge.php:33
getHelpUrls()
Return links to more detailed help pages about the module.
Definition ApiPurge.php:156
isWriteMode()
Indicates whether this module requires write mode.
Definition ApiPurge.php:124
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
PSR-3 logger instance factory.