From 15ae5ecbf4182d3f43b62ce7f8dbff57944f94b8 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 14 Jun 2007 03:14:44 +0000 Subject: [PATCH] API: fixed bug 10147 Silent normalization of interwiki titles --- RELEASE-NOTES | 2 ++ includes/api/ApiPageSet.php | 34 ++++++++++++++++++++++++++-------- includes/api/ApiQuery.php | 14 ++++++++++++++ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 223f155b46..12e3753c0c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -198,6 +198,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN not exist * (bug 9121) Introduced indexpageids query parameter to list the page_id values of all returned page items +* (bug 10147) Now interwiki titles are not processed but added to a separate + "interwiki" section of the output. == Maintenance script changes since 1.10 == diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index de1d2de8dd..29eae8dca2 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -43,7 +43,7 @@ if (!defined('MEDIAWIKI')) { class ApiPageSet extends ApiQueryBase { private $mAllPages; // [ns][dbkey] => page_id or 0 when missing - private $mTitles, $mGoodTitles, $mMissingTitles, $mMissingPageIDs, $mRedirectTitles, $mNormalizedTitles; + private $mTitles, $mGoodTitles, $mMissingTitles, $mMissingPageIDs, $mRedirectTitles, $mNormalizedTitles, $mInterwikiTitles; private $mResolveRedirects, $mPendingRedirectIDs; private $mGoodRevIDs, $mMissingRevIDs; @@ -59,6 +59,7 @@ class ApiPageSet extends ApiQueryBase { $this->mMissingPageIDs = array (); $this->mRedirectTitles = array (); $this->mNormalizedTitles = array (); + $this->mInterwikiTitles = array (); $this->mGoodRevIDs = array(); $this->mMissingRevIDs = array(); @@ -164,6 +165,15 @@ class ApiPageSet extends ApiQueryBase { return $this->mNormalizedTitles; } + /** + * Get a list of interwiki titles - maps the title given + * with to the interwiki prefix. + * @return array raw_prefixed_title (string) => interwiki_prefix (string) + */ + public function getInterwikiTitles() { + return $this->mInterwikiTitles; + } + /** * Get the list of revision IDs (requested with revids= parameter) * @return array revID (int) => pageID (int) @@ -546,6 +556,7 @@ class ApiPageSet extends ApiQueryBase { /** * Given an array of title strings, convert them into Title objects. + * Alternativelly, an array of Title objects may be given. * This method validates access rights for the title, * and appends normalization values to the output. * @@ -558,17 +569,24 @@ class ApiPageSet extends ApiQueryBase { foreach ($titles as $title) { $titleObj = is_string($title) ? Title :: newFromText($title) : $title; - - // Validation if (!$titleObj) $this->dieUsage("bad title $titleString", 'invalidtitle'); - if ($titleObj->getNamespace() < 0) - $this->dieUsage("No support for special page $titleString has been implemented", 'unsupportednamespace'); - if (!$titleObj->userCanRead()) - $this->dieUsage("No read permission for $titleString", 'titleaccessdenied'); - $linkBatch->addObj($titleObj); + $iw = $titleObj->getInterwiki(); + if (!empty($iw)) { + // This title is an interwiki link. + $this->mInterwikiTitles[$titleObj->getPrefixedText()] = $iw; + } else { + + // Validation + if ($titleObj->getNamespace() < 0) + $this->dieUsage("No support for special page $titleString has been implemented", 'unsupportednamespace'); + if (!$titleObj->userCanRead()) + $this->dieUsage("No read permission for $titleString", 'titleaccessdenied'); + $linkBatch->addObj($titleObj); + } + // Make sure we remember the original title that was given to us // This way the caller can correlate new titles with the originally requested, // i.e. namespace is localized or capitalization is different diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index ee44d406ae..befa075728 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -243,7 +243,21 @@ class ApiQuery extends ApiBase { $result->setIndexedTagName($normValues, 'n'); $result->addValue('query', 'normalized', $normValues); } + + // Interwiki titles + $intrwValues = array (); + foreach ($pageSet->getInterwikiTitles() as $rawTitleStr => $interwikiStr) { + $intrwValues[] = array ( + 'title' => $rawTitleStr, + 'iw' => $interwikiStr + ); + } + if (!empty ($intrwValues)) { + $result->setIndexedTagName($intrwValues, 'i'); + $result->addValue('query', 'interwiki', $intrwValues); + } + // Show redirect information $redirValues = array (); foreach ($pageSet->getRedirectTitles() as $titleStrFrom => $titleStrTo) { -- 2.20.1