Explicitally define some variables
[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 $flags = array(),
15 $manualLevel = array() ) {
16 $this->mDescCodeSep = ':';
17 $this->mDescVarSep = ';';
18 parent::__construct( $langobj, $maincode,
19 $variants,
20 $variantfallbacks,
21 $flags,
22 $manualLevel );
23 $names = array(
24 'gan' => '原文',
25 'gan-hans' => '简体',
26 'gan-hant' => '繁體',
27 );
28 $this->mVariantNames = array_merge( $this->mVariantNames, $names );
29 }
30
31 function loadDefaultTables() {
32 require( dirname( __FILE__ ) . "/../../includes/ZhConversion.php" );
33 $this->mTables = array(
34 'gan-hans' => new ReplacementArray( $zh2Hans ),
35 'gan-hant' => new ReplacementArray( $zh2Hant ),
36 'gan' => new ReplacementArray
37 );
38 }
39
40 /* there shouldn't be any latin text in Chinese conversion, so no need
41 to mark anything.
42 $noParse is there for compatibility with LanguageConvert::markNoConversion
43 */
44 function markNoConversion( $text, $noParse = false ) {
45 return $text;
46 }
47
48 function convertCategoryKey( $key ) {
49 return $this->autoConvert( $key, 'gan' );
50 }
51 }
52
53 /**
54 * class that handles both Traditional and Simplified Chinese
55 * right now it only distinguish gan_hans, gan_hant.
56 *
57 * @ingroup Language
58 */
59 class LanguageGan extends LanguageZh {
60
61 function __construct() {
62 global $wgHooks;
63 parent::__construct();
64
65 $variants = array( 'gan', 'gan-hans', 'gan-hant' );
66 $variantfallbacks = array(
67 'gan' => array( 'gan-hans', 'gan-hant' ),
68 'gan-hans' => array( 'gan' ),
69 'gan-hant' => array( 'gan' ),
70 );
71 $ml = array(
72 'gan' => 'disable',
73 );
74
75 $this->mConverter = new GanConverter( $this, 'gan',
76 $variants, $variantfallbacks,
77 array(),
78 $ml );
79
80 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
81 }
82
83 # this should give much better diff info
84 function segmentForDiff( $text ) {
85 return preg_replace(
86 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
87 "' ' .\"$1\"", $text );
88 }
89
90 function unsegmentForDiff( $text ) {
91 return preg_replace(
92 "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
93 "\"$1\"", $text );
94 }
95
96 // word segmentation
97 function normalizeForSearch( $string, $autoVariant = 'gan-hans' ) {
98 // LanguageZh::normalizeForSearch
99 return parent::normalizeForSearch( $string, $autoVariant );
100 }
101
102 function convertForSearchResult( $termsArray ) {
103 $terms = implode( '|', $termsArray );
104 $terms = self::convertDoubleWidth( $terms );
105 $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
106 $ret = array_unique( explode( '|', $terms ) );
107 return $ret;
108 }
109 }