From c7c31c6fecde75b0fa96a215e6de4a05eabc020f Mon Sep 17 00:00:00 2001 From: Zheng Zhu Date: Wed, 29 Dec 2004 02:47:33 +0000 Subject: [PATCH] Added magic word MAG_NOTITLECONVERT to indicate that the title of the page do not need to be converted. Useful in zh: --- includes/MagicWord.php | 1 + languages/Language.php | 3 ++- languages/LanguageZh.php | 31 +++++++++++++------------------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/includes/MagicWord.php b/includes/MagicWord.php index a8fd0eb472..1ca7a87671 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -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, diff --git a/languages/Language.php b/languages/Language.php index 0101538285..75376aa5c0 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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__'), ); #------------------------------------------------------------------- diff --git a/languages/LanguageZh.php b/languages/LanguageZh.php index a48e62e42f..cbccd14d66 100644 --- a/languages/LanguageZh.php +++ b/languages/LanguageZh.php @@ -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"); } -- 2.20.1