fa888c9aaa6afa0393adb0d847931e55de258cf6
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
{
35 * Purges the cache of a page
37 public function execute() {
38 $user = $this->getUser();
39 $params = $this->extractRequestParams();
40 if ( !$user->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() &&
41 !$this->getRequest()->wasPosted() ) {
42 $this->dieUsageMsg( array( 'mustbeposted', $this->getModuleName() ) );
45 $forceLinkUpdate = $params['forcelinkupdate'];
46 $pageSet = new ApiPageSet( $this );
50 foreach( $pageSet->getInvalidTitles() as $title ) {
56 foreach( $pageSet->getMissingPageIDs() as $p ) {
59 $page['missing'] = '';
62 foreach( $pageSet->getMissingRevisionIDs() as $r ) {
69 foreach ( $pageSet->getTitles() as $title ) {
72 ApiQueryBase
::addTitleInfo( $r, $title );
73 if ( !$title->exists() ) {
79 $page = WikiPage
::factory( $title );
80 $page->doPurge(); // Directly purge and skip the UI part of purge().
83 if( $forceLinkUpdate ) {
84 if ( !$user->pingLimiter() ) {
85 global $wgEnableParserCache;
87 $popts = $page->makeParserOptions( 'canonical' );
89 # Parse content; note that HTML generation is only needed if we want to cache the result.
90 $content = $page->getContent( Revision
::RAW
);
91 $p_result = $content->getParserOutput( $title, $page->getLatest(), $popts, $wgEnableParserCache );
93 # Update the links tables
94 $updates = $content->getSecondaryDataUpdates( $title, null, true, $p_result );
95 DataUpdate
::runUpdates( $updates );
97 $r['linkupdate'] = '';
99 if ( $wgEnableParserCache ) {
100 $pcache = ParserCache
::singleton();
101 $pcache->save( $p_result, $page, $popts );
104 $error = $this->parseMsg( array( 'actionthrottledtext' ) );
105 $this->setWarning( $error['info'] );
106 $forceLinkUpdate = false;
112 $apiResult = $this->getResult();
113 $apiResult->setIndexedTagName( $result, 'page' );
114 $apiResult->addValue( null, $this->getModuleName(), $result );
117 public function isWriteMode() {
121 public function getAllowedParams() {
122 $psModule = new ApiPageSet( $this );
123 return $psModule->getAllowedParams() +
array(
124 'forcelinkupdate' => false,
128 public function getParamDescription() {
129 $psModule = new ApiPageSet( $this );
130 return $psModule->getParamDescription() +
array(
131 'forcelinkupdate' => 'Update the links tables',
135 public function getResultProperties() {
137 ApiBase
::PROP_LIST
=> true,
140 ApiBase
::PROP_TYPE
=> 'namespace',
141 ApiBase
::PROP_NULLABLE
=> true
144 ApiBase
::PROP_TYPE
=> 'string',
145 ApiBase
::PROP_NULLABLE
=> true
148 ApiBase
::PROP_TYPE
=> 'integer',
149 ApiBase
::PROP_NULLABLE
=> true
152 ApiBase
::PROP_TYPE
=> 'integer',
153 ApiBase
::PROP_NULLABLE
=> true
155 'invalid' => 'boolean',
156 'missing' => 'boolean',
157 'purged' => 'boolean',
158 'linkupdate' => 'boolean'
163 public function getDescription() {
164 return array( 'Purge the cache for the given titles.',
165 'Requires a POST request if the user is not logged in.'
169 public function getPossibleErrors() {
170 $psModule = new ApiPageSet( $this );
172 parent
::getPossibleErrors(),
173 $psModule->getPossibleErrors()
177 public function getExamples() {
179 'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page',
183 public function getHelpUrls() {
184 return 'https://www.mediawiki.org/wiki/API:Purge';