MediaWiki  REL1_20
LanguageZh.php
Go to the documentation of this file.
00001 <?php
00024 require_once( __DIR__ . '/../LanguageConverter.php' );
00025 require_once( __DIR__ . '/LanguageZh_hans.php' );
00026 
00030 class ZhConverter extends LanguageConverter {
00031 
00040         function __construct( $langobj, $maincode,
00041                                                                 $variants = array(),
00042                                                                 $variantfallbacks = array(),
00043                                                                 $flags = array(),
00044                                                                 $manualLevel = array() ) {
00045                 $this->mDescCodeSep = ':';
00046                 $this->mDescVarSep = ';';
00047                 parent::__construct( $langobj, $maincode,
00048                                                                         $variants,
00049                                                                         $variantfallbacks,
00050                                                                         $flags,
00051                                                                         $manualLevel );
00052                 $names = array(
00053                         'zh'      => '原文',
00054                         'zh-hans' => '简体',
00055                         'zh-hant' => '繁體',
00056                         'zh-cn'   => '大陆',
00057                         'zh-tw'   => '台灣',
00058                         'zh-hk'   => '香港',
00059                         'zh-mo'   => '澳門',
00060                         'zh-sg'   => '新加坡',
00061                         'zh-my'   => '大马',
00062                 );
00063                 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
00064         }
00065 
00066         function loadDefaultTables() {
00067                 require( __DIR__ . "/../../includes/ZhConversion.php" );
00068                 $this->mTables = array(
00069                         'zh-hans' => new ReplacementArray( $zh2Hans ),
00070                         'zh-hant' => new ReplacementArray( $zh2Hant ),
00071                         'zh-cn'   => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
00072                         'zh-hk'   => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
00073                         'zh-mo'   => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
00074                         'zh-my'   => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
00075                         'zh-sg'   => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
00076                         'zh-tw'   => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
00077                         'zh'      => new ReplacementArray
00078                 );
00079         }
00080 
00081         function postLoadTables() {
00082                 $this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
00083                 $this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
00084                 $this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
00085                 $this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
00086                 $this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
00087                 $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
00088         }
00089 
00100         function markNoConversion( $text, $noParse = false ) {
00101                 return $text;
00102         }
00103 
00108         function convertCategoryKey( $key ) {
00109                 return $this->autoConvert( $key, 'zh' );
00110         }
00111 }
00112 
00119 class LanguageZh extends LanguageZh_hans {
00120 
00121         function __construct() {
00122                 global $wgHooks;
00123                 parent::__construct();
00124 
00125                 $variants = array( 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw' );
00126 
00127                 $variantfallbacks = array(
00128                         'zh'      => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
00129                         'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
00130                         'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
00131                         'zh-cn'   => array( 'zh-hans', 'zh-sg', 'zh-my' ),
00132                         'zh-sg'   => array( 'zh-hans', 'zh-cn', 'zh-my' ),
00133                         'zh-my'   => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
00134                         'zh-tw'   => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
00135                         'zh-hk'   => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
00136                         'zh-mo'   => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
00137                 );
00138                 $ml = array(
00139                         'zh'      => 'disable',
00140                         'zh-hans' => 'unidirectional',
00141                         'zh-hant' => 'unidirectional',
00142                 );
00143 
00144                 $this->mConverter = new ZhConverter( $this, 'zh',
00145                                                                 $variants, $variantfallbacks,
00146                                                                 array(),
00147                                                                 $ml );
00148 
00149                 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
00150         }
00151 
00158         function segmentForDiff( $text ) {
00159                 return preg_replace(
00160                         "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00161                         "' ' .\"$1\"", $text );
00162         }
00163 
00168         function unsegmentForDiff( $text ) {
00169                 return preg_replace(
00170                         "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00171                         "\"$1\"", $text );
00172         }
00173 
00181         function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
00182                 wfProfileIn( __METHOD__ );
00183 
00184                 // always convert to zh-hans before indexing. it should be
00185                 // better to use zh-hans for search, since conversion from
00186                 // Traditional to Simplified is less ambiguous than the
00187                 // other way around
00188                 $s = $this->mConverter->autoConvert( $string, $autoVariant );
00189                 // LanguageZh_hans::normalizeForSearch
00190                 $s = parent::normalizeForSearch( $s );
00191                 wfProfileOut( __METHOD__ );
00192                 return $s;
00193 
00194         }
00195 
00200         function convertForSearchResult( $termsArray ) {
00201                 $terms = implode( '|', $termsArray );
00202                 $terms = self::convertDoubleWidth( $terms );
00203                 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
00204                 $ret = array_unique( explode( '|', $terms ) );
00205                 return $ret;
00206         }
00207 }
00208