2004-02-18 02:15:00 +00:00
|
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
|
2008-11-30 03:15:22 +00:00
|
|
|
|
require_once( dirname(__FILE__).'/../LanguageConverter.php' );
|
|
|
|
|
|
require_once( dirname(__FILE__).'/LanguageZh_hans.php' );
|
2004-09-16 20:18:49 +00:00
|
|
|
|
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @ingroup Language
|
|
|
|
|
|
*/
|
2005-04-15 14:12:39 +00:00
|
|
|
|
class ZhConverter extends LanguageConverter {
|
2008-06-26 03:00:34 +00:00
|
|
|
|
|
|
|
|
|
|
function __construct($langobj, $maincode,
|
|
|
|
|
|
$variants=array(),
|
|
|
|
|
|
$variantfallbacks=array(),
|
|
|
|
|
|
$markup=array(),
|
|
|
|
|
|
$flags = array(),
|
|
|
|
|
|
$manualLevel = array() ) {
|
2008-07-09 08:16:39 +00:00
|
|
|
|
$this->mDescCodeSep = ':';
|
|
|
|
|
|
$this->mDescVarSep = ';';
|
2008-06-26 03:00:34 +00:00
|
|
|
|
parent::__construct($langobj, $maincode,
|
|
|
|
|
|
$variants,
|
|
|
|
|
|
$variantfallbacks,
|
|
|
|
|
|
$markup,
|
|
|
|
|
|
$flags,
|
|
|
|
|
|
$manualLevel);
|
|
|
|
|
|
$names = array(
|
|
|
|
|
|
'zh' => '原文',
|
|
|
|
|
|
'zh-hans' => '简体',
|
|
|
|
|
|
'zh-hant' => '繁體',
|
|
|
|
|
|
'zh-cn' => '大陆',
|
|
|
|
|
|
'zh-tw' => '台灣',
|
|
|
|
|
|
'zh-hk' => '香港',
|
|
|
|
|
|
'zh-mo' => '澳門',
|
|
|
|
|
|
'zh-sg' => '新加坡',
|
2008-06-27 15:08:07 +00:00
|
|
|
|
'zh-my' => '大马',
|
2008-06-26 03:00:34 +00:00
|
|
|
|
);
|
2009-01-29 08:59:53 +00:00
|
|
|
|
$this->mVariantNames = array_merge($this->mVariantNames,$names);
|
2009-02-06 13:21:11 +00:00
|
|
|
|
$this->loadNamespaceTables();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function loadNamespaceTables() {
|
|
|
|
|
|
global $wgMetaNamespace;
|
|
|
|
|
|
$nsproject = $wgMetaNamespace;
|
|
|
|
|
|
$projecttable = array(
|
|
|
|
|
|
'Wikipedia' => '维基百科',
|
|
|
|
|
|
'Wikisource' => '维基文库',
|
|
|
|
|
|
'Wikinews' => '维基新闻',
|
|
|
|
|
|
'Wiktionary' => '维基词典',
|
|
|
|
|
|
'Wikibooks' => '维基教科书',
|
|
|
|
|
|
'Wikiquote' => '维基语录',
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->mNamespaceTables['zh-hans'] = array(
|
|
|
|
|
|
'Media' => '媒体',
|
|
|
|
|
|
'Special' => '特殊',
|
|
|
|
|
|
'Talk' => '讨论',
|
|
|
|
|
|
'User' => '用户',
|
2009-03-04 06:56:37 +00:00
|
|
|
|
'User talk' => '用户讨论',
|
2009-02-06 13:21:11 +00:00
|
|
|
|
$nsproject
|
|
|
|
|
|
=> isset($projecttable[$nsproject]) ?
|
|
|
|
|
|
$projecttable[$nsproject] : $nsproject,
|
|
|
|
|
|
$nsproject . ' talk'
|
|
|
|
|
|
=> isset($projecttable[$nsproject]) ?
|
|
|
|
|
|
$projecttable[$nsproject] . '讨论' : $nsproject . '讨论',
|
|
|
|
|
|
'File' => '文件',
|
|
|
|
|
|
'File talk' => '文件讨论',
|
|
|
|
|
|
'MediaWiki' => 'MediaWiki',
|
|
|
|
|
|
'MediaWiki talk' => 'MediaWiki讨论',
|
|
|
|
|
|
'Template' => '模板',
|
|
|
|
|
|
'Template talk' => '模板讨论',
|
|
|
|
|
|
'Help' => '帮助',
|
|
|
|
|
|
'Help talk' => '帮助讨论',
|
|
|
|
|
|
'Category' => '分类',
|
|
|
|
|
|
'Category talk' => '分类讨论',
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->mNamespaceTables['zh-hant'] = array_merge($this->mNamespaceTables['zh-hans']);
|
|
|
|
|
|
$this->mNamespaceTables['zh-hant']['File'] = '檔案';
|
|
|
|
|
|
$this->mNamespaceTables['zh-hant']['File talk'] = '檔案討論';
|
|
|
|
|
|
$this->mNamespaceTables['zh'] = array_merge($this->mNamespaceTables['zh-hans']);
|
|
|
|
|
|
$this->mNamespaceTables['zh-cn'] = array_merge($this->mNamespaceTables['zh-hans']);
|
|
|
|
|
|
$this->mNamespaceTables['zh-hk'] = array_merge($this->mNamespaceTables['zh-hant']);
|
|
|
|
|
|
$this->mNamespaceTables['zh-mo'] = array_merge($this->mNamespaceTables['zh-hant']);
|
|
|
|
|
|
$this->mNamespaceTables['zh-my'] = array_merge($this->mNamespaceTables['zh-hans']);
|
|
|
|
|
|
$this->mNamespaceTables['zh-sg'] = array_merge($this->mNamespaceTables['zh-hans']);
|
|
|
|
|
|
$this->mNamespaceTables['zh-tw'] = array_merge($this->mNamespaceTables['zh-hant']);
|
2008-06-26 03:00:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-04-15 14:12:39 +00:00
|
|
|
|
function loadDefaultTables() {
|
2007-06-06 16:01:14 +00:00
|
|
|
|
require( dirname(__FILE__)."/../../includes/ZhConversion.php" );
|
2006-11-21 09:53:45 +00:00
|
|
|
|
$this->mTables = array(
|
2007-12-02 09:02:09 +00:00
|
|
|
|
'zh-hans' => new ReplacementArray( $zh2Hans ),
|
|
|
|
|
|
'zh-hant' => new ReplacementArray( $zh2Hant ),
|
|
|
|
|
|
'zh-cn' => new ReplacementArray( array_merge($zh2Hans, $zh2CN) ),
|
|
|
|
|
|
'zh-hk' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
|
2008-06-26 03:00:34 +00:00
|
|
|
|
'zh-mo' => new ReplacementArray( array_merge($zh2Hant, $zh2HK) ),
|
|
|
|
|
|
'zh-my' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
|
|
|
|
|
|
'zh-sg' => new ReplacementArray( array_merge($zh2Hans, $zh2SG) ),
|
|
|
|
|
|
'zh-tw' => new ReplacementArray( array_merge($zh2Hant, $zh2TW) ),
|
2007-12-02 09:02:09 +00:00
|
|
|
|
'zh' => new ReplacementArray
|
2006-11-21 09:53:45 +00:00
|
|
|
|
);
|
2004-10-04 04:14:05 +00:00
|
|
|
|
}
|
2005-01-22 03:22:16 +00:00
|
|
|
|
|
2005-04-15 14:12:39 +00:00
|
|
|
|
function postLoadTables() {
|
2007-12-02 09:02:09 +00:00
|
|
|
|
$this->mTables['zh-cn']->merge( $this->mTables['zh-hans'] );
|
|
|
|
|
|
$this->mTables['zh-hk']->merge( $this->mTables['zh-hant'] );
|
2008-06-26 03:00:34 +00:00
|
|
|
|
$this->mTables['zh-mo']->merge( $this->mTables['zh-hant'] );
|
|
|
|
|
|
$this->mTables['zh-my']->merge( $this->mTables['zh-hans'] );
|
|
|
|
|
|
$this->mTables['zh-sg']->merge( $this->mTables['zh-hans'] );
|
|
|
|
|
|
$this->mTables['zh-tw']->merge( $this->mTables['zh-hant'] );
|
2007-12-02 09:02:09 +00:00
|
|
|
|
}
|
2005-04-28 03:27:07 +00:00
|
|
|
|
|
2005-08-15 19:27:58 +00:00
|
|
|
|
/* there shouldn't be any latin text in Chinese conversion, so no need
|
2006-12-14 20:47:19 +00:00
|
|
|
|
to mark anything.
|
|
|
|
|
|
$noParse is there for compatibility with LanguageConvert::markNoConversion
|
2008-06-26 03:00:34 +00:00
|
|
|
|
*/
|
2006-12-14 20:47:19 +00:00
|
|
|
|
function markNoConversion($text, $noParse = false) {
|
2005-04-28 03:27:07 +00:00
|
|
|
|
return $text;
|
|
|
|
|
|
}
|
2005-04-28 03:33:54 +00:00
|
|
|
|
|
|
|
|
|
|
function convertCategoryKey( $key ) {
|
2007-12-02 09:02:09 +00:00
|
|
|
|
return $this->autoConvert( $key, 'zh' );
|
2005-04-28 03:33:54 +00:00
|
|
|
|
}
|
2005-04-15 14:12:39 +00:00
|
|
|
|
}
|
2004-12-29 01:07:43 +00:00
|
|
|
|
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* class that handles both Traditional and Simplified Chinese
|
|
|
|
|
|
* right now it only distinguish zh_hans, zh_hant, zh_cn, zh_tw, zh_sg and zh_hk.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @ingroup Language
|
|
|
|
|
|
*/
|
2007-09-27 15:40:35 +00:00
|
|
|
|
class LanguageZh extends LanguageZh_hans {
|
2005-08-15 19:27:58 +00:00
|
|
|
|
|
2006-06-24 18:48:58 +00:00
|
|
|
|
function __construct() {
|
2005-04-15 14:12:39 +00:00
|
|
|
|
global $wgHooks;
|
2006-07-26 07:15:39 +00:00
|
|
|
|
parent::__construct();
|
2007-12-02 03:41:12 +00:00
|
|
|
|
|
2009-09-16 23:53:31 +00:00
|
|
|
|
$variants = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
|
2009-08-21 16:00:01 +00:00
|
|
|
|
|
2007-12-02 03:41:12 +00:00
|
|
|
|
$variantfallbacks = array(
|
2008-06-26 03:00:34 +00:00
|
|
|
|
'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
|
|
|
|
|
|
'zh-hans' => array('zh-cn','zh-sg','zh-my'),
|
|
|
|
|
|
'zh-hant' => array('zh-tw','zh-hk','zh-mo'),
|
|
|
|
|
|
'zh-cn' => array('zh-hans','zh-sg','zh-my'),
|
|
|
|
|
|
'zh-sg' => array('zh-hans','zh-cn','zh-my'),
|
2008-07-06 17:23:00 +00:00
|
|
|
|
'zh-my' => array('zh-hans','zh-sg','zh-cn'),
|
2008-06-26 03:00:34 +00:00
|
|
|
|
'zh-tw' => array('zh-hant','zh-hk','zh-mo'),
|
|
|
|
|
|
'zh-hk' => array('zh-hant','zh-mo','zh-tw'),
|
|
|
|
|
|
'zh-mo' => array('zh-hant','zh-hk','zh-tw'),
|
|
|
|
|
|
);
|
|
|
|
|
|
$ml=array(
|
|
|
|
|
|
'zh' => 'disable',
|
|
|
|
|
|
'zh-hans' => 'unidirectional',
|
|
|
|
|
|
'zh-hant' => 'unidirectional',
|
2007-12-02 03:41:12 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
2008-06-26 03:00:34 +00:00
|
|
|
|
$this->mConverter = new ZhConverter( $this, 'zh',
|
|
|
|
|
|
$variants, $variantfallbacks,
|
|
|
|
|
|
array(),array(),
|
|
|
|
|
|
$ml);
|
2007-12-02 03:41:12 +00:00
|
|
|
|
|
2005-04-15 14:12:39 +00:00
|
|
|
|
$wgHooks['ArticleSaveComplete'][] = $this->mConverter;
|
2004-12-29 01:07:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-05 02:17:21 +00:00
|
|
|
|
# this should give much better diff info
|
|
|
|
|
|
function segmentForDiff( $text ) {
|
|
|
|
|
|
return preg_replace(
|
|
|
|
|
|
"/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
|
|
|
|
|
|
"' ' .\"$1\"", $text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function unsegmentForDiff( $text ) {
|
|
|
|
|
|
return preg_replace(
|
|
|
|
|
|
"/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
|
|
|
|
|
|
"\"$1\"", $text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-29 01:07:43 +00:00
|
|
|
|
// word segmentation
|
2004-11-09 21:41:30 +00:00
|
|
|
|
function stripForSearch( $string ) {
|
2008-11-25 02:39:06 +00:00
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-12-29 01:07:43 +00:00
|
|
|
|
|
2007-12-02 09:02:09 +00:00
|
|
|
|
//always convert to zh-hans before indexing. it should be
|
|
|
|
|
|
//better to use zh-hans for search, since conversion from
|
2004-11-25 03:17:05 +00:00
|
|
|
|
//Traditional to Simplified is less ambiguous than the
|
|
|
|
|
|
//other way around
|
2004-12-29 01:07:43 +00:00
|
|
|
|
|
2009-06-24 02:27:51 +00:00
|
|
|
|
$t = $this->mConverter->autoConvert( $string, 'zh-hans' );
|
2006-08-06 14:23:53 +00:00
|
|
|
|
$t = parent::stripForSearch( $t );
|
2008-11-25 02:39:06 +00:00
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-11-09 21:41:30 +00:00
|
|
|
|
return $t;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2004-11-29 01:22:44 +00:00
|
|
|
|
|
|
|
|
|
|
function convertForSearchResult( $termsArray ) {
|
|
|
|
|
|
$terms = implode( '|', $termsArray );
|
2005-04-15 14:12:39 +00:00
|
|
|
|
$terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
|
2004-11-29 02:42:58 +00:00
|
|
|
|
$ret = array_unique( explode('|', $terms) );
|
2004-11-29 01:22:44 +00:00
|
|
|
|
return $ret;
|
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
}
|
2008-06-26 03:00:34 +00:00
|
|
|
|
|