From: Roan Kattouw Date: Tue, 18 Mar 2008 15:17:24 +0000 (+0000) Subject: (bug 13390) Invalid title no longer kills an entire API query X-Git-Tag: 1.31.0-rc.0~49022 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=16c85524378da888abf3fc380d9ab28c52876404;p=lhc%2Fweb%2Fwiklou.git (bug 13390) Invalid title no longer kills an entire API query --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 86cc26cc9e..756665ad3e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 12da5fa4f5..24e9b2d2f1 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -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. diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 6775ddbdf6..7cb4e830c7 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -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 (