r105828 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105827‎ | r105828 | r105829 >
Date:20:43, 11 December 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (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!
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/api/ApiPurge.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -205,6 +205,7 @@
206206 many types.
207207 * (bug 32415) Empty page get no size attribute in API output.
208208 * (bug 31759) Undefined property notice in querypages API.
 209+* (bug 32495) API should allow purge by pageids.
209210
210211 === Languages updated in 1.19 ===
211212
Index: trunk/phase3/includes/api/ApiPurge.php
@@ -47,17 +47,32 @@
4848 }
4949
5050 $forceLinkUpdate = $params['forcelinkupdate'];
 51+ $pageSet = new ApiPageSet( $this );
 52+ $pageSet->execute();
5153
5254 $result = array();
53 - foreach ( $params['titles'] as $t ) {
 55+ foreach( $pageSet->getInvalidTitles() as $title ) {
5456 $r = array();
55 - $title = Title::newFromText( $t );
56 - if ( !$title instanceof Title ) {
57 - $r['title'] = $t;
58 - $r['invalid'] = '';
59 - $result[] = $r;
60 - continue;
61 - }
 57+ $r['title'] = $title;
 58+ $r['invalid'] = '';
 59+ $result[] = $r;
 60+ }
 61+ foreach( $pageSet->getMissingPageIDs() as $p ) {
 62+ $page = array();
 63+ $page['pageid'] = $p;
 64+ $page['missing'] = '';
 65+ $result[] = $page;
 66+ }
 67+ foreach( $pageSet->getMissingPageIDs() as $r ) {
 68+ $rev = array();
 69+ $rev['revid'] = $r;
 70+ $rev['missing'] = '';
 71+ $result[] = $rev;
 72+ }
 73+
 74+ foreach ( $pageSet->getTitles() as $title ) {
 75+ $r = array();
 76+
6277 ApiQueryBase::addTitleInfo( $r, $title );
6378 if ( !$title->exists() ) {
6479 $r['missing'] = '';
@@ -104,18 +119,15 @@
105120 }
106121
107122 public function getAllowedParams() {
108 - return array(
109 - 'titles' => array(
110 - ApiBase::PARAM_ISMULTI => true,
111 - ApiBase::PARAM_REQUIRED => true
112 - ),
 123+ $psModule = new ApiPageSet( $this );
 124+ return $psModule->getAllowedParams() + array(
113125 'forcelinkupdate' => false,
114126 );
115127 }
116128
117129 public function getParamDescription() {
118 - return array(
119 - 'titles' => 'A list of titles',
 130+ $psModule = new ApiPageSet( $this );
 131+ return $psModule->getParamDescription() + array(
120132 'forcelinkupdate' => 'Update the links tables',
121133 );
122134 }
@@ -127,9 +139,12 @@
128140 }
129141
130142 public function getPossibleErrors() {
131 - return array_merge( parent::getPossibleErrors(), array(
132 - array( 'cantpurge' ),
133 - ) );
 143+ $psModule = new ApiPageSet( $this );
 144+ return array_merge(
 145+ parent::getPossibleErrors(),
 146+ array( array( 'cantpurge' ), ),
 147+ $psModule->getPossibleErrors()
 148+ );
134149 }
135150
136151 public function getExamples() {
Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -35,6 +35,11 @@
3636
3737 private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds;
3838
 39+ /**
 40+ * @param $query ApiBase
 41+ * @param $moduleName string
 42+ * @param $paramPrefix string
 43+ */
3944 public function __construct( ApiBase $query, $moduleName, $paramPrefix = '' ) {
4045 parent::__construct( $query->getMain(), $moduleName, $paramPrefix );
4146 $this->mQueryModule = $query;

Follow-up revisions

RevisionCommit summaryAuthorDate
r105833Attempt to fix tests broken by r105828...reedy21:49, 11 December 2011
r105834Mark testPurgeMainPage broken after r105828 and r105833...reedy22:39, 11 December 2011
r106339Use a revision return method for revisions, follows up r105828reedy17:21, 15 December 2011

Comments

#Comment by Catrope (talk | contribs)   16:44, 15 December 2011
+		foreach( $pageSet->getMissingPageIDs() as $r ) {

Should be MissingRevIDs().

OK otherwise.

Status & tagging log