Added option wgDisableLangConversion to disable langauge variant conversion, mainly...
authorZheng Zhu <zhengzhu@users.mediawiki.org>
Tue, 19 Oct 2004 18:02:44 +0000 (18:02 +0000)
committerZheng Zhu <zhengzhu@users.mediawiki.org>
Tue, 19 Oct 2004 18:02:44 +0000 (18:02 +0000)
includes/DefaultSettings.php
includes/Parser.php
includes/SpecialPreferences.php
includes/SpecialSitesettings.php
languages/Language.php
languages/LanguageLatin1.php
languages/LanguageZh.php

index a6bb741..1aa0139 100644 (file)
@@ -313,6 +313,13 @@ $wgTranslateNumerals = true; # For Hindi and Arabic use local numerals instead
 $wgUseDatabaseMessages = true;
 $wgMsgCacheExpiry      = 86400;
 $wgPartialMessageCache = false;
+
+# Whether to enable language variant conversion. Currently only zh 
+# supports this function, to convert between Traditional and Simplified
+# Chinese. This flag is meant to isolate the (untested) conversion 
+# code, so that if it breaks, only zh will be affected
+$wgDisableLangConversion = true;
+
 # Miscellaneous configuration settings
 #
 
index f97bffc..0983b53 100644 (file)
@@ -1093,6 +1093,7 @@ class Parser
 
        function replaceInternalLinks( $s ) {
                global $wgLang, $wgContLang, $wgLinkCache;
+               global $wgDisableLangConversion;
                static $fname = 'Parser::replaceInternalLinks' ;
                # use a counter to prevent too much unknown links from
                # being checked for different language variants.
@@ -1204,31 +1205,32 @@ class Parser
                                continue;
                        }
 
-                       //check other language variants of the link
-                       //if the article does not exist
-                       global $wgContLang;
-                       $variants = $wgContLang->getVariants();
-
-                       if(sizeof($variants) > 1 && $convertCount < 200) {
-                               $varnt = false; 
-                               if($nt->getArticleID() == 0) {
-                                       foreach ( $variants as $v ) {
-                                               if($v == $wgContLang->getPreferredVariant())
-                                                       continue;
-                                               $convertCount ++;
-                                               $varlink = $wgContLang->autoConvert($link, $v);
-                                               $varnt = Title::newFromText($varlink);
-                                               if($varnt && $varnt->getArticleID()>0) {
-                                                       break;
+                       #check other language variants of the link
+                       #if the article does not exist
+                       if(!$wgDisableLangConversion) {
+                               global $wgContLang;
+                               $variants = $wgContLang->getVariants();
+
+                               if(sizeof($variants) > 1 && $convertCount < 200) {
+                                       $varnt = false; 
+                                       if($nt->getArticleID() == 0) {
+                                               foreach ( $variants as $v ) {
+                                                       if($v == $wgContLang->getPreferredVariant())
+                                                               continue;
+                                                       $convertCount ++;
+                                                       $varlink = $wgContLang->autoConvert($link, $v);
+                                                       $varnt = Title::newFromText($varlink);
+                                                       if($varnt && $varnt->getArticleID()>0) {
+                                                               break;
+                                                       }
                                                }
                                        }
-                               }
-                               if($varnt && $varnt->getArticleID()>0) {
-                                       $nt = $varnt;
-                                       $link = $varlink;
+                                       if($varnt && $varnt->getArticleID()>0) {
+                                               $nt = $varnt;
+                                               $link = $varlink;
+                                       }
                                }
                        }
-
                        $ns = $nt->getNamespace();
                        $iw = $nt->getInterWiki();
                        
index 8934793..4e2fea7 100644 (file)
@@ -312,7 +312,7 @@ class PreferencesForm {
        function mainPrefsForm( $err ) {
                global $wgUser, $wgOut, $wgLang, $wgContLang, $wgUseDynamicDates, $wgValidSkinNames;
                global $wgAllowRealName, $wgImageLimits;
-               global $wgLanguageNames;
+               global $wgLanguageNames, $wgDisableLangConversion;
 
                $wgOut->setPageTitle( wfMsg( 'preferences' ) );
                $wgOut->setArticleRelated( false );
@@ -406,28 +406,28 @@ class PreferencesForm {
                $wgOut->addHtml("</select></label></div>\n" );
 
                /* see if there are multiple language variants to choose from*/
-               $variants = $wgContLang->getVariants();
-               $size=sizeof($variants);
+               if(!$wgDisableLangConversion) {
+                       $variants = $wgContLang->getVariants();
+                       $size=sizeof($variants);
                
-               $variantArray=array();
-               foreach($variants as $v) {
-                       $v = str_replace( '_', '-', strtolower($v));
-                       if($name=$wgLanguageNames[$v]) {
-                               $variantArray[$v] = $name;
+                       $variantArray=array();
+                       foreach($variants as $v) {
+                               $v = str_replace( '_', '-', strtolower($v));
+                               if($name=$wgLanguageNames[$v]) {
+                                       $variantArray[$v] = $name;
+                               }
                        }
-               }
-               $size=sizeof($variantArray);
+                       $size=sizeof($variantArray);
                
-               if(sizeof($variantArray) > 1) {
+                       if(sizeof($variantArray) > 1) {
                        $wgOut->addHtml("
                                <div><label>$yv: <select name=\"wpUserVariant\">\n");
-                       foreach($variantArray as $code => $name) {
-                               $sel = ($code==$this->mUserVariant)? 'selected="selected"' : '';
-                               $wgOut->addHtml("\t<option value=\"$code\" $sel>$code - $name</option>\n");
+                               foreach($variantArray as $code => $name) {
+                                       $sel = ($code==$this->mUserVariant)? 'selected="selected"' : '';
+                                       $wgOut->addHtml("\t<option value=\"$code\" $sel>$code - $name</option>\n");
+                               }
                        }
-                       $wgOut->addHtml("</select></label></div>\n");
                }
-
                # Fields for changing password
                #
                $this->mOldpass = htmlspecialchars( $this->mOldpass );
index a47751a..51eeaee 100644 (file)
@@ -62,6 +62,7 @@ class SiteSettingsForm extends HTMLForm {
                        $this->checkbox( 'wgUseDatabaseMessages' ) .
                        $this->checkbox( 'wgUseCategoryMagic' ) .
                        $this->checkbox( 'wgUseCategoryBrowser' ) .
+                       $this->checkbox( 'wgDisableLangConversion' ).
                        $this->textbox( 'wgHitcounterUpdateFreq' ) .
                        $this->textbox( 'wgExtraSubtitle' ).
                        $this->textbox( 'wgSiteSupportPage' ) .
index 8b6ff6f..783e223 100644 (file)
@@ -2050,10 +2050,15 @@ class Language {
        # syntax of the markup:
        # -{code1:text1;code2:text2;...}-  or
        # -{text}- in which case no conversion should take place for text
-       function convert( $text ) {
-
+       function convert( $text , $isTitle=false) {
+               global $wgDisableLangConversion;
+               if($wgDisableLangConversion)
+                       return $text; 
                if(sizeof($this->getVariants())<2) 
                        return $text;
+               
+               if($isTitle)
+                       return $this->convertTitle($text);
 
                // no conversion if redirecting
                if(substr($text,0,9) == "#REDIRECT") {
@@ -2114,7 +2119,13 @@ class Language {
        function autoConvert($text, $toVariant=false) {
                return $text;
        }
-       
+
+       /* hook for converting the title, which may needs special treatment
+       */
+       function convertTitle($text) {
+               return $text;
+       }
+
        # returns a list of language variants for conversion.
        # right now mainly used in the Chinese conversion
        function getVariants() {
index ce4a4a3..d66d215 100644 (file)
@@ -260,13 +260,20 @@ class LanguageLatin1 {
                return $this->lang->getPreferredVariant();
        }
 
-       function convert( $text ) {
-               return utf8_decode( $this->lang->convert( utf8_encode( $text ) ) );
+       function convert( $text, $isTitle=false ) {
+               return utf8_decode( $this->lang->convert( utf8_encode( $text ), $isTitle ) );
        }
        
        function autoConvert($text, $toVariant=false) {
                return utf8_decode( $this->lang->autoConvert( utf8_encode( $text ), $toVariant ) );
        }
+
+       /* hook for converting the title, which may needs special treatment
+       */
+       function convertTitle($text) {
+               return utf8_decode( $this->lang->convertTitle( utf8_encode( $text ) ) );
+       }
+
        
        function getVariants() {
                return $this->lang->getVariants();
index 738329d..a6392e5 100644 (file)
@@ -102,6 +102,18 @@ class LanguageZh extends LanguageZh_cn {
                return $t;
        }
 
+       # only convert titles having more than one character
+       function convertTitle($text) {
+               $len=0;
+               if( function_exists( 'mb_strlen' ) )
+                       $len = mb_strlen($text);
+               else
+                       $len = strlen($text)/3;
+               if($len>1)
+                       return $this->autoConvert( $text);
+               return $text;
+       }
+
        function getVariants() {
                return array("zh-cn", "zh-tw", "zh-sg", "zh-hk");
        }