summaryrefslogtreecommitdiff
path: root/includes/api/ApiPurge.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiPurge.php')
-rw-r--r--includes/api/ApiPurge.php142
1 files changed, 85 insertions, 57 deletions
diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php
index 9fedaf1b..134f4a0d 100644
--- a/includes/api/ApiPurge.php
+++ b/includes/api/ApiPurge.php
@@ -31,69 +31,69 @@
*/
class ApiPurge extends ApiBase {
- public function __construct( $main, $action ) {
- parent::__construct( $main, $action );
+ private $mPageSet;
+
+ /**
+ * Add all items from $values into the result
+ * @param array $result output
+ * @param array $values values to add
+ * @param string $flag the name of the boolean flag to mark this element
+ * @param string $name if given, name of the value
+ */
+ private static function addValues( array &$result, $values, $flag = null, $name = null ) {
+ foreach ( $values as $val ) {
+ if( $val instanceof Title ) {
+ $v = array();
+ ApiQueryBase::addTitleInfo( $v, $val );
+ } elseif( $name !== null ) {
+ $v = array( $name => $val );
+ } else {
+ $v = $val;
+ }
+ if( $flag !== null ) {
+ $v[$flag] = '';
+ }
+ $result[] = $v;
+ }
}
/**
* Purges the cache of a page
*/
public function execute() {
- $user = $this->getUser();
$params = $this->extractRequestParams();
- if ( !$user->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() &&
- !$this->getRequest()->wasPosted() ) {
- $this->dieUsageMsg( array( 'mustbeposted', $this->getModuleName() ) );
- }
$forceLinkUpdate = $params['forcelinkupdate'];
- $pageSet = new ApiPageSet( $this );
+ $pageSet = $this->getPageSet();
$pageSet->execute();
$result = array();
- foreach( $pageSet->getInvalidTitles() as $title ) {
- $r = array();
- $r['title'] = $title;
- $r['invalid'] = '';
- $result[] = $r;
- }
- foreach( $pageSet->getMissingPageIDs() as $p ) {
- $page = array();
- $page['pageid'] = $p;
- $page['missing'] = '';
- $result[] = $page;
- }
- foreach( $pageSet->getMissingRevisionIDs() as $r ) {
- $rev = array();
- $rev['revid'] = $r;
- $rev['missing'] = '';
- $result[] = $rev;
- }
-
- foreach ( $pageSet->getTitles() as $title ) {
+ self::addValues( $result, $pageSet->getInvalidTitles(), 'invalid', 'title' );
+ self::addValues( $result, $pageSet->getSpecialTitles(), 'special', 'title' );
+ self::addValues( $result, $pageSet->getMissingPageIDs(), 'missing', 'pageid' );
+ self::addValues( $result, $pageSet->getMissingRevisionIDs(), 'missing', 'revid' );
+ self::addValues( $result, $pageSet->getMissingTitles(), 'missing' );
+ self::addValues( $result, $pageSet->getInterwikiTitlesAsResult() );
+
+ foreach ( $pageSet->getGoodTitles() as $title ) {
$r = array();
-
ApiQueryBase::addTitleInfo( $r, $title );
- if ( !$title->exists() ) {
- $r['missing'] = '';
- $result[] = $r;
- continue;
- }
-
$page = WikiPage::factory( $title );
$page->doPurge(); // Directly purge and skip the UI part of purge().
$r['purged'] = '';
- if( $forceLinkUpdate ) {
- if ( !$user->pingLimiter() ) {
- global $wgParser, $wgEnableParserCache;
+ if ( $forceLinkUpdate ) {
+ if ( !$this->getUser()->pingLimiter() ) {
+ global $wgEnableParserCache;
$popts = $page->makeParserOptions( 'canonical' );
- $p_result = $wgParser->parse( $page->getRawText(), $title, $popts,
- true, true, $page->getLatest() );
+
+ # Parse content; note that HTML generation is only needed if we want to cache the result.
+ $content = $page->getContent( Revision::RAW );
+ $p_result = $content->getParserOutput( $title, $page->getLatest(), $popts, $wgEnableParserCache );
# Update the links tables
- $updates = $p_result->getSecondaryDataUpdates( $title );
+ $updates = $content->getSecondaryDataUpdates( $title, null, true, $p_result );
DataUpdate::runUpdates( $updates );
$r['linkupdate'] = '';
@@ -114,24 +114,52 @@ class ApiPurge extends ApiBase {
$apiResult = $this->getResult();
$apiResult->setIndexedTagName( $result, 'page' );
$apiResult->addValue( null, $this->getModuleName(), $result );
+
+ $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 );
+ }
+ return $this->mPageSet;
}
public function isWriteMode() {
return true;
}
- public function getAllowedParams() {
- $psModule = new ApiPageSet( $this );
- return $psModule->getAllowedParams() + array(
- 'forcelinkupdate' => false,
- );
+ public function mustBePosted() {
+ // Anonymous users are not allowed a non-POST request
+ return !$this->getUser()->isAllowed( 'purge' );
+ }
+
+ public function getAllowedParams( $flags = 0 ) {
+ $result = array( 'forcelinkupdate' => false );
+ if ( $flags ) {
+ $result += $this->getPageSet()->getFinalParams( $flags );
+ }
+ return $result;
}
public function getParamDescription() {
- $psModule = new ApiPageSet( $this );
- return $psModule->getParamDescription() + array(
- 'forcelinkupdate' => 'Update the links tables',
- );
+ return $this->getPageSet()->getParamDescription()
+ + array( 'forcelinkupdate' => 'Update the links tables' );
}
public function getResultProperties() {
@@ -155,9 +183,14 @@ class ApiPurge extends ApiBase {
ApiBase::PROP_NULLABLE => true
),
'invalid' => 'boolean',
+ 'special' => 'boolean',
'missing' => 'boolean',
'purged' => 'boolean',
- 'linkupdate' => 'boolean'
+ 'linkupdate' => 'boolean',
+ 'iw' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ ),
)
);
}
@@ -169,10 +202,9 @@ class ApiPurge extends ApiBase {
}
public function getPossibleErrors() {
- $psModule = new ApiPageSet( $this );
return array_merge(
parent::getPossibleErrors(),
- $psModule->getPossibleErrors()
+ $this->getPageSet()->getPossibleErrors()
);
}
@@ -185,8 +217,4 @@ class ApiPurge extends ApiBase {
public function getHelpUrls() {
return 'https://www.mediawiki.org/wiki/API:Purge';
}
-
- public function getVersion() {
- return __CLASS__ . ': $Id$';
- }
}