* API: Added revids parameter.
authorYuri Astrakhan <yurik@users.mediawiki.org>
Fri, 13 Oct 2006 04:59:14 +0000 (04:59 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Fri, 13 Oct 2006 04:59:14 +0000 (04:59 +0000)
includes/api/ApiMain.php
includes/api/ApiPageSet.php
includes/api/ApiQuery.php
includes/api/ApiQueryRevisions.php

index 8394991..0b3f6ab 100644 (file)
@@ -227,7 +227,7 @@ class ApiMain extends ApiBase {
                 if ( is_a( $e, 'MWException' ) ) {
                         try {
                                $msg = "Exception Caught: {$e->getMessage()}";
-                               $this->makeErrorMessage($msg, 'internal_error', "\n\n{$e->getTraceAsString()}\n\n");
+                               $this->makeErrorMessage($msg, 'internal_api_error', "\n\n{$e->getTraceAsString()}\n\n");
                                $this->printError();
                         } catch (Exception $e2) {
                  echo $e->__toString();
index 2d4d2cd..7f3cdc9 100644 (file)
@@ -34,6 +34,7 @@ class ApiPageSet extends ApiQueryBase {
        private $mAllPages; // [ns][dbkey] => page_id or 0 when missing
        private $mGoodTitles, $mMissingTitles, $mMissingPageIDs, $mRedirectTitles, $mNormalizedTitles;
        private $mResolveRedirects, $mPendingRedirectIDs;
+       private $mGoodRevIDs, $mMissingRevIDs;
 
        private $mRequestedPageFields;
 
@@ -46,6 +47,8 @@ class ApiPageSet extends ApiQueryBase {
                $this->mMissingPageIDs = array ();
                $this->mRedirectTitles = array ();
                $this->mNormalizedTitles = array ();
+               $this->mGoodRevIDs = array();
+               $this->mMissingRevIDs = array();
 
                $this->mRequestedPageFields = array ();
                $this->mResolveRedirects = $resolveRedirects;
@@ -135,16 +138,25 @@ class ApiPageSet extends ApiQueryBase {
 
        /**
         * Get the list of revision IDs (requested with revids= parameter)
+        * @return array revID (int) => pageID (int)
         */
        public function getRevisionIDs() {
-               $this->dieUsage(__METHOD__ . ' is not implemented', 'notimplemented');
+               return $this->mGoodRevIDs;
+       }
+
+       /**
+        * Revision IDs that were not found in the database
+        * @return array of revision IDs
+        */
+       public function getMissingRevisionIDs() {
+               return $this->mMissingRevIDs;
        }
 
        /**
         * Returns the number of revisions (requested with revids= parameter)
         */
        public function getRevisionCount() {
-               return 0; // TODO: implement
+               return count($this->getRevisionIDs());
        }
 
        /**
@@ -178,6 +190,8 @@ class ApiPageSet extends ApiQueryBase {
                                $this->initFromPageIds($pageids);
                                break;
                        case 'revids' :
+                               if($this->mResolveRedirects)
+                                       $this->dieUsage('revids may not be used with redirect resolution', 'params');
                                $this->initFromRevIDs($revids);
                                break;
                        default :
@@ -348,7 +362,36 @@ class ApiPageSet extends ApiQueryBase {
        }
 
        private function initFromRevIDs($revids) {
-               $this->dieUsage(__METHOD__ . ' is not implemented', 'notimplemented');
+
+               $db = $this->getDB();
+               $pageids = array();
+               $remaining = array_flip($revids);
+               
+               $tables = array('page', 'revision');
+               $fields = array('rev_id','rev_page');
+               $where = array( 'rev_deleted' => 0, 'rev_id' => $revids );
+               
+               // Get pageIDs data from the `page` table
+               $this->profileDBIn();
+               $res = $db->select( $tables, $fields, $where,  __METHOD__ );
+               while ( $row = $db->fetchObject( $res ) ) {
+                       $revid = intval($row->rev_id);
+                       $pageid = intval($row->rev_page);
+                       $this->mGoodRevIDs[$revid] = $pageid;
+                       $pageids[$pageid] = '';
+                       unset($remaining[$revid]);
+               }
+               $db->freeResult( $res );
+               $this->profileDBOut();
+
+               $this->mMissingRevIDs = array_keys($remaining);
+
+               // Populate all the page information
+               if($this->mResolveRedirects)
+                       $this->dieDebug('revids may not be used with redirect resolution');
+               $pageids = array_keys($pageids);
+               if(!empty($pageids))
+                       $this->initFromPageIds($pageids);
        }
 
        private function resolvePendingRedirects() {
index ea6d359..45848b2 100644 (file)
@@ -195,6 +195,22 @@ class ApiQuery extends ApiBase {
                        $this->getResult()->addValue('query', 'redirects', $redirValues);
                }
 
+
+               //
+               // Missing revision elements
+               //
+               $missingRevIDs = $pageSet->getMissingRevisionIDs();
+               if (!empty($missingRevIDs)) {
+                       $revids = array();
+                       foreach ($missingRevIDs as $revid) {
+                               $revids[$revid] = array (
+                                       'revid' => $revid
+                               );
+                       }
+                       ApiResult :: setIndexedTagName($revids, 'rev');
+                       $this->getResult()->addValue('query', 'badrevids', $revids);
+               }
+               
                //
                // Page elements
                //
index 65e25b6..a059ffc 100644 (file)
@@ -58,13 +58,10 @@ class ApiQueryRevisions extends ApiQueryBase {
                if ($revCount === 0 && $pageCount === 0)
                        return;
 
-               if ($revCount > 0 && $pageCount > 0)
-                       $this->dieUsage('The revids= parameter may not be used with titles, pageids, or generator options.', 'revids');
-
                if ($revCount > 0 && $enumRevMode)
                        $this->dieUsage('The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids');
 
-               if ($revCount === 0 && $pageCount > 1 && $enumRevMode)
+               if ($pageCount > 1 && $enumRevMode)
                        $this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, start, and end parameters may only be used on a single page.', 'multpages');
 
                $tables = array (