From: Sam Reed Date: Sun, 11 Dec 2011 20:43:42 +0000 (+0000) Subject: * (bug 32495) API should allow purge by pageids. X-Git-Tag: 1.31.0-rc.0~26070 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=d1e77338a65a22a452f3e78e755f775f7a101b55;p=lhc%2Fweb%2Fwiklou.git * (bug 32495) API should allow purge by pageids. ApiPageSet isn't really designed for non query usage, but a little hacking and it can be made to work in the ApiPageSet mould. Allows us to use titles, pageids and revids, without the work of validating them and such ourselves Same caveat that you can't use a mix of them in one request - tough! --- diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 2929f78054..86b61c372c 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -205,6 +205,7 @@ production. many types. * (bug 32415) Empty page get no size attribute in API output. * (bug 31759) Undefined property notice in querypages API. +* (bug 32495) API should allow purge by pageids. === Languages updated in 1.19 === diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index f0ae64e937..ceee00a00e 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -47,17 +47,32 @@ class ApiPurge extends ApiBase { } $forceLinkUpdate = $params['forcelinkupdate']; + $pageSet = new ApiPageSet( $this ); + $pageSet->execute(); $result = array(); - foreach ( $params['titles'] as $t ) { + foreach( $pageSet->getInvalidTitles() as $title ) { $r = array(); - $title = Title::newFromText( $t ); - if ( !$title instanceof Title ) { - $r['title'] = $t; - $r['invalid'] = ''; - $result[] = $r; - continue; - } + $r['title'] = $title; + $r['invalid'] = ''; + $result[] = $r; + } + foreach( $pageSet->getMissingPageIDs() as $p ) { + $page = array(); + $page['pageid'] = $p; + $page['missing'] = ''; + $result[] = $page; + } + foreach( $pageSet->getMissingPageIDs() as $r ) { + $rev = array(); + $rev['revid'] = $r; + $rev['missing'] = ''; + $result[] = $rev; + } + + foreach ( $pageSet->getTitles() as $title ) { + $r = array(); + ApiQueryBase::addTitleInfo( $r, $title ); if ( !$title->exists() ) { $r['missing'] = ''; @@ -104,18 +119,15 @@ class ApiPurge extends ApiBase { } public function getAllowedParams() { - return array( - 'titles' => array( - ApiBase::PARAM_ISMULTI => true, - ApiBase::PARAM_REQUIRED => true - ), + $psModule = new ApiPageSet( $this ); + return $psModule->getAllowedParams() + array( 'forcelinkupdate' => false, ); } public function getParamDescription() { - return array( - 'titles' => 'A list of titles', + $psModule = new ApiPageSet( $this ); + return $psModule->getParamDescription() + array( 'forcelinkupdate' => 'Update the links tables', ); } @@ -127,9 +139,12 @@ class ApiPurge extends ApiBase { } public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'cantpurge' ), - ) ); + $psModule = new ApiPageSet( $this ); + return array_merge( + parent::getPossibleErrors(), + array( array( 'cantpurge' ), ), + $psModule->getPossibleErrors() + ); } public function getExamples() { diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index f70eca8cb3..4fe82de0cb 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -35,6 +35,11 @@ abstract class ApiQueryBase extends ApiBase { private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds; + /** + * @param $query ApiBase + * @param $moduleName string + * @param $paramPrefix string + */ public function __construct( ApiBase $query, $moduleName, $paramPrefix = '' ) { parent::__construct( $query->getMain(), $moduleName, $paramPrefix ); $this->mQueryModule = $query;