Added magic word MAG_NOTITLECONVERT to indicate that the title of the page do not...
authorZheng Zhu <zhengzhu@users.mediawiki.org>
Wed, 29 Dec 2004 02:47:33 +0000 (02:47 +0000)
committerZheng Zhu <zhengzhu@users.mediawiki.org>
Wed, 29 Dec 2004 02:47:33 +0000 (02:47 +0000)
includes/MagicWord.php
languages/Language.php
languages/LanguageZh.php

index a8fd0eb..1ca7a87 100644 (file)
@@ -45,6 +45,7 @@ define('MAG_PAGENAMEE', 31);
 define('MAG_NAMESPACE', 32);
 define('MAG_TOC', 33);
 define('MAG_GRAMMAR', 34);
+define('MAG_NOTITLECONVERT', 35);
 
 $wgVariableIDs = array(
        MAG_CURRENTMONTH,
index 0101538..75376aa 100644 (file)
@@ -235,7 +235,8 @@ $wgLanguageNamesEn =& $wgLanguageNames;
        MAG_LOCALURL             => array( 0,    'LOCALURL:'              ),
        MAG_LOCALURLE            => array( 0,    'LOCALURLE:'             ),
        MAG_SERVER               => array( 0,    'SERVER'                 ),
-       MAG_GRAMMAR              => array( 0,    'GRAMMAR:'               )
+       MAG_GRAMMAR              => array( 0,    'GRAMMAR:'               ),
+       MAG_NOTITLECONVERT       => array( 0,    '__NOTITLECONVERT__', '__NOTC__'),
 );
 
 #-------------------------------------------------------------------
index a48e62e..cbccd14 100644 (file)
@@ -37,6 +37,7 @@ class LanguageZh extends LanguageZh_cn {
        var $mTables=false; //the mapping tables
        var $mTablesLoaded = false;
        var $mCacheKey;
+       var $mDoTitleConvert = true;
        function LanguageZh() {
                global $wgDBname;
                $this->mCacheKey = $wgDBname . ":zhtables";
@@ -76,6 +77,7 @@ class LanguageZh extends LanguageZh_cn {
 
                                $cached = $this->parseCachedTable( $wgMessageCache->get( 'zhconversiontable/zh-hk', true, true, true ) );
                                $this->mTables['zh-hk'] = array_merge($this->mTables['zh-hk'], $cached);
+
                        }
                        $wgMemc->set($this->mCacheKey, $this->mTables, 43200);
                }
@@ -204,16 +206,22 @@ class LanguageZh extends LanguageZh_cn {
        # -{text}- in which case no conversion should take place for text
        function convert( $text , $isTitle=false) {
                global $wgDisableLangConversion;
-
                if($wgDisableLangConversion)
                        return $text; 
-               
+
+               $mw =& MagicWord::get( MAG_NOTITLECONVERT );
+               if( $mw->matchAndRemove( $text ) )
+                       $this->mDoTitleConvert = false;
+
                // no conversion if redirecting
-               if(strtolower( substr( $text,0,9 ) ) == "#redirect") {
+               $mw =& MagicWord::get( MAG_REDIRECT );
+               if( $mw->matchStart( $text ))
                        return $text;
-               }
 
                if( $isTitle ) {
+                       if( !$this->mDoTitleConvert )
+                               return $text;
+
                        global $wgRequest;
                        $isredir = $wgRequest->getText( 'redirect', 'yes' );
                        $action = $wgRequest->getText( 'action' );
@@ -221,8 +229,7 @@ class LanguageZh extends LanguageZh_cn {
                                return $text;
                        }
                        else {
-                               $text = $this->convertTitle($text);
-                               return $text;
+                               return $this->autoConvert($text);
                        }
                }
 
@@ -272,18 +279,6 @@ class LanguageZh extends LanguageZh_cn {
        }
 
 
-       # 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", "zh-cn", "zh-tw", "zh-sg", "zh-hk");
        }