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
{
34 public function __construct( $main, $action ) {
35 parent
::__construct( $main, $action );
39 * Purges the cache of a page
41 public function execute() {
42 $user = $this->getUser();
43 $params = $this->extractRequestParams();
44 if ( !$user->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() &&
45 !$this->getRequest()->wasPosted() ) {
46 $this->dieUsageMsg( array( 'mustbeposted', $this->getModuleName() ) );
49 $forceLinkUpdate = $params['forcelinkupdate'];
50 $pageSet = new ApiPageSet( $this );
54 foreach( $pageSet->getInvalidTitles() as $title ) {
60 foreach( $pageSet->getMissingPageIDs() as $p ) {
63 $page['missing'] = '';
66 foreach( $pageSet->getMissingRevisionIDs() as $r ) {
73 foreach ( $pageSet->getTitles() as $title ) {
76 ApiQueryBase
::addTitleInfo( $r, $title );
77 if ( !$title->exists() ) {
83 $page = WikiPage
::factory( $title );
84 $page->doPurge(); // Directly purge and skip the UI part of purge().
87 if( $forceLinkUpdate ) {
88 if ( !$user->pingLimiter() ) {
89 global $wgParser, $wgEnableParserCache;
91 $popts = $page->makeParserOptions( 'canonical' );
92 $p_result = $wgParser->parse( $page->getRawText(), $title, $popts,
93 true, true, $page->getLatest() );
95 # Update the links tables
96 $updates = $p_result->getSecondaryDataUpdates( $title );
97 DataUpdate
::runUpdates( $updates );
99 $r['linkupdate'] = '';
101 if ( $wgEnableParserCache ) {
102 $pcache = ParserCache
::singleton();
103 $pcache->save( $p_result, $page, $popts );
106 $error = $this->parseMsg( array( 'actionthrottledtext' ) );
107 $this->setWarning( $error['info'] );
108 $forceLinkUpdate = false;
114 $apiResult = $this->getResult();
115 $apiResult->setIndexedTagName( $result, 'page' );
116 $apiResult->addValue( null, $this->getModuleName(), $result );
119 public function isWriteMode() {
123 public function getAllowedParams() {
124 $psModule = new ApiPageSet( $this );
125 return $psModule->getAllowedParams() +
array(
126 'forcelinkupdate' => false,
130 public function getParamDescription() {
131 $psModule = new ApiPageSet( $this );
132 return $psModule->getParamDescription() +
array(
133 'forcelinkupdate' => 'Update the links tables',
137 public function getResultProperties() {
139 ApiBase
::PROP_LIST
=> true,
142 ApiBase
::PROP_TYPE
=> 'namespace',
143 ApiBase
::PROP_NULLABLE
=> true
146 ApiBase
::PROP_TYPE
=> 'string',
147 ApiBase
::PROP_NULLABLE
=> true
150 ApiBase
::PROP_TYPE
=> 'integer',
151 ApiBase
::PROP_NULLABLE
=> true
154 ApiBase
::PROP_TYPE
=> 'integer',
155 ApiBase
::PROP_NULLABLE
=> true
157 'invalid' => 'boolean',
158 'missing' => 'boolean',
159 'purged' => 'boolean',
160 'linkupdate' => 'boolean'
165 public function getDescription() {
166 return array( 'Purge the cache for the given titles.',
167 'Requires a POST request if the user is not logged in.'
171 public function getPossibleErrors() {
172 $psModule = new ApiPageSet( $this );
174 parent
::getPossibleErrors(),
175 array( array( 'cantpurge' ), ),
176 $psModule->getPossibleErrors()
180 public function getExamples() {
182 'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page',
186 public function getHelpUrls() {
187 return 'https://www.mediawiki.org/wiki/API:Purge';
190 public function getVersion() {
191 return __CLASS__
. ': $Id$';