| Index: trunk/phase3/includes/SpecialPreferences.php |
| — | — | @@ -312,7 +312,7 @@ |
| 313 | 313 | function mainPrefsForm( $err ) { |
| 314 | 314 | global $wgUser, $wgOut, $wgLang, $wgContLang, $wgUseDynamicDates, $wgValidSkinNames; |
| 315 | 315 | global $wgAllowRealName, $wgImageLimits; |
| 316 | | - global $wgLanguageNames; |
| | 316 | + global $wgLanguageNames, $wgDisableLangConversion; |
| 317 | 317 | |
| 318 | 318 | $wgOut->setPageTitle( wfMsg( 'preferences' ) ); |
| 319 | 319 | $wgOut->setArticleRelated( false ); |
| — | — | @@ -406,28 +406,28 @@ |
| 407 | 407 | $wgOut->addHtml("</select></label></div>\n" ); |
| 408 | 408 | |
| 409 | 409 | /* see if there are multiple language variants to choose from*/ |
| 410 | | - $variants = $wgContLang->getVariants(); |
| 411 | | - $size=sizeof($variants); |
| | 410 | + if(!$wgDisableLangConversion) { |
| | 411 | + $variants = $wgContLang->getVariants(); |
| | 412 | + $size=sizeof($variants); |
| 412 | 413 | |
| 413 | | - $variantArray=array(); |
| 414 | | - foreach($variants as $v) { |
| 415 | | - $v = str_replace( '_', '-', strtolower($v)); |
| 416 | | - if($name=$wgLanguageNames[$v]) { |
| 417 | | - $variantArray[$v] = $name; |
| | 414 | + $variantArray=array(); |
| | 415 | + foreach($variants as $v) { |
| | 416 | + $v = str_replace( '_', '-', strtolower($v)); |
| | 417 | + if($name=$wgLanguageNames[$v]) { |
| | 418 | + $variantArray[$v] = $name; |
| | 419 | + } |
| 418 | 420 | } |
| 419 | | - } |
| 420 | | - $size=sizeof($variantArray); |
| | 421 | + $size=sizeof($variantArray); |
| 421 | 422 | |
| 422 | | - if(sizeof($variantArray) > 1) { |
| | 423 | + if(sizeof($variantArray) > 1) { |
| 423 | 424 | $wgOut->addHtml(" |
| 424 | 425 | <div><label>$yv: <select name=\"wpUserVariant\">\n"); |
| 425 | | - foreach($variantArray as $code => $name) { |
| 426 | | - $sel = ($code==$this->mUserVariant)? 'selected="selected"' : ''; |
| 427 | | - $wgOut->addHtml("\t<option value=\"$code\" $sel>$code - $name</option>\n"); |
| | 426 | + foreach($variantArray as $code => $name) { |
| | 427 | + $sel = ($code==$this->mUserVariant)? 'selected="selected"' : ''; |
| | 428 | + $wgOut->addHtml("\t<option value=\"$code\" $sel>$code - $name</option>\n"); |
| | 429 | + } |
| 428 | 430 | } |
| 429 | | - $wgOut->addHtml("</select></label></div>\n"); |
| 430 | 431 | } |
| 431 | | - |
| 432 | 432 | # Fields for changing password |
| 433 | 433 | # |
| 434 | 434 | $this->mOldpass = htmlspecialchars( $this->mOldpass ); |
| Index: trunk/phase3/includes/DefaultSettings.php |
| — | — | @@ -313,6 +313,13 @@ |
| 314 | 314 | $wgUseDatabaseMessages = true; |
| 315 | 315 | $wgMsgCacheExpiry = 86400; |
| 316 | 316 | $wgPartialMessageCache = false; |
| | 317 | + |
| | 318 | +# Whether to enable language variant conversion. Currently only zh |
| | 319 | +# supports this function, to convert between Traditional and Simplified |
| | 320 | +# Chinese. This flag is meant to isolate the (untested) conversion |
| | 321 | +# code, so that if it breaks, only zh will be affected |
| | 322 | +$wgDisableLangConversion = true; |
| | 323 | + |
| 317 | 324 | # Miscellaneous configuration settings |
| 318 | 325 | # |
| 319 | 326 | |
| Index: trunk/phase3/includes/SpecialSitesettings.php |
| — | — | @@ -62,6 +62,7 @@ |
| 63 | 63 | $this->checkbox( 'wgUseDatabaseMessages' ) . |
| 64 | 64 | $this->checkbox( 'wgUseCategoryMagic' ) . |
| 65 | 65 | $this->checkbox( 'wgUseCategoryBrowser' ) . |
| | 66 | + $this->checkbox( 'wgDisableLangConversion' ). |
| 66 | 67 | $this->textbox( 'wgHitcounterUpdateFreq' ) . |
| 67 | 68 | $this->textbox( 'wgExtraSubtitle' ). |
| 68 | 69 | $this->textbox( 'wgSiteSupportPage' ) . |
| Index: trunk/phase3/includes/Parser.php |
| — | — | @@ -1093,6 +1093,7 @@ |
| 1094 | 1094 | |
| 1095 | 1095 | function replaceInternalLinks( $s ) { |
| 1096 | 1096 | global $wgLang, $wgContLang, $wgLinkCache; |
| | 1097 | + global $wgDisableLangConversion; |
| 1097 | 1098 | static $fname = 'Parser::replaceInternalLinks' ; |
| 1098 | 1099 | # use a counter to prevent too much unknown links from |
| 1099 | 1100 | # being checked for different language variants. |
| — | — | @@ -1204,31 +1205,32 @@ |
| 1205 | 1206 | continue; |
| 1206 | 1207 | } |
| 1207 | 1208 | |
| 1208 | | - //check other language variants of the link |
| 1209 | | - //if the article does not exist |
| 1210 | | - global $wgContLang; |
| 1211 | | - $variants = $wgContLang->getVariants(); |
| | 1209 | + #check other language variants of the link |
| | 1210 | + #if the article does not exist |
| | 1211 | + if(!$wgDisableLangConversion) { |
| | 1212 | + global $wgContLang; |
| | 1213 | + $variants = $wgContLang->getVariants(); |
| 1212 | 1214 | |
| 1213 | | - if(sizeof($variants) > 1 && $convertCount < 200) { |
| 1214 | | - $varnt = false; |
| 1215 | | - if($nt->getArticleID() == 0) { |
| 1216 | | - foreach ( $variants as $v ) { |
| 1217 | | - if($v == $wgContLang->getPreferredVariant()) |
| 1218 | | - continue; |
| 1219 | | - $convertCount ++; |
| 1220 | | - $varlink = $wgContLang->autoConvert($link, $v); |
| 1221 | | - $varnt = Title::newFromText($varlink); |
| 1222 | | - if($varnt && $varnt->getArticleID()>0) { |
| 1223 | | - break; |
| | 1215 | + if(sizeof($variants) > 1 && $convertCount < 200) { |
| | 1216 | + $varnt = false; |
| | 1217 | + if($nt->getArticleID() == 0) { |
| | 1218 | + foreach ( $variants as $v ) { |
| | 1219 | + if($v == $wgContLang->getPreferredVariant()) |
| | 1220 | + continue; |
| | 1221 | + $convertCount ++; |
| | 1222 | + $varlink = $wgContLang->autoConvert($link, $v); |
| | 1223 | + $varnt = Title::newFromText($varlink); |
| | 1224 | + if($varnt && $varnt->getArticleID()>0) { |
| | 1225 | + break; |
| | 1226 | + } |
| 1224 | 1227 | } |
| 1225 | 1228 | } |
| | 1229 | + if($varnt && $varnt->getArticleID()>0) { |
| | 1230 | + $nt = $varnt; |
| | 1231 | + $link = $varlink; |
| | 1232 | + } |
| 1226 | 1233 | } |
| 1227 | | - if($varnt && $varnt->getArticleID()>0) { |
| 1228 | | - $nt = $varnt; |
| 1229 | | - $link = $varlink; |
| 1230 | | - } |
| 1231 | 1234 | } |
| 1232 | | - |
| 1233 | 1235 | $ns = $nt->getNamespace(); |
| 1234 | 1236 | $iw = $nt->getInterWiki(); |
| 1235 | 1237 | |
| Index: trunk/phase3/languages/LanguageLatin1.php |
| — | — | @@ -260,13 +260,20 @@ |
| 261 | 261 | return $this->lang->getPreferredVariant(); |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | | - function convert( $text ) { |
| 265 | | - return utf8_decode( $this->lang->convert( utf8_encode( $text ) ) ); |
| | 264 | + function convert( $text, $isTitle=false ) { |
| | 265 | + return utf8_decode( $this->lang->convert( utf8_encode( $text ), $isTitle ) ); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | function autoConvert($text, $toVariant=false) { |
| 269 | 269 | return utf8_decode( $this->lang->autoConvert( utf8_encode( $text ), $toVariant ) ); |
| 270 | 270 | } |
| | 271 | + |
| | 272 | + /* hook for converting the title, which may needs special treatment |
| | 273 | + */ |
| | 274 | + function convertTitle($text) { |
| | 275 | + return utf8_decode( $this->lang->convertTitle( utf8_encode( $text ) ) ); |
| | 276 | + } |
| | 277 | + |
| 271 | 278 | |
| 272 | 279 | function getVariants() { |
| 273 | 280 | return $this->lang->getVariants(); |
| Index: trunk/phase3/languages/Language.php |
| — | — | @@ -2050,10 +2050,15 @@ |
| 2051 | 2051 | # syntax of the markup: |
| 2052 | 2052 | # -{code1:text1;code2:text2;...}- or |
| 2053 | 2053 | # -{text}- in which case no conversion should take place for text |
| 2054 | | - function convert( $text ) { |
| 2055 | | - |
| | 2054 | + function convert( $text , $isTitle=false) { |
| | 2055 | + global $wgDisableLangConversion; |
| | 2056 | + if($wgDisableLangConversion) |
| | 2057 | + return $text; |
| 2056 | 2058 | if(sizeof($this->getVariants())<2) |
| 2057 | 2059 | return $text; |
| | 2060 | + |
| | 2061 | + if($isTitle) |
| | 2062 | + return $this->convertTitle($text); |
| 2058 | 2063 | |
| 2059 | 2064 | // no conversion if redirecting |
| 2060 | 2065 | if(substr($text,0,9) == "#REDIRECT") { |
| — | — | @@ -2114,7 +2119,13 @@ |
| 2115 | 2120 | function autoConvert($text, $toVariant=false) { |
| 2116 | 2121 | return $text; |
| 2117 | 2122 | } |
| 2118 | | - |
| | 2123 | + |
| | 2124 | + /* hook for converting the title, which may needs special treatment |
| | 2125 | + */ |
| | 2126 | + function convertTitle($text) { |
| | 2127 | + return $text; |
| | 2128 | + } |
| | 2129 | + |
| 2119 | 2130 | # returns a list of language variants for conversion. |
| 2120 | 2131 | # right now mainly used in the Chinese conversion |
| 2121 | 2132 | function getVariants() { |
| Index: trunk/phase3/languages/LanguageZh.php |
| — | — | @@ -102,6 +102,18 @@ |
| 103 | 103 | return $t; |
| 104 | 104 | } |
| 105 | 105 | |
| | 106 | + # only convert titles having more than one character |
| | 107 | + function convertTitle($text) { |
| | 108 | + $len=0; |
| | 109 | + if( function_exists( 'mb_strlen' ) ) |
| | 110 | + $len = mb_strlen($text); |
| | 111 | + else |
| | 112 | + $len = strlen($text)/3; |
| | 113 | + if($len>1) |
| | 114 | + return $this->autoConvert( $text); |
| | 115 | + return $text; |
| | 116 | + } |
| | 117 | + |
| 106 | 118 | function getVariants() { |
| 107 | 119 | return array("zh-cn", "zh-tw", "zh-sg", "zh-hk"); |
| 108 | 120 | } |