4 * API for MediaWiki 1.14+
6 * Created on Sep 2, 2008
8 * Copyright © 2008 Chad Horohoe
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
29 * API interface for page purging
32 class ApiPurge
extends ApiBase
{
36 * Purges the cache of a page
38 public function execute() {
39 $params = $this->extractRequestParams();
41 $continuationManager = new ApiContinuationManager( $this, array(), array() );
42 $this->setContinuationManager( $continuationManager );
44 $forceLinkUpdate = $params['forcelinkupdate'];
45 $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate'];
46 $pageSet = $this->getPageSet();
49 $result = $pageSet->getInvalidTitlesAndRevisions();
51 foreach ( $pageSet->getGoodTitles() as $title ) {
53 ApiQueryBase
::addTitleInfo( $r, $title );
54 $page = WikiPage
::factory( $title );
55 $page->doPurge(); // Directly purge and skip the UI part of purge().
58 if ( $forceLinkUpdate ||
$forceRecursiveLinkUpdate ) {
59 if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) {
60 $popts = $page->makeParserOptions( 'canonical' );
62 # Parse content; note that HTML generation is only needed if we want to cache the result.
63 $content = $page->getContent( Revision
::RAW
);
64 $enableParserCache = $this->getConfig()->get( 'EnableParserCache' );
65 $p_result = $content->getParserOutput(
72 # Update the links tables
73 $updates = $content->getSecondaryDataUpdates(
74 $title, null, $forceRecursiveLinkUpdate, $p_result );
75 DataUpdate
::runUpdates( $updates );
77 $r['linkupdate'] = true;
79 if ( $enableParserCache ) {
80 $pcache = ParserCache
::singleton();
81 $pcache->save( $p_result, $page, $popts );
84 $error = $this->parseMsg( array( 'actionthrottledtext' ) );
85 $this->setWarning( $error['info'] );
86 $forceLinkUpdate = false;
92 $apiResult = $this->getResult();
93 ApiResult
::setIndexedTagName( $result, 'page' );
94 $apiResult->addValue( null, $this->getModuleName(), $result );
96 $values = $pageSet->getNormalizedTitlesAsResult( $apiResult );
98 $apiResult->addValue( null, 'normalized', $values );
100 $values = $pageSet->getConvertedTitlesAsResult( $apiResult );
102 $apiResult->addValue( null, 'converted', $values );
104 $values = $pageSet->getRedirectTitlesAsResult( $apiResult );
106 $apiResult->addValue( null, 'redirects', $values );
109 $this->setContinuationManager( null );
110 $continuationManager->setContinuationIntoResult( $apiResult );
114 * Get a cached instance of an ApiPageSet object
117 private function getPageSet() {
118 if ( !isset( $this->mPageSet
) ) {
119 $this->mPageSet
= new ApiPageSet( $this );
122 return $this->mPageSet
;
125 public function isWriteMode() {
129 public function mustBePosted() {
130 // Anonymous users are not allowed a non-POST request
131 return !$this->getUser()->isAllowed( 'purge' );
134 public function getAllowedParams( $flags = 0 ) {
136 'forcelinkupdate' => false,
137 'forcerecursivelinkupdate' => false,
139 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
143 $result +
= $this->getPageSet()->getFinalParams( $flags );
149 protected function getExamplesMessages() {
151 'action=purge&titles=Main_Page|API'
152 => 'apihelp-purge-example-simple',
153 'action=purge&generator=allpages&gapnamespace=0&gaplimit=10'
154 => 'apihelp-purge-example-generator',
158 public function getHelpUrls() {
159 return 'https://www.mediawiki.org/wiki/API:Purge';