$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();
* @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;
}
/**
* @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;
}
/**
/* this does the real conversion to the preferred variant.
see LanguageZh.php for example
*/
- function autoConvert($text) {
+ function autoConvert($text, $toVariant=false) {
return $text;
}
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");