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 $this->getResult()->beginContinuation( $params['continue'], array(), array() );
43 $forceLinkUpdate = $params['forcelinkupdate'];
44 $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate'];
45 $pageSet = $this->getPageSet();
48 $result = $pageSet->getInvalidTitlesAndRevisions();
50 foreach ( $pageSet->getGoodTitles() as $title ) {
52 ApiQueryBase
::addTitleInfo( $r, $title );
53 $page = WikiPage
::factory( $title );
54 $page->doPurge(); // Directly purge and skip the UI part of purge().
57 if ( $forceLinkUpdate ||
$forceRecursiveLinkUpdate ) {
58 if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) {
59 $popts = $page->makeParserOptions( 'canonical' );
61 # Parse content; note that HTML generation is only needed if we want to cache the result.
62 $content = $page->getContent( Revision
::RAW
);
63 $enableParserCache = $this->getConfig()->get( 'EnableParserCache' );
64 $p_result = $content->getParserOutput(
71 # Update the links tables
72 $updates = $content->getSecondaryDataUpdates(
73 $title, null, $forceRecursiveLinkUpdate, $p_result );
74 DataUpdate
::runUpdates( $updates );
76 $r['linkupdate'] = '';
78 if ( $enableParserCache ) {
79 $pcache = ParserCache
::singleton();
80 $pcache->save( $p_result, $page, $popts );
83 $error = $this->parseMsg( array( 'actionthrottledtext' ) );
84 $this->setWarning( $error['info'] );
85 $forceLinkUpdate = false;
91 $apiResult = $this->getResult();
92 $apiResult->setIndexedTagName( $result, 'page' );
93 $apiResult->addValue( null, $this->getModuleName(), $result );
95 $values = $pageSet->getNormalizedTitlesAsResult( $apiResult );
97 $apiResult->addValue( null, 'normalized', $values );
99 $values = $pageSet->getConvertedTitlesAsResult( $apiResult );
101 $apiResult->addValue( null, 'converted', $values );
103 $values = $pageSet->getRedirectTitlesAsResult( $apiResult );
105 $apiResult->addValue( null, 'redirects', $values );
108 $apiResult->endContinuation();
112 * Get a cached instance of an ApiPageSet object
115 private function getPageSet() {
116 if ( !isset( $this->mPageSet
) ) {
117 $this->mPageSet
= new ApiPageSet( $this );
120 return $this->mPageSet
;
123 public function isWriteMode() {
127 public function mustBePosted() {
128 // Anonymous users are not allowed a non-POST request
129 return !$this->getUser()->isAllowed( 'purge' );
132 public function getAllowedParams( $flags = 0 ) {
134 'forcelinkupdate' => false,
135 'forcerecursivelinkupdate' => false,
137 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
141 $result +
= $this->getPageSet()->getFinalParams( $flags );
147 protected function getExamplesMessages() {
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',
156 public function getHelpUrls() {
157 return 'https://www.mediawiki.org/wiki/API:Purge';