From bfc27da4c482af8473a18ad9bb2cfa7e90ee51ac Mon Sep 17 00:00:00 2001 From: Zheng Zhu Date: Mon, 4 Oct 2004 03:47:39 +0000 Subject: [PATCH] Convert the title of an article to the preferred language variant. --- includes/Parser.php | 25 ++++++++++++++++++++++++- includes/Title.php | 10 ++++++++-- languages/Language.php | 2 +- languages/LanguageZh.php | 19 +++++++++++-------- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 8e3e8a4263..2395ace96e 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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(); diff --git a/includes/Title.php b/includes/Title.php index 350537bad7..c4d972ceb2 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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; } /** diff --git a/languages/Language.php b/languages/Language.php index c6c7267380..d0ee9cd733 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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; } diff --git a/languages/LanguageZh.php b/languages/LanguageZh.php index f7b3b3ea2e..c98255c118 100644 --- a/languages/LanguageZh.php +++ b/languages/LanguageZh.php @@ -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"); -- 2.20.1