* (bug 32495) API should allow purge by pageids.
authorSam Reed <reedy@users.mediawiki.org>
Sun, 11 Dec 2011 20:43:42 +0000 (20:43 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 11 Dec 2011 20:43:42 +0000 (20:43 +0000)
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!

RELEASE-NOTES-1.19
includes/api/ApiPurge.php
includes/api/ApiQueryBase.php

index 2929f78..86b61c3 100644 (file)
@@ -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 ===
 
index f0ae64e..ceee00a 100644 (file)
@@ -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() {
index f70eca8..4fe82de 100644 (file)
@@ -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;