MediaWiki  REL1_21
LanguageGan.php
Go to the documentation of this file.
00001 <?php
00024 require_once( __DIR__ . '/../LanguageConverter.php' );
00025 require_once( __DIR__ . '/LanguageZh.php' );
00026 
00030 class GanConverter 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                         'gan'      => '原文',
00054                         'gan-hans' => '简体',
00055                         'gan-hant' => '繁體',
00056                 );
00057                 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
00058         }
00059 
00060         function loadDefaultTables() {
00061                 require( __DIR__ . "/../../includes/ZhConversion.php" );
00062                 $this->mTables = array(
00063                         'gan-hans' => new ReplacementArray( $zh2Hans ),
00064                         'gan-hant' => new ReplacementArray( $zh2Hant ),
00065                         'gan'      => new ReplacementArray
00066                 );
00067         }
00068 
00073         function convertCategoryKey( $key ) {
00074                 return $this->autoConvert( $key, 'gan' );
00075         }
00076 }
00077 
00084 class LanguageGan extends LanguageZh {
00085 
00086         function __construct() {
00087                 global $wgHooks;
00088                 parent::__construct();
00089 
00090                 $variants = array( 'gan', 'gan-hans', 'gan-hant' );
00091                 $variantfallbacks = array(
00092                         'gan'      => array( 'gan-hans', 'gan-hant' ),
00093                         'gan-hans' => array( 'gan' ),
00094                         'gan-hant' => array( 'gan' ),
00095                 );
00096                 $ml = array(
00097                         'gan'      => 'disable',
00098                 );
00099 
00100                 $this->mConverter = new GanConverter( $this, 'gan',
00101                                                                 $variants, $variantfallbacks,
00102                                                                 array(),
00103                                                                 $ml );
00104 
00105                 $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
00106         }
00107 
00114         function segmentForDiff( $text ) {
00115                 return preg_replace(
00116                         "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00117                         "' ' .\"$1\"", $text );
00118         }
00119 
00124         function unsegmentForDiff( $text ) {
00125                 return preg_replace(
00126                         "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00127                         "\"$1\"", $text );
00128         }
00129 
00137         function normalizeForSearch( $string, $autoVariant = 'gan-hans' ) {
00138                 // LanguageZh::normalizeForSearch
00139                 return parent::normalizeForSearch( $string, $autoVariant );
00140         }
00141 
00146         function convertForSearchResult( $termsArray ) {
00147                 $terms = implode( '|', $termsArray );
00148                 $terms = self::convertDoubleWidth( $terms );
00149                 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
00150                 $ret = array_unique( explode( '|', $terms ) );
00151                 return $ret;
00152         }
00153 }