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 {
|
2013-02-08 20:39:40 +00:00
|
|
|
private $mPageSet;
|
|
|
|
|
|
2008-09-04 21:53:43 +00:00
|
|
|
/**
|
|
|
|
|
* Purges the cache of a page
|
|
|
|
|
*/
|
|
|
|
|
public function execute() {
|
|
|
|
|
$params = $this->extractRequestParams();
|
2011-01-05 17:57:12 +00:00
|
|
|
|
|
|
|
|
$forceLinkUpdate = $params['forcelinkupdate'];
|
2013-07-05 04:49:02 +00:00
|
|
|
$forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate'];
|
2013-02-08 20:39:40 +00:00
|
|
|
$pageSet = $this->getPageSet();
|
2011-12-11 20:43:42 +00:00
|
|
|
$pageSet->execute();
|
2011-01-05 17:57:12 +00:00
|
|
|
|
2014-01-29 18:10:36 +00:00
|
|
|
$result = $pageSet->getInvalidTitlesAndRevisions();
|
2013-02-08 20:39:40 +00:00
|
|
|
|
|
|
|
|
foreach ( $pageSet->getGoodTitles() as $title ) {
|
2008-09-04 21:53:43 +00:00
|
|
|
$r = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
ApiQueryBase::addTitleInfo( $r, $title );
|
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
|
|
|
|
2013-07-05 04:49:02 +00:00
|
|
|
if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) {
|
2013-09-20 22:26:08 +00:00
|
|
|
if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) {
|
2012-06-25 11:39:29 +00:00
|
|
|
$popts = $page->makeParserOptions( 'canonical' );
|
2012-06-13 09:59:40 +00:00
|
|
|
|
|
|
|
|
# Parse content; note that HTML generation is only needed if we want to cache the result.
|
|
|
|
|
$content = $page->getContent( Revision::RAW );
|
2014-01-24 02:51:11 +00:00
|
|
|
$enableParserCache = $this->getConfig()->get( 'EnableParserCache' );
|
2013-11-14 18:03:09 +00:00
|
|
|
$p_result = $content->getParserOutput(
|
|
|
|
|
$title,
|
|
|
|
|
$page->getLatest(),
|
|
|
|
|
$popts,
|
2014-01-24 02:51:11 +00:00
|
|
|
$enableParserCache
|
2013-11-14 18:03:09 +00:00
|
|
|
);
|
2011-01-05 03:31:51 +00:00
|
|
|
|
|
|
|
|
# Update the links tables
|
2013-07-05 04:49:02 +00:00
|
|
|
$updates = $content->getSecondaryDataUpdates(
|
|
|
|
|
$title, null, $forceRecursiveLinkUpdate, $p_result );
|
2012-05-08 15:09:30 +00:00
|
|
|
DataUpdate::runUpdates( $updates );
|
2011-01-05 03:31:51 +00:00
|
|
|
|
|
|
|
|
$r['linkupdate'] = '';
|
|
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $enableParserCache ) {
|
2011-01-05 03:31:51 +00:00
|
|
|
$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-05 22:58:54 +00:00
|
|
|
$error = $this->parseMsg( array( 'actionthrottledtext' ) );
|
|
|
|
|
$this->setWarning( $error['info'] );
|
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 );
|
2013-02-08 20:39:40 +00:00
|
|
|
|
|
|
|
|
$values = $pageSet->getNormalizedTitlesAsResult( $apiResult );
|
|
|
|
|
if ( $values ) {
|
|
|
|
|
$apiResult->addValue( null, 'normalized', $values );
|
|
|
|
|
}
|
|
|
|
|
$values = $pageSet->getConvertedTitlesAsResult( $apiResult );
|
|
|
|
|
if ( $values ) {
|
|
|
|
|
$apiResult->addValue( null, 'converted', $values );
|
|
|
|
|
}
|
|
|
|
|
$values = $pageSet->getRedirectTitlesAsResult( $apiResult );
|
|
|
|
|
if ( $values ) {
|
|
|
|
|
$apiResult->addValue( null, 'redirects', $values );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a cached instance of an ApiPageSet object
|
|
|
|
|
* @return ApiPageSet
|
|
|
|
|
*/
|
|
|
|
|
private function getPageSet() {
|
|
|
|
|
if ( !isset( $this->mPageSet ) ) {
|
|
|
|
|
$this->mPageSet = new ApiPageSet( $this );
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
return $this->mPageSet;
|
2008-09-04 21:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-06 13:49:44 +00:00
|
|
|
public function isWriteMode() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
public function mustBePosted() {
|
|
|
|
|
// Anonymous users are not allowed a non-POST request
|
|
|
|
|
return !$this->getUser()->isAllowed( 'purge' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAllowedParams( $flags = 0 ) {
|
2013-07-05 04:49:02 +00:00
|
|
|
$result = array(
|
|
|
|
|
'forcelinkupdate' => false,
|
|
|
|
|
'forcerecursivelinkupdate' => false
|
|
|
|
|
);
|
2013-02-08 20:39:40 +00:00
|
|
|
if ( $flags ) {
|
|
|
|
|
$result += $this->getPageSet()->getFinalParams( $flags );
|
|
|
|
|
}
|
2013-11-14 12:47:20 +00:00
|
|
|
|
2013-02-08 20:39:40 +00:00
|
|
|
return $result;
|
2008-09-04 21:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getParamDescription() {
|
2013-04-05 15:09:18 +00:00
|
|
|
return $this->getPageSet()->getFinalParamDescription()
|
2013-07-05 04:49:02 +00:00
|
|
|
+ array(
|
|
|
|
|
'forcelinkupdate' => 'Update the links tables',
|
|
|
|
|
'forcerecursivelinkupdate' => 'Update the links table, and update ' .
|
|
|
|
|
'the links tables for any page that uses this page as a template',
|
|
|
|
|
);
|
2008-09-04 21:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
Added result properties to action=paraminfo
Added information about the properties of the results of API calls
to action=paraminfo, including information about "property groups":
what should the prop parameter be set to to get that property.
Uses the same format for types as parameters already do.
The output format of some modules doesn't fit this, so the result
properties for them weren't added, or only partially.
Partially implemented modules:
* expandtemplates:
parsetree is in its own tag
* protect, allusers, backlinks, deletedrevs, info, imageinfo,
logevents, querypage, recentchanges, revisions, searchinfo,
usercontribs, userinfo, users, watchlist, upload:
response with partially complex structure
Not implemented modules:
* feedcontributions, feedwatchlist, opensearch, rds:
non-standard reponse
* help:
error is normal response; not very useful for automated tools anyway
* paraminfo, parse, pageprops, siteinfo, userrights:
response with complex structure
Change-Id: Iff2a9bef79f994e73eef3062b4dd5461bff968ab
2012-05-02 15:00:30 +00:00
|
|
|
public function getResultProperties() {
|
|
|
|
|
return array(
|
|
|
|
|
ApiBase::PROP_LIST => true,
|
|
|
|
|
'' => array(
|
|
|
|
|
'ns' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'namespace',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'title' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'string',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'pageid' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'integer',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'revid' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'integer',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'invalid' => 'boolean',
|
2013-02-08 20:39:40 +00:00
|
|
|
'special' => 'boolean',
|
Added result properties to action=paraminfo
Added information about the properties of the results of API calls
to action=paraminfo, including information about "property groups":
what should the prop parameter be set to to get that property.
Uses the same format for types as parameters already do.
The output format of some modules doesn't fit this, so the result
properties for them weren't added, or only partially.
Partially implemented modules:
* expandtemplates:
parsetree is in its own tag
* protect, allusers, backlinks, deletedrevs, info, imageinfo,
logevents, querypage, recentchanges, revisions, searchinfo,
usercontribs, userinfo, users, watchlist, upload:
response with partially complex structure
Not implemented modules:
* feedcontributions, feedwatchlist, opensearch, rds:
non-standard reponse
* help:
error is normal response; not very useful for automated tools anyway
* paraminfo, parse, pageprops, siteinfo, userrights:
response with complex structure
Change-Id: Iff2a9bef79f994e73eef3062b4dd5461bff968ab
2012-05-02 15:00:30 +00:00
|
|
|
'missing' => 'boolean',
|
|
|
|
|
'purged' => 'boolean',
|
2013-02-08 20:39:40 +00:00
|
|
|
'linkupdate' => 'boolean',
|
|
|
|
|
'iw' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'string',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
Added result properties to action=paraminfo
Added information about the properties of the results of API calls
to action=paraminfo, including information about "property groups":
what should the prop parameter be set to to get that property.
Uses the same format for types as parameters already do.
The output format of some modules doesn't fit this, so the result
properties for them weren't added, or only partially.
Partially implemented modules:
* expandtemplates:
parsetree is in its own tag
* protect, allusers, backlinks, deletedrevs, info, imageinfo,
logevents, querypage, recentchanges, revisions, searchinfo,
usercontribs, userinfo, users, watchlist, upload:
response with partially complex structure
Not implemented modules:
* feedcontributions, feedwatchlist, opensearch, rds:
non-standard reponse
* help:
error is normal response; not very useful for automated tools anyway
* paraminfo, parse, pageprops, siteinfo, userrights:
response with complex structure
Change-Id: Iff2a9bef79f994e73eef3062b4dd5461bff968ab
2012-05-02 15:00:30 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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.',
|
2014-03-09 20:22:47 +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
|
|
|
return array_merge(
|
|
|
|
|
parent::getPossibleErrors(),
|
2013-04-05 16:34:47 +00:00
|
|
|
$this->getPageSet()->getFinalPossibleErrors()
|
2011-12-11 20:43:42 +00:00
|
|
|
);
|
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
|
|
|
}
|