Convert the title of an article to the preferred language variant.
authorZheng Zhu <zhengzhu@users.mediawiki.org>
Mon, 4 Oct 2004 03:47:39 +0000 (03:47 +0000)
committerZheng Zhu <zhengzhu@users.mediawiki.org>
Mon, 4 Oct 2004 03:47:39 +0000 (03:47 +0000)
includes/Parser.php
includes/Title.php
languages/Language.php
languages/LanguageZh.php

index 8e3e8a4..2395ace 100644 (file)
@@ -1160,7 +1160,30 @@ class Parser
                                $s .= $prefix . '[[' . $line;
                                continue;
                        }
-                       
+
+                       //check other language variants of the link
+                       //if the article does not exist
+                       if($nt->getArticleID() == 0) {
+                               global $wgContLang;
+                               $variants = $wgContLang->getVariants();
+                               $varnt = false; 
+                               if(sizeof($variants) > 1) {
+                                       foreach ( $variants as $v ) {
+                                               if($v == $wgContLang->getPreferredVariant())
+                                                       continue;
+                                               $varlink = $wgContLang->autoConvert($link, $v);
+                                               $varnt = Title::newFromText($varlink);
+                                               if($varnt && $varnt->getArticleID()>0) {
+                                                       break;
+                                               }
+                                       }
+                               }
+                               if($varnt && $varnt->getArticleID()>0) {
+                                       $nt = $varnt;
+                                       $link = $varlink;
+                               }
+                       }
+
                        $ns = $nt->getNamespace();
                        $iw = $nt->getInterWiki();
                        
index 350537b..c4d972c 100644 (file)
@@ -526,12 +526,15 @@ class Title {
         * @access public
         */
        function getPrefixedText() {
+               global $wgContLang;
                if ( empty( $this->mPrefixedText ) ) {
                        $s = $this->prefix( $this->mTextform );
                        $s = str_replace( '_', ' ', $s );
                        $this->mPrefixedText = $s;
                }
-               return $this->mPrefixedText;
+               //convert to the desired language variant
+               $t = $wgContLang->convert($this->mPrefixedText);
+               return $t;
        }
        
        /**
@@ -542,11 +545,14 @@ class Title {
         * @access public
         */
        function getFullText() {
+               global $wgContLang;
                $text = $this->getPrefixedText();
                if( '' != $this->mFragment ) {
                        $text .= '#' . $this->mFragment;
                }
-               return $text;
+               //convert to desired language variant
+               $t = $wgContLang->convert($text);
+               return $t;
        }
 
        /**
index c6c7267..d0ee9cd 100644 (file)
@@ -2096,7 +2096,7 @@ class Language {
        /* this does the real conversion to the preferred variant.
           see LanguageZh.php for example
        */
-       function autoConvert($text) {
+       function autoConvert($text, $toVariant=false) {
                return $text;
        }
        
index f7b3b3e..c98255c 100644 (file)
@@ -63,14 +63,17 @@ class LanguageZh extends LanguageZh_cn {
                return strtr($text, $zhTrad2Simp);
        }
        
-       function autoConvert($text) {
-        if($this->getPreferredVariant() == "zh-cn") {
-            return $this->trad2simp($text);
-        }
-        else {
-            return $this->simp2trad($text);
-        }
-    }
+       function autoConvert($text, $toVariant=false) {
+               if(!$toVariant) 
+                       $toVariant = $this->getPreferredVariant();
+
+               if($toVariant == "zh-cn") {
+                       return $this->trad2simp($text);
+               }
+               else {
+                       return $this->simp2trad($text);
+               }
+       }
 
     function getVariants() {
         return array("zh-cn", "zh-tw");