MediaWiki  REL1_19
LanguageGan.php
Go to the documentation of this file.
00001 <?php
00002 
00003 require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );
00004 require_once( dirname( __FILE__ ) . '/LanguageZh.php' );
00005 
00009 class GanConverter 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                         'gan'      => '原文',
00033                         'gan-hans' => '简体',
00034                         'gan-hant' => '繁體',
00035                 );
00036                 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
00037         }
00038 
00039         function loadDefaultTables() {
00040                 require( dirname( __FILE__ ) . "/../../includes/ZhConversion.php" );
00041                 $this->mTables = array(
00042                         'gan-hans' => new ReplacementArray( $zh2Hans ),
00043                         'gan-hant' => new ReplacementArray( $zh2Hant ),
00044                         'gan'      => new ReplacementArray
00045                 );
00046         }
00047 
00058         function markNoConversion( $text, $noParse = false ) {
00059                 return $text;
00060         }
00061 
00066         function convertCategoryKey( $key ) {
00067                 return $this->autoConvert( $key, 'gan' );
00068         }
00069 }
00070 
00077 class LanguageGan extends LanguageZh {
00078 
00079         function __construct() {
00080                 global $wgHooks;
00081                 parent::__construct();
00082 
00083                 $variants = array( 'gan', 'gan-hans', 'gan-hant' );
00084                 $variantfallbacks = array(
00085                         'gan'      => array( 'gan-hans', 'gan-hant' ),
00086                         'gan-hans' => array( 'gan' ),
00087                         'gan-hant' => array( 'gan' ),
00088                 );
00089                 $ml = array(
00090                         'gan'      => 'disable',
00091                 );
00092 
00093                 $this->mConverter = new GanConverter( $this, 'gan',
00094                                                                 $variants, $variantfallbacks,
00095                                                                 array(),
00096                                                                 $ml );
00097 
00098                 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
00099         }
00100 
00107         function segmentForDiff( $text ) {
00108                 return preg_replace(
00109                         "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00110                         "' ' .\"$1\"", $text );
00111         }
00112 
00117         function unsegmentForDiff( $text ) {
00118                 return preg_replace(
00119                         "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00120                         "\"$1\"", $text );
00121         }
00122 
00130         function normalizeForSearch( $string, $autoVariant = 'gan-hans' ) {
00131                 // LanguageZh::normalizeForSearch
00132                 return parent::normalizeForSearch( $string, $autoVariant );
00133         }
00134 
00139         function convertForSearchResult( $termsArray ) {
00140                 $terms = implode( '|', $termsArray );
00141                 $terms = self::convertDoubleWidth( $terms );
00142                 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
00143                 $ret = array_unique( explode( '|', $terms ) );
00144                 return $ret;
00145         }
00146 }