(bug 13390) Invalid title no longer kills an entire API query
authorRoan Kattouw <catrope@users.mediawiki.org>
Tue, 18 Mar 2008 15:17:24 +0000 (15:17 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Tue, 18 Mar 2008 15:17:24 +0000 (15:17 +0000)
RELEASE-NOTES
includes/api/ApiPageSet.php
includes/api/ApiQuery.php

index 86cc26c..756665a 100644 (file)
@@ -117,6 +117,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Introduced list=allimages
 * (bug 13371) Build page set from image hashes
 * Mark non-existent messages in meta=allmessages as missing
+* (bug 13390) One invalid title no longer kills an entire API query
 
 === Languages updated in 1.13 ===
 
index 12da5fa..24e9b2d 100644 (file)
@@ -42,8 +42,9 @@ if (!defined('MEDIAWIKI')) {
  */
 class ApiPageSet extends ApiQueryBase {
 
-       private $mAllPages; // [ns][dbkey] => page_id or 0 when missing
-       private $mTitles, $mGoodTitles, $mMissingTitles, $mMissingPageIDs, $mRedirectTitles;
+       private $mAllPages; // [ns][dbkey] => page_id or negative when missing
+       private $mTitles, $mGoodTitles, $mMissingTitles, $mInvalidTitles;
+       private $mMissingPageIDs, $mRedirectTitles;
        private $mNormalizedTitles, $mInterwikiTitles;
        private $mResolveRedirects, $mPendingRedirectIDs;
        private $mGoodRevIDs, $mMissingRevIDs;
@@ -58,6 +59,7 @@ class ApiPageSet extends ApiQueryBase {
                $this->mTitles = array();
                $this->mGoodTitles = array ();
                $this->mMissingTitles = array ();
+               $this->mInvalidTitles = array ();
                $this->mMissingPageIDs = array ();
                $this->mRedirectTitles = array ();
                $this->mNormalizedTitles = array ();
@@ -107,8 +109,9 @@ class ApiPageSet extends ApiQueryBase {
        }
 
        /**
-        * Returns an array [ns][dbkey] => page_id for all requested titles
-        * page_id is a unique negative number in case title was not found
+        * Returns an array [ns][dbkey] => page_id for all requested titles.
+        * page_id is a unique negative number in case title was not found.
+        * Invalid titles will also have negative page IDs and will be in namespace 0
         */
        public function getAllTitlesByNamespace() {
                return $this->mAllPages;
@@ -152,6 +155,15 @@ class ApiPageSet extends ApiQueryBase {
        public function getMissingTitles() {
                return $this->mMissingTitles;
        }
+       
+       /**
+        * Titles that were deemed invalid by Title::newFromText()
+        * The array's index will be unique and negative for each item
+        * @return array of strings (not Title objects)
+        */
+       public function getInvalidTitles() {
+               return $this->mInvalidTitles;
+       }
 
        /**
         * Page IDs that were not found in the database
@@ -580,8 +592,13 @@ class ApiPageSet extends ApiQueryBase {
                        
                        $titleObj = is_string($title) ? Title :: newFromText($title) : $title;
                        if (!$titleObj)
-                               $this->dieUsage("bad title", 'invalidtitle');
-
+                       {
+                               # Handle invalid titles gracefully
+                               $this->mAllpages[0][$title] = $this->mFakePageId;
+                               $this->mInvalidTitles[$this->mFakePageId] = $title;
+                               $this->mFakePageId--;
+                               continue; // There's nothing else we can do
+                       }
                        $iw = $titleObj->getInterwiki();
                        if (!empty($iw)) {
                                // This title is an interwiki link.
index 6775ddb..7cb4e83 100644 (file)
@@ -236,7 +236,7 @@ class ApiQuery extends ApiBase {
 
        /**
         * Appends an element for each page in the current pageSet with the most general
-        * information (id, title), plus any title normalizations and missing title/pageids/revids.
+        * information (id, title), plus any title normalizations and missing or invalid title/pageids/revids.
         */
        private function outputGeneralPageInfo() {
 
@@ -312,7 +312,9 @@ class ApiQuery extends ApiBase {
                        $vals['missing'] = '';
                        $pages[$fakeId] = $vals;
                }
-
+               // Report any invalid titles
+               foreach ($pageSet->getInvalidTitles() as $fakeId => $title)
+                       $pages[$fakeId] = array('title' => $title, 'invalid' => '');    
                // Report any missing page ids
                foreach ($pageSet->getMissingPageIDs() as $pageid) {
                        $pages[$pageid] = array (