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
|
|
|
* API for MediaWiki 1.14+
|
|
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Sep 2, 2008
|
|
|
|
|
*
|
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.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-09-04 21:53:43 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
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() {
|
2011-10-26 23:27:01 +00:00
|
|
|
$user = $this->getUser();
|
2008-09-04 21:53:43 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2011-10-26 23:27:01 +00:00
|
|
|
if ( !$user->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() &&
|
|
|
|
|
!$this->getRequest()->wasPosted() ) {
|
2010-10-18 09:19:20 +00:00
|
|
|
$this->dieUsageMsg( array( 'mustbeposted', $this->getModuleName() ) );
|
2010-02-24 13:34:11 +00:00
|
|
|
}
|
2011-01-05 17:57:12 +00:00
|
|
|
|
|
|
|
|
$forceLinkUpdate = $params['forcelinkupdate'];
|
2011-12-11 20:43:42 +00:00
|
|
|
$pageSet = new ApiPageSet( $this );
|
|
|
|
|
$pageSet->execute();
|
2011-01-05 17:57:12 +00:00
|
|
|
|
2008-09-04 21:53:43 +00:00
|
|
|
$result = array();
|
2011-12-11 20:43:42 +00:00
|
|
|
foreach( $pageSet->getInvalidTitles() as $title ) {
|
2008-09-04 21:53:43 +00:00
|
|
|
$r = array();
|
2011-12-11 20:43:42 +00:00
|
|
|
$r['title'] = $title;
|
|
|
|
|
$r['invalid'] = '';
|
|
|
|
|
$result[] = $r;
|
|
|
|
|
}
|
|
|
|
|
foreach( $pageSet->getMissingPageIDs() as $p ) {
|
|
|
|
|
$page = array();
|
|
|
|
|
$page['pageid'] = $p;
|
|
|
|
|
$page['missing'] = '';
|
|
|
|
|
$result[] = $page;
|
|
|
|
|
}
|
2011-12-15 17:21:56 +00:00
|
|
|
foreach( $pageSet->getMissingRevisionIDs() as $r ) {
|
2011-12-11 20:43:42 +00:00
|
|
|
$rev = array();
|
|
|
|
|
$rev['revid'] = $r;
|
|
|
|
|
$rev['missing'] = '';
|
|
|
|
|
$result[] = $rev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $pageSet->getTitles() as $title ) {
|
|
|
|
|
$r = array();
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2011-11-05 19:17:15 +00:00
|
|
|
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$page->doPurge(); // Directly purge and skip the UI part of purge().
|
2008-09-04 21:53:43 +00:00
|
|
|
$r['purged'] = '';
|
2011-06-30 01:06:17 +00:00
|
|
|
|
2011-01-05 17:57:12 +00:00
|
|
|
if( $forceLinkUpdate ) {
|
2011-10-26 23:27:01 +00:00
|
|
|
if ( !$user->pingLimiter() ) {
|
2011-01-05 03:31:51 +00:00
|
|
|
global $wgParser, $wgEnableParserCache;
|
2011-11-05 19:17:15 +00:00
|
|
|
|
|
|
|
|
$popts = ParserOptions::newFromContext( $this->getContext() );
|
2012-05-12 13:56:31 +00:00
|
|
|
$popts->setTidy( true );
|
2012-01-21 07:59:25 +00:00
|
|
|
$p_result = $wgParser->parse( $page->getRawText(), $title, $popts,
|
|
|
|
|
true, true, $page->getLatest() );
|
2011-01-05 03:31:51 +00:00
|
|
|
|
|
|
|
|
# Update the links tables
|
2012-05-08 15:09:30 +00:00
|
|
|
$updates = $p_result->getSecondaryDataUpdates( $title );
|
|
|
|
|
DataUpdate::runUpdates( $updates );
|
2011-01-05 03:31:51 +00:00
|
|
|
|
|
|
|
|
$r['linkupdate'] = '';
|
|
|
|
|
|
|
|
|
|
if ( $wgEnableParserCache ) {
|
|
|
|
|
$pcache = ParserCache::singleton();
|
2011-11-05 19:17:15 +00:00
|
|
|
$pcache->save( $p_result, $page, $popts );
|
2011-01-05 03:31:51 +00:00
|
|
|
}
|
2011-01-05 17:57:12 +00:00
|
|
|
} else {
|
2012-06-02 15:43:04 +00:00
|
|
|
$this->setWarning( $this->parseMsg( array( 'actionthrottledtext' ) ) );
|
2011-01-05 17:57:12 +00:00
|
|
|
$forceLinkUpdate = false;
|
2011-01-05 03:31:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-30 01:06:17 +00:00
|
|
|
|
2008-09-04 21:53:43 +00:00
|
|
|
$result[] = $r;
|
|
|
|
|
}
|
2011-06-30 01:06:17 +00:00
|
|
|
$apiResult = $this->getResult();
|
|
|
|
|
$apiResult->setIndexedTagName( $result, 'page' );
|
|
|
|
|
$apiResult->addValue( null, $this->getModuleName(), $result );
|
2008-09-04 21:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-06 13:49:44 +00:00
|
|
|
public function isWriteMode() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-04 21:53:43 +00:00
|
|
|
public function getAllowedParams() {
|
2011-12-11 20:43:42 +00:00
|
|
|
$psModule = new ApiPageSet( $this );
|
|
|
|
|
return $psModule->getAllowedParams() + array(
|
2011-01-05 03:31:51 +00:00
|
|
|
'forcelinkupdate' => false,
|
2008-09-04 21:53:43 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getParamDescription() {
|
2011-12-11 20:43:42 +00:00
|
|
|
$psModule = new ApiPageSet( $this );
|
|
|
|
|
return $psModule->getParamDescription() + array(
|
2011-01-05 03:31:51 +00:00
|
|
|
'forcelinkupdate' => 'Update the links tables',
|
2008-09-04 21:53:43 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDescription() {
|
2010-10-18 09:19:20 +00:00
|
|
|
return array( 'Purge the cache for the given titles.',
|
2011-04-25 14:05:57 +00:00
|
|
|
'Requires a POST request if the user is not logged in.'
|
2010-10-18 09:19:20 +00:00
|
|
|
);
|
2008-09-04 21:53:43 +00:00
|
|
|
}
|
2010-02-24 13:34:11 +00:00
|
|
|
|
|
|
|
|
public function getPossibleErrors() {
|
2011-12-11 20:43:42 +00:00
|
|
|
$psModule = new ApiPageSet( $this );
|
|
|
|
|
return array_merge(
|
|
|
|
|
parent::getPossibleErrors(),
|
|
|
|
|
array( array( 'cantpurge' ), ),
|
|
|
|
|
$psModule->getPossibleErrors()
|
|
|
|
|
);
|
2010-02-13 00:09:05 +00:00
|
|
|
}
|
2008-09-04 21:53:43 +00:00
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getExamples() {
|
2008-09-04 21:53:43 +00:00
|
|
|
return array(
|
2012-01-12 17:36:06 +00:00
|
|
|
'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page',
|
2008-09-04 21:53:43 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-17 16:38:24 +00:00
|
|
|
public function getHelpUrls() {
|
2011-11-28 15:43:11 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/API:Purge';
|
2011-07-17 16:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
2008-09-04 21:53:43 +00:00
|
|
|
public function getVersion() {
|
|
|
|
|
return __CLASS__ . ': $Id$';
|
|
|
|
|
}
|
|
|
|
|
}
|