MediaWiki
REL1_24
|
00001 <?php 00024 require_once __DIR__ . '/../LanguageConverter.php'; 00025 require_once __DIR__ . '/LanguageZh_hans.php'; 00026 00030 class ZhConverter extends LanguageConverter { 00039 function __construct( $langobj, $maincode, 00040 $variants = array(), 00041 $variantfallbacks = array(), 00042 $flags = array(), 00043 $manualLevel = array() ) { 00044 $this->mDescCodeSep = ':'; 00045 $this->mDescVarSep = ';'; 00046 parent::__construct( $langobj, $maincode, 00047 $variants, 00048 $variantfallbacks, 00049 $flags, 00050 $manualLevel ); 00051 $names = array( 00052 'zh' => '原文', 00053 'zh-hans' => '简体', 00054 'zh-hant' => '繁體', 00055 'zh-cn' => '大陆', 00056 'zh-tw' => '台灣', 00057 'zh-hk' => '香港', 00058 'zh-mo' => '澳門', 00059 'zh-sg' => '新加坡', 00060 'zh-my' => '大马', 00061 ); 00062 $this->mVariantNames = array_merge( $this->mVariantNames, $names ); 00063 } 00064 00065 function loadDefaultTables() { 00066 require __DIR__ . "/../../includes/ZhConversion.php"; 00067 $this->mTables = array( 00068 'zh-hans' => new ReplacementArray( $zh2Hans ), 00069 'zh-hant' => new ReplacementArray( $zh2Hant ), 00070 'zh-cn' => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ), 00071 'zh-hk' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ), 00072 'zh-mo' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ), 00073 'zh-my' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ), 00074 'zh-sg' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ), 00075 'zh-tw' => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ), 00076 'zh' => new ReplacementArray 00077 ); 00078 } 00079 00080 function postLoadTables() { 00081 $this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] ); 00082 $this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] ); 00083 $this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] ); 00084 $this->mTables['zh-my']->merge( $this->mTables['zh-hans'] ); 00085 $this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] ); 00086 $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] ); 00087 } 00088 00093 function convertCategoryKey( $key ) { 00094 return $this->autoConvert( $key, 'zh' ); 00095 } 00096 } 00097 00104 class LanguageZh extends LanguageZh_hans { 00105 function __construct() { 00106 global $wgHooks; 00107 00108 parent::__construct(); 00109 00110 $variants = array( 00111 'zh', 00112 'zh-hans', 00113 'zh-hant', 00114 'zh-cn', 00115 'zh-hk', 00116 'zh-mo', 00117 'zh-my', 00118 'zh-sg', 00119 'zh-tw' 00120 ); 00121 00122 $variantfallbacks = array( 00123 'zh' => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ), 00124 'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ), 00125 'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ), 00126 'zh-cn' => array( 'zh-hans', 'zh-sg', 'zh-my' ), 00127 'zh-sg' => array( 'zh-hans', 'zh-cn', 'zh-my' ), 00128 'zh-my' => array( 'zh-hans', 'zh-sg', 'zh-cn' ), 00129 'zh-tw' => array( 'zh-hant', 'zh-hk', 'zh-mo' ), 00130 'zh-hk' => array( 'zh-hant', 'zh-mo', 'zh-tw' ), 00131 'zh-mo' => array( 'zh-hant', 'zh-hk', 'zh-tw' ), 00132 ); 00133 $ml = array( 00134 'zh' => 'disable', 00135 'zh-hans' => 'unidirectional', 00136 'zh-hant' => 'unidirectional', 00137 ); 00138 00139 $this->mConverter = new ZhConverter( $this, 'zh', 00140 $variants, $variantfallbacks, 00141 array(), 00142 $ml ); 00143 00144 $wgHooks['PageContentSaveComplete'][] = $this->mConverter; 00145 } 00146 00153 function segmentForDiff( $text ) { 00154 return preg_replace( '/[\xc0-\xff][\x80-\xbf]*/', ' $0', $text ); 00155 } 00156 00161 function unsegmentForDiff( $text ) { 00162 return preg_replace( '/ ([\xc0-\xff][\x80-\xbf]*)/', '$1', $text ); 00163 } 00164 00172 function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) { 00173 wfProfileIn( __METHOD__ ); 00174 00175 // always convert to zh-hans before indexing. it should be 00176 // better to use zh-hans for search, since conversion from 00177 // Traditional to Simplified is less ambiguous than the 00178 // other way around 00179 $s = $this->mConverter->autoConvert( $string, $autoVariant ); 00180 // LanguageZh_hans::normalizeForSearch 00181 $s = parent::normalizeForSearch( $s ); 00182 wfProfileOut( __METHOD__ ); 00183 return $s; 00184 00185 } 00186 00191 function convertForSearchResult( $termsArray ) { 00192 $terms = implode( '|', $termsArray ); 00193 $terms = self::convertDoubleWidth( $terms ); 00194 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) ); 00195 $ret = array_unique( explode( '|', $terms ) ); 00196 return $ret; 00197 } 00198 }