API: fixed bug 10147 Silent normalization of interwiki titles
authorYuri Astrakhan <yurik@users.mediawiki.org>
Thu, 14 Jun 2007 03:14:44 +0000 (03:14 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Thu, 14 Jun 2007 03:14:44 +0000 (03:14 +0000)
RELEASE-NOTES
includes/api/ApiPageSet.php
includes/api/ApiQuery.php

index 223f155..12e3753 100644 (file)
@@ -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 ==
 
index de1d2de..29eae8d 100644 (file)
@@ -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
index ee44d40..befa075 100644 (file)
@@ -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) {