MediaWiki  1.23.2
LanguageZh.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/../LanguageConverter.php';
25 require_once __DIR__ . '/LanguageZh_hans.php';
26 
30 class ZhConverter extends LanguageConverter {
31 
40  function __construct( $langobj, $maincode,
41  $variants = array(),
42  $variantfallbacks = array(),
43  $flags = array(),
44  $manualLevel = array() ) {
45  $this->mDescCodeSep = ':';
46  $this->mDescVarSep = ';';
47  parent::__construct( $langobj, $maincode,
48  $variants,
49  $variantfallbacks,
50  $flags,
51  $manualLevel );
52  $names = array(
53  'zh' => '原文',
54  'zh-hans' => '简体',
55  'zh-hant' => '繁體',
56  'zh-cn' => '大陆',
57  'zh-tw' => '台灣',
58  'zh-hk' => '香港',
59  'zh-mo' => '澳門',
60  'zh-sg' => '新加坡',
61  'zh-my' => '大马',
62  );
63  $this->mVariantNames = array_merge( $this->mVariantNames, $names );
64  }
65 
66  function loadDefaultTables() {
67  require __DIR__ . "/../../includes/ZhConversion.php";
68  $this->mTables = array(
69  'zh-hans' => new ReplacementArray( $zh2Hans ),
70  'zh-hant' => new ReplacementArray( $zh2Hant ),
71  'zh-cn' => new ReplacementArray( array_merge( $zh2Hans, $zh2CN ) ),
72  'zh-hk' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
73  'zh-mo' => new ReplacementArray( array_merge( $zh2Hant, $zh2HK ) ),
74  'zh-my' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
75  'zh-sg' => new ReplacementArray( array_merge( $zh2Hans, $zh2SG ) ),
76  'zh-tw' => new ReplacementArray( array_merge( $zh2Hant, $zh2TW ) ),
77  'zh' => new ReplacementArray
78  );
79  }
80 
81  function postLoadTables() {
82  $this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
83  $this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
84  $this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
85  $this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
86  $this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
87  $this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
88  }
89 
94  function convertCategoryKey( $key ) {
95  return $this->autoConvert( $key, 'zh' );
96  }
97 }
98 
106 
107  function __construct() {
109  parent::__construct();
110 
111  $variants = array( 'zh', 'zh-hans', 'zh-hant', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-my', 'zh-sg', 'zh-tw' );
112 
113  $variantfallbacks = array(
114  'zh' => array( 'zh-hans', 'zh-hant', 'zh-cn', 'zh-tw', 'zh-hk', 'zh-sg', 'zh-mo', 'zh-my' ),
115  'zh-hans' => array( 'zh-cn', 'zh-sg', 'zh-my' ),
116  'zh-hant' => array( 'zh-tw', 'zh-hk', 'zh-mo' ),
117  'zh-cn' => array( 'zh-hans', 'zh-sg', 'zh-my' ),
118  'zh-sg' => array( 'zh-hans', 'zh-cn', 'zh-my' ),
119  'zh-my' => array( 'zh-hans', 'zh-sg', 'zh-cn' ),
120  'zh-tw' => array( 'zh-hant', 'zh-hk', 'zh-mo' ),
121  'zh-hk' => array( 'zh-hant', 'zh-mo', 'zh-tw' ),
122  'zh-mo' => array( 'zh-hant', 'zh-hk', 'zh-tw' ),
123  );
124  $ml = array(
125  'zh' => 'disable',
126  'zh-hans' => 'unidirectional',
127  'zh-hant' => 'unidirectional',
128  );
129 
130  $this->mConverter = new ZhConverter( $this, 'zh',
131  $variants, $variantfallbacks,
132  array(),
133  $ml );
134 
135  $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
136  }
137 
144  function segmentForDiff( $text ) {
145  return preg_replace( '/[\xc0-\xff][\x80-\xbf]*/', ' $0', $text );
146  }
147 
152  function unsegmentForDiff( $text ) {
153  return preg_replace( '/ ([\xc0-\xff][\x80-\xbf]*)/', '$1', $text );
154  }
155 
163  function normalizeForSearch( $string, $autoVariant = 'zh-hans' ) {
164  wfProfileIn( __METHOD__ );
165 
166  // always convert to zh-hans before indexing. it should be
167  // better to use zh-hans for search, since conversion from
168  // Traditional to Simplified is less ambiguous than the
169  // other way around
170  $s = $this->mConverter->autoConvert( $string, $autoVariant );
171  // LanguageZh_hans::normalizeForSearch
172  $s = parent::normalizeForSearch( $s );
173  wfProfileOut( __METHOD__ );
174  return $s;
175 
176  }
177 
182  function convertForSearchResult( $termsArray ) {
183  $terms = implode( '|', $termsArray );
184  $terms = self::convertDoubleWidth( $terms );
185  $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
186  $ret = array_unique( explode( '|', $terms ) );
187  return $ret;
188  }
189 }
190 
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
LanguageZh
class that handles both Traditional and Simplified Chinese right now it only distinguish zh_hans,...
Definition: LanguageZh.php:105
$zh2TW
$zh2TW
Definition: ZhConversion.php:16104
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
$zh2Hans
$zh2Hans
Definition: ZhConversion.php:10023
Language\$mConverter
LanguageConverter $mConverter
Definition: Language.php:78
$s
$s
Definition: mergeMessageFileList.php:156
ZhConverter
Definition: LanguageZh.php:30
$zh2CN
$zh2CN
Definition: ZhConversion.php:18785
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:110
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2113
LanguageZh\convertForSearchResult
convertForSearchResult( $termsArray)
Definition: LanguageZh.php:182
LanguageZh\unsegmentForDiff
unsegmentForDiff( $text)
Definition: LanguageZh.php:152
$zh2HK
$zh2HK
Definition: ZhConversion.php:16507
LanguageZh\__construct
__construct()
Definition: LanguageZh.php:107
LanguageZh\segmentForDiff
segmentForDiff( $text)
this should give much better diff info
Definition: LanguageZh.php:144
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
$zh2SG
$zh2SG
Definition: ZhConversion.php:19063
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
Language\convertDoubleWidth
static convertDoubleWidth( $string)
convert double-width roman characters to single-width.
Definition: Language.php:2682
ZhConverter\postLoadTables
postLoadTables()
Definition: LanguageZh.php:81
ZhConverter\convertCategoryKey
convertCategoryKey( $key)
Definition: LanguageZh.php:94
ReplacementArray
Replacement array for FSS with fallback to strtr() Supports lazy initialisation of FSS resource.
Definition: StringUtils.php:411
$zh2Hant
$zh2Hant
Definition: ZhConversion.php:11
LanguageZh_hans
Simplified Chinese.
Definition: LanguageZh_hans.php:29
ZhConverter\__construct
__construct( $langobj, $maincode, $variants=array(), $variantfallbacks=array(), $flags=array(), $manualLevel=array())
Definition: LanguageZh.php:40
ZhConverter\loadDefaultTables
loadDefaultTables()
Definition: LanguageZh.php:66
LanguageZh\normalizeForSearch
normalizeForSearch( $string, $autoVariant='zh-hans')
auto convert to zh-hans and normalize special characters.
Definition: LanguageZh.php:163