Replaced all @fixme with "@todo Fixme" since doxygen doesn't have a @fixme command
[lhc/web/wiklou.git] / languages / classes / LanguageGan.php
1 <?php
2
3 require_once( dirname(__FILE__).'/../LanguageConverter.php' );
4 require_once( dirname(__FILE__).'/LanguageZh.php' );
5
6 /**
7 * @ingroup Language
8 */
9 class GanConverter extends LanguageConverter {
10
11 function __construct($langobj, $maincode,
12 $variants=array(),
13 $variantfallbacks=array(),
14 $markup=array(),
15 $flags = array(),
16 $manualLevel = array() ) {
17 $this->mDescCodeSep = ':';
18 $this->mDescVarSep = ';';
19 parent::__construct($langobj, $maincode,
20 $variants,
21 $variantfallbacks,
22 $markup,
23 $flags,
24 $manualLevel);
25 $names = array(
26 'gan' => '原文',
27 'gan-hans' => '简体',
28 'gan-hant' => '繁體',
29 );
30 $this->mVariantNames = array_merge($this->mVariantNames,$names);
31 $this->loadNamespaceTables();
32 }
33
34 function loadNamespaceTables() {
35 global $wgMetaNamespace;
36 $nsproject = $wgMetaNamespace;
37 $projecttable = array(
38 'Wikipedia' => '维基百科',
39 'Wikisource' => '维基文库',
40 'Wikinews' => '维基新闻',
41 'Wiktionary' => '维基词典',
42 'Wikibooks' => '维基教科书',
43 'Wikiquote' => '维基语录',
44 );
45 $this->mNamespaceTables['gan-hans'] = array(
46 'Media' => '媒体',
47 'Special' => '特殊',
48 'Talk' => '談詑',
49 'User' => '用户',
50 'User talk' => '用户談詑',
51 $nsproject
52 => isset($projecttable[$nsproject]) ?
53 $projecttable[$nsproject] : $nsproject,
54 $nsproject . ' talk'
55 => isset($projecttable[$nsproject]) ?
56 $projecttable[$nsproject] . '談詑' : $nsproject . '談詑',
57 'File' => '文件',
58 'File talk' => '文件談詑',
59 'MediaWiki' => 'MediaWiki',
60 'MediaWiki talk' => 'MediaWiki談詑',
61 'Template' => '模板',
62 'Template talk' => '模板談詑',
63 'Help' => '帮助',
64 'Help talk' => '帮助談詑',
65 'Category' => '分类',
66 'Category talk' => '分类談詑',
67 );
68 $this->mNamespaceTables['gan-hant'] = array_merge($this->mNamespaceTables['gan-hans']);
69 $this->mNamespaceTables['gan-hant']['File'] = '檔案';
70 $this->mNamespaceTables['gan-hant']['File talk'] = '檔案談詑';
71 $this->mNamespaceTables['gan'] = array_merge($this->mNamespaceTables['gan-hans']);
72 }
73
74 function loadDefaultTables() {
75 require( dirname(__FILE__)."/../../includes/ZhConversion.php" );
76 $this->mTables = array(
77 'gan-hans' => new ReplacementArray( $zh2Hans ),
78 'gan-hant' => new ReplacementArray( $zh2Hant ),
79 'gan' => new ReplacementArray
80 );
81 }
82
83 /* there shouldn't be any latin text in Chinese conversion, so no need
84 to mark anything.
85 $noParse is there for compatibility with LanguageConvert::markNoConversion
86 */
87 function markNoConversion($text, $noParse = false) {
88 return $text;
89 }
90
91 function convertCategoryKey( $key ) {
92 return $this->autoConvert( $key, 'gan' );
93 }
94 }
95
96 /**
97 * class that handles both Traditional and Simplified Chinese
98 * right now it only distinguish gan_hans, gan_hant.
99 *
100 * @ingroup Language
101 */
102 class LanguageGan extends LanguageZh {
103
104 function __construct() {
105 global $wgHooks;
106 parent::__construct();
107
108 $variants = array('gan','gan-hans','gan-hant');
109 $variantfallbacks = array(
110 'gan' => array('gan-hans','gan-hant'),
111 'gan-hans' => array('gan'),
112 'gan-hant' => array('gan'),
113 );
114 $ml=array(
115 'gan' => 'disable',
116 );
117
118 $this->mConverter = new GanConverter( $this, 'gan',
119 $variants, $variantfallbacks,
120 array(),array(),
121 $ml);
122
123 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
124 }
125
126 # this should give much better diff info
127 function segmentForDiff( $text ) {
128 return preg_replace(
129 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
130 "' ' .\"$1\"", $text);
131 }
132
133 function unsegmentForDiff( $text ) {
134 return preg_replace(
135 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
136 "\"$1\"", $text);
137 }
138
139 // word segmentation
140 function stripForSearch( $string ) {
141 wfProfileIn( __METHOD__ );
142
143 // eventually this should be a word segmentation
144 // for now just treat each character as a word
145 // @todo Fixme: only do this for Han characters...
146 $t = preg_replace(
147 "/([\\xc0-\\xff][\\x80-\\xbf]*)/",
148 " $1", $string);
149
150 //always convert to gan-hans before indexing. it should be
151 //better to use gan-hans for search, since conversion from
152 //Traditional to Simplified is less ambiguous than the
153 //other way around
154
155 $t = $this->mConverter->autoConvert($t, 'gan-hans');
156 $t = parent::stripForSearch( $t );
157 wfProfileOut( __METHOD__ );
158 return $t;
159
160 }
161
162 function convertForSearchResult( $termsArray ) {
163 $terms = implode( '|', $termsArray );
164 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
165 $ret = array_unique( explode('|', $terms) );
166 return $ret;
167 }
168 }