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
28 if ( !defined( 'MEDIAWIKI' ) ) {
29 require_once( 'ApiBase.php' );
33 * API interface for page purging
36 class ApiPurge
extends ApiBase
{
38 public function __construct( $main, $action ) {
39 parent
::__construct( $main, $action );
43 * Purges the cache of a page
45 public function execute() {
47 $params = $this->extractRequestParams();
48 if ( !$wgUser->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() &&
49 !$this->getMain()->getRequest()->wasPosted() ) {
50 $this->dieUsageMsg( array( 'mustbeposted', $this->getModuleName() ) );
53 $forceLinkUpdate = $params['forcelinkupdate'];
56 foreach ( $params['titles'] as $t ) {
58 $title = Title
::newFromText( $t );
59 if ( !$title instanceof Title
) {
65 ApiQueryBase
::addTitleInfo( $r, $title );
66 if ( !$title->exists() ) {
71 $context = RequestContext
::getMain();
72 $article = MediaWiki
::articleFromTitle( $title, $context );
73 $article->doPurge(); // Directly purge and skip the UI part of purge().
76 if( $forceLinkUpdate ) {
77 if ( !$wgUser->pingLimiter() ) {
78 global $wgParser, $wgEnableParserCache;
79 $popts = new ParserOptions();
80 $p_result = $wgParser->parse( $article->getContent(), $title, $popts );
82 # Update the links tables
83 $u = new LinksUpdate( $title, $p_result );
86 $r['linkupdate'] = '';
88 if ( $wgEnableParserCache ) {
89 $pcache = ParserCache
::singleton();
90 $pcache->save( $p_result, $article, $popts );
93 $this->setWarning( $this->parseMsg( array( 'actionthrottledtext' ) ) );
94 $forceLinkUpdate = false;
100 $this->getResult()->setIndexedTagName( $result, 'page' );
101 $this->getResult()->addValue( null, $this->getModuleName(), $result );
104 public function isWriteMode() {
108 public function getAllowedParams() {
111 ApiBase
::PARAM_ISMULTI
=> true,
112 ApiBase
::PARAM_REQUIRED
=> true
114 'forcelinkupdate' => false,
118 public function getParamDescription() {
120 'titles' => 'A list of titles',
121 'forcelinkupdate' => 'Update the links tables',
125 public function getDescription() {
126 return array( 'Purge the cache for the given titles.',
127 'Requires a POST request if the user is not logged in.'
131 public function getPossibleErrors() {
132 return array_merge( parent
::getPossibleErrors(), array(
133 array( 'cantpurge' ),
137 protected function getExamples() {
139 'api.php?action=purge&titles=Main_Page|API'
143 public function getVersion() {
144 return __CLASS__
. ': $Id$';