2008-09-04 21:53:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
2010-02-24 13:34:11 +00:00
|
|
|
/**
|
2008-09-04 21:53:43 +00:00
|
|
|
* Created on Sep 2, 2008
|
|
|
|
|
*
|
|
|
|
|
* API for MediaWiki 1.14+
|
|
|
|
|
*
|
2010-02-24 13:34:11 +00:00
|
|
|
* Copyright © 2008 Chad Horohoe
|
2008-09-04 21:53:43 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
require_once( 'ApiBase.php' );
|
2008-09-04 21:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
2008-09-19 00:21:03 +00:00
|
|
|
/**
|
|
|
|
|
* API interface for page purging
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
2008-09-04 21:53:43 +00:00
|
|
|
class ApiPurge extends ApiBase {
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $main, $action ) {
|
2010-02-24 13:34:11 +00:00
|
|
|
parent::__construct( $main, $action );
|
2008-09-04 21:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Purges the cache of a page
|
|
|
|
|
*/
|
|
|
|
|
public function execute() {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$params = $this->extractRequestParams();
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !$wgUser->isAllowed( 'purge' ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'cantpurge' ) );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
|
|
|
|
if ( !isset( $params['titles'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'titles' ) );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2008-09-04 21:53:43 +00:00
|
|
|
$result = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $params['titles'] as $t ) {
|
2008-09-04 21:53:43 +00:00
|
|
|
$r = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
$title = Title::newFromText( $t );
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !$title instanceof Title ) {
|
2008-09-04 21:53:43 +00:00
|
|
|
$r['title'] = $t;
|
|
|
|
|
$r['invalid'] = '';
|
|
|
|
|
$result[] = $r;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
ApiQueryBase::addTitleInfo( $r, $title );
|
2010-02-24 13:34:11 +00:00
|
|
|
if ( !$title->exists() ) {
|
2008-09-04 21:53:43 +00:00
|
|
|
$r['missing'] = '';
|
|
|
|
|
$result[] = $r;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-04-03 13:27:30 +00:00
|
|
|
$article = Mediawiki::articleFromTitle( $title );
|
2008-09-04 21:53:43 +00:00
|
|
|
$article->doPurge(); // Directly purge and skip the UI part of purge().
|
|
|
|
|
$r['purged'] = '';
|
|
|
|
|
$result[] = $r;
|
|
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->setIndexedTagName( $result, 'page' );
|
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
2008-09-04 21:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-06 13:49:44 +00:00
|
|
|
public function mustBePosted() {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
return $wgUser->isAnon();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isWriteMode() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-04 21:53:43 +00:00
|
|
|
public function getAllowedParams() {
|
2010-02-24 13:34:11 +00:00
|
|
|
return array(
|
2008-09-04 21:53:43 +00:00
|
|
|
'titles' => array(
|
2010-02-24 13:34:11 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true
|
2008-09-04 21:53:43 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getParamDescription() {
|
2010-02-24 13:34:11 +00:00
|
|
|
return array(
|
2008-09-04 21:53:43 +00:00
|
|
|
'titles' => 'A list of titles',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDescription() {
|
2010-05-25 20:46:09 +00:00
|
|
|
return 'Purge the cache for the given titles';
|
2008-09-04 21:53:43 +00:00
|
|
|
}
|
2010-02-24 13:34:11 +00:00
|
|
|
|
|
|
|
|
public function getPossibleErrors() {
|
2010-02-13 00:09:05 +00:00
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
|
|
|
|
array( 'cantpurge' ),
|
|
|
|
|
array( 'missingparam', 'titles' ),
|
2010-02-24 13:34:11 +00:00
|
|
|
) );
|
2010-02-13 00:09:05 +00:00
|
|
|
}
|
2008-09-04 21:53:43 +00:00
|
|
|
|
|
|
|
|
protected function getExamples() {
|
|
|
|
|
return array(
|
|
|
|
|
'api.php?action=purge&titles=Main_Page|API'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
|
|
|
|
return __CLASS__ . ': $Id$';
|
|
|
|
|
}
|
|
|
|
|
}
|