00001 <?php
00002
00003 require_once( dirname(__FILE__).'/../LanguageConverter.php' );
00004 require_once( dirname(__FILE__).'/LanguageZh.php' );
00005
00009 class GanConverter extends LanguageConverter {
00010
00011 function __construct($langobj, $maincode,
00012 $variants=array(),
00013 $variantfallbacks=array(),
00014 $markup=array(),
00015 $flags = array(),
00016 $manualLevel = array() ) {
00017 $this->mDescCodeSep = ':';
00018 $this->mDescVarSep = ';';
00019 parent::__construct($langobj, $maincode,
00020 $variants,
00021 $variantfallbacks,
00022 $markup,
00023 $flags,
00024 $manualLevel);
00025 $names = array(
00026 'gan' => '原文',
00027 'gan-hans' => '简体',
00028 'gan-hant' => '繁體',
00029 );
00030 $this->mVariantNames = array_merge($this->mVariantNames,$names);
00031 $this->loadNamespaceTables();
00032 }
00033
00034 function loadNamespaceTables() {
00035 global $wgMetaNamespace;
00036 $nsproject = $wgMetaNamespace;
00037 $projecttable = array(
00038 'Wikipedia' => '维基百科',
00039 'Wikisource' => '维基文库',
00040 'Wikinews' => '维基新闻',
00041 'Wiktionary' => '维基词典',
00042 'Wikibooks' => '维基教科书',
00043 'Wikiquote' => '维基语录',
00044 );
00045 $this->mNamespaceTables['gan-hans'] = array(
00046 'Media' => '媒体',
00047 'Special' => '特殊',
00048 'Talk' => '談詑',
00049 'User' => '用户',
00050 'User talk' => '用户談詑',
00051 $nsproject
00052 => isset($projecttable[$nsproject]) ?
00053 $projecttable[$nsproject] : $nsproject,
00054 $nsproject . ' talk'
00055 => isset($projecttable[$nsproject]) ?
00056 $projecttable[$nsproject] . '談詑' : $nsproject . '談詑',
00057 'File' => '文件',
00058 'File talk' => '文件談詑',
00059 'MediaWiki' => 'MediaWiki',
00060 'MediaWiki talk' => 'MediaWiki談詑',
00061 'Template' => '模板',
00062 'Template talk' => '模板談詑',
00063 'Help' => '帮助',
00064 'Help talk' => '帮助談詑',
00065 'Category' => '分类',
00066 'Category talk' => '分类談詑',
00067 );
00068 $this->mNamespaceTables['gan-hant'] = array_merge($this->mNamespaceTables['gan-hans']);
00069 $this->mNamespaceTables['gan-hant']['File'] = '檔案';
00070 $this->mNamespaceTables['gan-hant']['File talk'] = '檔案談詑';
00071 $this->mNamespaceTables['gan'] = array_merge($this->mNamespaceTables['gan-hans']);
00072 }
00073
00074 function loadDefaultTables() {
00075 require( dirname(__FILE__)."/../../includes/ZhConversion.php" );
00076 $this->mTables = array(
00077 'gan-hans' => new ReplacementArray( $zh2Hans ),
00078 'gan-hant' => new ReplacementArray( $zh2Hant ),
00079 'gan' => new ReplacementArray
00080 );
00081 }
00082
00083
00084
00085
00086
00087 function markNoConversion($text, $noParse = false) {
00088 return $text;
00089 }
00090
00091 function convertCategoryKey( $key ) {
00092 return $this->autoConvert( $key, 'gan' );
00093 }
00094 }
00095
00102 class LanguageGan extends LanguageZh {
00103
00104 function __construct() {
00105 global $wgHooks;
00106 parent::__construct();
00107
00108 $variants = array('gan','gan-hans','gan-hant');
00109 $variantfallbacks = array(
00110 'gan' => array('gan-hans','gan-hant'),
00111 'gan-hans' => array('gan'),
00112 'gan-hant' => array('gan'),
00113 );
00114 $ml=array(
00115 'gan' => 'disable',
00116 );
00117
00118 $this->mConverter = new GanConverter( $this, 'gan',
00119 $variants, $variantfallbacks,
00120 array(),array(),
00121 $ml);
00122
00123 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
00124 }
00125
00126 # this should give much better diff info
00127 function segmentForDiff( $text ) {
00128 return preg_replace(
00129 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00130 "' ' .\"$1\"", $text);
00131 }
00132
00133 function unsegmentForDiff( $text ) {
00134 return preg_replace(
00135 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
00136 "\"$1\"", $text);
00137 }
00138
00139
00140 function stripForSearch( $string ) {
00141 wfProfileIn( __METHOD__ );
00142
00143
00144
00145
00146 $t = preg_replace(
00147 "/([\\xc0-\\xff][\\x80-\\xbf]*)/",
00148 " $1", $string);
00149
00150
00151
00152
00153
00154
00155 $t = $this->mConverter->autoConvert($t, 'gan-hans');
00156 $t = parent::stripForSearch( $t );
00157 wfProfileOut( __METHOD__ );
00158 return $t;
00159
00160 }
00161
00162 function convertForSearchResult( $termsArray ) {
00163 $terms = implode( '|', $termsArray );
00164 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
00165 $ret = array_unique( explode('|', $terms) );
00166 return $ret;
00167 }
00168 }