MediaWiki  REL1_19
LanguageZh.php
Go to the documentation of this file.
00001 <?php
00002 
00003 require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );
00004 require_once( dirname( __FILE__ ) . '/LanguageZh_hans.php' );
00005 
00009 class ZhConverter extends LanguageConverter {
00010 
00019         function __construct( $langobj, $maincode,
00020                                                                 $variants = array(),
00021                                                                 $variantfallbacks = array(),
00022                                                                 $flags = array(),
00023                                                                 $manualLevel = array() ) {
00024                 $this->mDescCodeSep = ':';
00025                 $this->mDescVarSep = ';';
00026                 parent::__construct( $langobj, $maincode,
00027                                                                         $variants,
00028                                                                         $variantfallbacks,
00029                                                                         $flags,
00030                                                                         $manualLevel );
00031                 $names = array(
00032                         'zh'      => '原文',
00033                         'zh-hans' => '简体',
00034                         'zh-hant' => '繁體',
00035                         'zh-cn'   => '大陆',
00036                         'zh-tw'   => '台灣',
00037                         'zh-hk'   => '香港',
00038                         'zh-mo'   => '澳門',
00039                         'zh-sg'   => '新加坡',
00040                         'zh-my'   => '大马',
00041                 );
00042                 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
00043         }
00044 
00045         function loadDefaultTables() {
00046                 require( dirname( __FILE__ ) . "/../../includes/ZhConversion.php" );
00047                 $this->mTables = array(
00048                         'zh-hans' => new ReplacementArray( $zh2Hans ),
00049                         'zh-hant' => new ReplacementArray( $zh2Hant ),
00050                         'zh-cn'   => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
00051                         'zh-hk'   => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
00052                         'zh-mo'   => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
00053                         'zh-my'   => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
00054                         'zh-sg'   => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
00055                         'zh-tw'   => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
00056                         'zh'      => new ReplacementArray
00057                 );
00058         }
00059 
00060         function postLoadTables() {
00061                 $this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
00062                 $this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
00063                 $this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
00064                 $this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
00065                 $this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
00066                 $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
00067         }
00068 
00079         function markNoConversion( $text, $noParse = false ) {
00080                 return $text;
00081         }
00082 
00087         function convertCategoryKey( $key ) {
00088                 return $this->autoConvert( $key, 'zh' );
00089         }
00090 }
00091 
00098 class LanguageZh extends LanguageZh_hans {
00099 
00100         function __construct() {
00101                 global $wgHooks;
00102                 parent::__construct();
00103 
00104                 $variants = array( 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw' );
00105 
00106                 $variantfallbacks = array(
00107                         'zh'      => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
00108                         'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
00109                         'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
00110                         'zh-cn'   => array( 'zh-hans', 'zh-sg', 'zh-my' ),
00111                         'zh-sg'   => array( 'zh-hans', 'zh-cn', 'zh-my' ),
00112                         'zh-my'   => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
00113                         'zh-tw'   => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
00114                         'zh-hk'   => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
00115                         'zh-mo'   => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
00116                 );
00117                 $ml = array(
00118                         'zh'      => 'disable',
00119                         'zh-hans' => 'unidirectional',
00120                         'zh-hant' => 'unidirectional',
00121                 );
00122 
00123                 $this->mConverter = new ZhConverter( $this, 'zh',
00124                                                                 $variants, $variantfallbacks,
00125                                                                 array(),
00126                                                                 $ml );
00127 
00128                 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
00129         }
00130 
00137         function segmentForDiff( $text ) {
00138                 return preg_replace(
00139                         "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00140                         "' ' .\"$1\"", $text );
00141         }
00142 
00147         function unsegmentForDiff( $text ) {
00148                 return preg_replace(
00149                         "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00150                         "\"$1\"", $text );
00151         }
00152 
00160         function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
00161                 wfProfileIn( __METHOD__ );
00162 
00163                 // always convert to zh-hans before indexing. it should be
00164                 // better to use zh-hans for search, since conversion from
00165                 // Traditional to Simplified is less ambiguous than the
00166                 // other way around
00167                 $s = $this->mConverter->autoConvert( $string, $autoVariant );
00168                 // LanguageZh_hans::normalizeForSearch
00169                 $s = parent::normalizeForSearch( $s );
00170                 wfProfileOut( __METHOD__ );
00171                 return $s;
00172 
00173         }
00174 
00179         function convertForSearchResult( $termsArray ) {
00180                 $terms = implode( '|', $termsArray );
00181                 $terms = self::convertDoubleWidth( $terms );
00182                 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
00183                 $ret = array_unique( explode( '|', $terms ) );
00184                 return $ret;
00185         }
00186 }
00187