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'];
52 foreach ( $params['titles'] as $t ) {
54 $title = Title
::newFromText( $t );
55 if ( !$title instanceof Title
) {
61 ApiQueryBase
::addTitleInfo( $r, $title );
62 if ( !$title->exists() ) {
68 $page = WikiPage
::factory( $title );
69 $page->doPurge(); // Directly purge and skip the UI part of purge().
72 if( $forceLinkUpdate ) {
73 if ( !$user->pingLimiter() ) {
74 global $wgParser, $wgEnableParserCache;
76 $popts = ParserOptions
::newFromContext( $this->getContext() );
77 $p_result = $wgParser->parse( $page->getRawText(), $title, $popts );
79 # Update the links tables
80 $u = new LinksUpdate( $title, $p_result );
83 $r['linkupdate'] = '';
85 if ( $wgEnableParserCache ) {
86 $pcache = ParserCache
::singleton();
87 $pcache->save( $p_result, $page, $popts );
90 $this->setWarning( $this->parseMsg( array( 'actionthrottledtext' ) ) );
91 $forceLinkUpdate = false;
97 $apiResult = $this->getResult();
98 $apiResult->setIndexedTagName( $result, 'page' );
99 $apiResult->addValue( null, $this->getModuleName(), $result );
102 public function isWriteMode() {
106 public function getAllowedParams() {
109 ApiBase
::PARAM_ISMULTI
=> true,
110 ApiBase
::PARAM_REQUIRED
=> true
112 'forcelinkupdate' => false,
116 public function getParamDescription() {
118 'titles' => 'A list of titles',
119 'forcelinkupdate' => 'Update the links tables',
123 public function getDescription() {
124 return array( 'Purge the cache for the given titles.',
125 'Requires a POST request if the user is not logged in.'
129 public function getPossibleErrors() {
130 return array_merge( parent
::getPossibleErrors(), array(
131 array( 'cantpurge' ),
135 public function getExamples() {
137 'api.php?action=purge&titles=Main_Page|API'
141 public function getHelpUrls() {
142 return 'https://www.mediawiki.org/wiki/API:Purge';
145 public function getVersion() {
146 return __CLASS__
. ': $Id$';