r46913 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46912‎ | r46913 | r46914 >
Date:13:21, 6 February 2009
Author:philip
Status:resolved (Comments)
Tags:
Comment:
1. Namespace translation for Chinese Language.
2. New function to convert namespace text for display. (only applies on wiki with LanguageConverter class)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageZh.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesZh.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesZh_hans.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesZh_hant.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/messages/MessagesZh_hans.php
@@ -10,27 +10,28 @@
1111 * @author O
1212 * @author Shinjiman
1313 * @author Wmr89502270
 14+ * @author Philip
1415 */
1516
1617 $namespaceNames = array(
17 - NS_MEDIA => 'Media',
18 - NS_SPECIAL => 'Special',
 18+ NS_MEDIA => '媒体',
 19+ NS_SPECIAL => '特殊',
1920 NS_MAIN => '',
20 - NS_TALK => 'Talk',
21 - NS_USER => 'User',
22 - NS_USER_TALK => 'User_talk',
 21+ NS_TALK => '讨论',
 22+ NS_USER => '用户',
 23+ NS_USER_TALK => '用户讨论',
2324 # NS_PROJECT set by $wgMetaNamespace
24 - NS_PROJECT_TALK => '$1_talk',
25 - NS_FILE => 'File',
26 - NS_FILE_TALK => 'File_talk',
 25+ NS_PROJECT_TALK => '$1讨论',
 26+ NS_FILE => '文件',
 27+ NS_FILE_TALK => '文件讨论',
2728 NS_MEDIAWIKI => 'MediaWiki',
28 - NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
29 - NS_TEMPLATE => 'Template',
30 - NS_TEMPLATE_TALK => 'Template_talk',
31 - NS_HELP => 'Help',
32 - NS_HELP_TALK => 'Help_talk',
33 - NS_CATEGORY => 'Category',
34 - NS_CATEGORY_TALK => 'Category_talk'
 29+ NS_MEDIAWIKI_TALK => 'MediaWiki讨论',
 30+ NS_TEMPLATE => '模板',
 31+ NS_TEMPLATE_TALK => '模板讨论',
 32+ NS_HELP => '帮助',
 33+ NS_HELP_TALK => '帮助讨论',
 34+ NS_CATEGORY => '分类',
 35+ NS_CATEGORY_TALK => '分类讨论'
3536 );
3637
3738 $namespaceAliases = array(
@@ -49,13 +50,19 @@
5051 'Image' => NS_FILE,
5152 'Image_talk' => NS_FILE_TALK,
5253 '图像对话' => NS_FILE_TALK,
 54+ '图像讨论' => NS_FILE_TALK,
5355 '档案对话' => NS_FILE_TALK,
 56+ '档案讨论' => NS_FILE_TALK,
5457 '文件对话' => NS_FILE_TALK,
 58+ '文件讨论' => NS_FILE_TALK,
5559 '模板' => NS_TEMPLATE,
 60+ '模板对话'=> NS_TEMPLATE_TALK,
5661 '模板讨论'=> NS_TEMPLATE_TALK,
5762 '帮助' => NS_HELP,
 63+ '帮助对话'=> NS_HELP_TALK,
5864 '帮助讨论'=> NS_HELP_TALK,
5965 '分类' => NS_CATEGORY,
 66+ '分类对话'=> NS_CATEGORY_TALK,
6067 '分类讨论'=> NS_CATEGORY_TALK,
6168 );
6269
Index: trunk/phase3/languages/messages/MessagesZh.php
@@ -4,12 +4,34 @@
55 * @ingroup Language
66 * @file
77 *
 8+ * @author Philip
89 */
910
1011 # Stub message file for converter code "zh"
1112
1213 $fallback = 'zh-hans';
1314
 15+$namespaceNames = array(
 16+ NS_MEDIA => 'Media',
 17+ NS_SPECIAL => 'Special',
 18+ NS_MAIN => '',
 19+ NS_TALK => 'Talk',
 20+ NS_USER => 'User',
 21+ NS_USER_TALK => 'User_talk',
 22+ # NS_PROJECT set by $wgMetaNamespace
 23+ NS_PROJECT_TALK => '$1_talk',
 24+ NS_FILE => 'File',
 25+ NS_FILE_TALK => 'File_talk',
 26+ NS_MEDIAWIKI => 'MediaWiki',
 27+ NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
 28+ NS_TEMPLATE => 'Template',
 29+ NS_TEMPLATE_TALK => 'Template_talk',
 30+ NS_HELP => 'Help',
 31+ NS_HELP_TALK => 'Help_talk',
 32+ NS_CATEGORY => 'Category',
 33+ NS_CATEGORY_TALK => 'Category_talk'
 34+);
 35+
1436 $namespaceAliases = array(
1537 '媒体' => NS_MEDIA,
1638 '媒體' => NS_MEDIA,
@@ -34,22 +56,39 @@
3557 '文件' => NS_FILE,
3658 '图像对话' => NS_FILE_TALK,
3759 '圖像對話' => NS_FILE_TALK,
 60+ '图像讨论' => NS_FILE_TALK,
 61+ '圖像討論' => NS_FILE_TALK,
3862 '档案对话' => NS_FILE_TALK,
3963 '檔案對話' => NS_FILE_TALK,
40 - '文件对話' => NS_FILE_TALK,
 64+ '档案讨论' => NS_FILE_TALK,
 65+ '檔案討論' => NS_FILE_TALK,
 66+ '文件对话' => NS_FILE_TALK,
4167 '文件對話' => NS_FILE_TALK,
 68+ '文件讨论' => NS_FILE_TALK,
 69+ '文件討論' => NS_FILE_TALK,
4270 '模板' => NS_TEMPLATE,
43 - '模板讨论'=> NS_TEMPLATE_TALK,
44 - "樣板" => NS_TEMPLATE,
45 - "樣板討論" => NS_TEMPLATE_TALK,
 71+ '样板' => NS_TEMPLATE,
 72+ '樣板' => NS_TEMPLATE,
 73+ '模板对话' => NS_TEMPLATE_TALK,
 74+ '模板對話' => NS_TEMPLATE_TALK,
 75+ '模板讨论' => NS_TEMPLATE_TALK,
 76+ '模板討論' => NS_TEMPLATE_TALK,
 77+ '样板对话' => NS_TEMPLATE_TALK,
 78+ '樣板對話' => NS_TEMPLATE_TALK,
 79+ '样板讨论' => NS_TEMPLATE_TALK,
 80+ '樣板討論' => NS_TEMPLATE_TALK,
4681 '帮助' => NS_HELP,
47 - '帮助讨论'=> NS_HELP_TALK,
48 - "幫助" => NS_HELP,
49 - "幫助討論" => NS_HELP_TALK,
 82+ '幫助' => NS_HELP,
 83+ '帮助对话' => NS_HELP_TALK,
 84+ '幫助對話' => NS_HELP_TALK,
 85+ '帮助讨论' => NS_HELP_TALK,
 86+ '幫助討論' => NS_HELP_TALK,
5087 '分类' => NS_CATEGORY,
 88+ '分類' => NS_CATEGORY,
 89+ '分类对话'=> NS_CATEGORY_TALK,
 90+ '分類對話' => NS_CATEGORY_TALK,
5191 '分类讨论'=> NS_CATEGORY_TALK,
52 - "分類" => NS_CATEGORY,
53 - "分類討論" => NS_CATEGORY_TALK,
 92+ '分類討論' => NS_CATEGORY_TALK,
5493 );
5594
5695 $messages = array(
Index: trunk/phase3/languages/messages/MessagesZh_hant.php
@@ -9,37 +9,40 @@
1010 * @author Shinjiman
1111 * @author Skjackey tse
1212 * @author Wrightbus
 13+ * @author Philip
1314 */
1415
1516 $fallback = 'zh-hans';
1617
1718 $namespaceNames = array(
18 - NS_MEDIA => 'Media',
19 - NS_SPECIAL => 'Special',
 19+ NS_MEDIA => '媒體',
 20+ NS_SPECIAL => '特殊',
2021 NS_MAIN => '',
21 - NS_TALK => 'Talk',
22 - NS_USER => 'User',
23 - NS_USER_TALK => 'User_talk',
 22+ NS_TALK => '討論',
 23+ NS_USER => '用戶',
 24+ NS_USER_TALK => '用戶討論',
2425 # NS_PROJECT set by $wgMetaNamespace
25 - NS_PROJECT_TALK => '$1_talk',
26 - NS_FILE => 'File',
27 - NS_FILE_TALK => 'File_talk',
 26+ NS_PROJECT_TALK => '$1討論',
 27+ NS_FILE => '檔案',
 28+ NS_FILE_TALK => '檔案討論',
2829 NS_MEDIAWIKI => 'MediaWiki',
29 - NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
30 - NS_TEMPLATE => 'Template',
31 - NS_TEMPLATE_TALK => 'Template_talk',
32 - NS_HELP => 'Help',
33 - NS_HELP_TALK => 'Help_talk',
34 - NS_CATEGORY => 'Category',
35 - NS_CATEGORY_TALK => 'Category_talk'
 30+ NS_MEDIAWIKI_TALK => 'MediaWiki討論',
 31+ NS_TEMPLATE => '模板',
 32+ NS_TEMPLATE_TALK => '模板討論',
 33+ NS_HELP => '幫助',
 34+ NS_HELP_TALK => '幫助討論',
 35+ NS_CATEGORY => '分類',
 36+ NS_CATEGORY_TALK => '分類討論'
3637 );
3738
3839 $namespaceAliases = array(
3940 "媒體" => NS_MEDIA,
4041 "特殊" => NS_SPECIAL,
4142 "對話" => NS_TALK,
 43+ "討論" => NS_USER_TALK,
4244 "用戶" => NS_USER,
4345 "用戶對話" => NS_USER_TALK,
 46+ "用戶討論" => NS_USER_TALK,
4447 # This has never worked so it's unlikely to annoy anyone if I disable it -- TS
4548 #"{{SITENAME}}_對話" => NS_PROJECT_TALK
4649 "圖像" => NS_FILE,
@@ -48,13 +51,22 @@
4952 'Image' => NS_FILE,
5053 'Image_talk' => NS_FILE_TALK,
5154 "圖像對話" => NS_FILE_TALK,
 55+ "圖像討論" => NS_FILE_TALK,
5256 "檔案對話" => NS_FILE_TALK,
 57+ "檔案討論" => NS_FILE_TALK,
5358 "文件對話" => NS_FILE_TALK,
 59+ "文件討論" => NS_FILE_TALK,
5460 "樣板" => NS_TEMPLATE,
 61+ "模板" => NS_TEMPLATE,
 62+ "樣板對話" => NS_TEMPLATE_TALK,
5563 "樣板討論" => NS_TEMPLATE_TALK,
 64+ "模板對話" => NS_TEMPLATE_TALK,
 65+ "模板討論" => NS_TEMPLATE_TALK,
5666 "幫助" => NS_HELP,
 67+ "幫助對話" => NS_HELP_TALK,
5768 "幫助討論" => NS_HELP_TALK,
5869 "分類" => NS_CATEGORY,
 70+ "分類對話" => NS_CATEGORY_TALK,
5971 "分類討論" => NS_CATEGORY_TALK,
6072 );
6173
Index: trunk/phase3/languages/classes/LanguageZh.php
@@ -34,7 +34,54 @@
3535 'zh-my' => '大马',
3636 );
3737 $this->mVariantNames = array_merge($this->mVariantNames,$names);
 38+ $this->loadNamespaceTables();
3839 }
 40+
 41+ function loadNamespaceTables() {
 42+ global $wgMetaNamespace;
 43+ $nsproject = $wgMetaNamespace;
 44+ $projecttable = array(
 45+ 'Wikipedia' => '维基百科',
 46+ 'Wikisource' => '维基文库',
 47+ 'Wikinews' => '维基新闻',
 48+ 'Wiktionary' => '维基词典',
 49+ 'Wikibooks' => '维基教科书',
 50+ 'Wikiquote' => '维基语录',
 51+ );
 52+ $this->mNamespaceTables['zh-hans'] = array(
 53+ 'Media' => '媒体',
 54+ 'Special' => '特殊',
 55+ 'Talk' => '讨论',
 56+ 'User' => '用户',
 57+ 'User Talk' => '用户讨论',
 58+ $nsproject
 59+ => isset($projecttable[$nsproject]) ?
 60+ $projecttable[$nsproject] : $nsproject,
 61+ $nsproject . ' talk'
 62+ => isset($projecttable[$nsproject]) ?
 63+ $projecttable[$nsproject] . '讨论' : $nsproject . '讨论',
 64+ 'File' => '文件',
 65+ 'File talk' => '文件讨论',
 66+ 'MediaWiki' => 'MediaWiki',
 67+ 'MediaWiki talk' => 'MediaWiki讨论',
 68+ 'Template' => '模板',
 69+ 'Template talk' => '模板讨论',
 70+ 'Help' => '帮助',
 71+ 'Help talk' => '帮助讨论',
 72+ 'Category' => '分类',
 73+ 'Category talk' => '分类讨论',
 74+ );
 75+ $this->mNamespaceTables['zh-hant'] = array_merge($this->mNamespaceTables['zh-hans']);
 76+ $this->mNamespaceTables['zh-hant']['File'] = '檔案';
 77+ $this->mNamespaceTables['zh-hant']['File talk'] = '檔案討論';
 78+ $this->mNamespaceTables['zh'] = array_merge($this->mNamespaceTables['zh-hans']);
 79+ $this->mNamespaceTables['zh-cn'] = array_merge($this->mNamespaceTables['zh-hans']);
 80+ $this->mNamespaceTables['zh-hk'] = array_merge($this->mNamespaceTables['zh-hant']);
 81+ $this->mNamespaceTables['zh-mo'] = array_merge($this->mNamespaceTables['zh-hant']);
 82+ $this->mNamespaceTables['zh-my'] = array_merge($this->mNamespaceTables['zh-hans']);
 83+ $this->mNamespaceTables['zh-sg'] = array_merge($this->mNamespaceTables['zh-hans']);
 84+ $this->mNamespaceTables['zh-tw'] = array_merge($this->mNamespaceTables['zh-hant']);
 85+ }
3986
4087 function loadDefaultTables() {
4188 require( dirname(__FILE__)."/../../includes/ZhConversion.php" );
Index: trunk/phase3/languages/LanguageConverter.php
@@ -23,6 +23,7 @@
2424 var $mTables;
2525 var $mManualAddTables;
2626 var $mManualRemoveTables;
 27+ var $mNamespaceTables;
2728 var $mTitleDisplay='';
2829 var $mDoTitleConvert=true, $mDoContentConvert=true;
2930 var $mManualLevel; // 'bidirectional' 'unidirectional' 'disable' for each variants
@@ -89,6 +90,7 @@
9091 :'bidirectional';
9192 $this->mManualAddTables[$v] = array();
9293 $this->mManualRemoveTables[$v] = array();
 94+ $this->mNamespaceTables[$v] = array();
9395 }
9496 }
9597
@@ -425,12 +427,28 @@
426428 $parser->mOutput->setTitleText( $this->mTitleDisplay );
427429 return $text;
428430 }
 431+
 432+ /**
 433+ * convert namespace
 434+ * @param string $title the title included namespace
 435+ * @return array of string
 436+ * @private
 437+ */
 438+ function convertNamespace( $title, $variant ) {
 439+ $splittitle = explode( ':', $title );
 440+ if (count($splittitle) < 2)
 441+ return $title;
 442+ if ( isset( $this->mNamespaceTables[$variant][$splittitle[0]] ) )
 443+ $splittitle[0] = $this->mNamespaceTables[$variant][$splittitle[0]];
 444+ $ret = implode(':', $splittitle );
 445+ return $ret;
 446+ }
429447
430448 /**
431 - * convert title
 449+ * convert title
432450 * @private
433451 */
434 - function convertTitle( $text ){
 452+ function convertTitle( $text, $variant ){
435453 global $wgDisableTitleConversion, $wgUser;
436454
437455 // check for global param and __NOTC__ tag
@@ -452,7 +470,8 @@
453471 if ( $isredir == 'no' || $action == 'edit' || $action == 'submit' || $linkconvert == 'no' ) {
454472 return $text;
455473 } else {
456 - $this->mTitleDisplay = $this->convert($text);
 474+ $text = $this->convertNamespace( $text, $variant );
 475+ $this->mTitleDisplay = $this->convert( $text );
457476 return $this->mTitleDisplay;
458477 }
459478 }
@@ -488,10 +507,11 @@
489508 if( $mw->matchStart( $text ) )
490509 return $text;
491510
 511+ $plang = $this->getPreferredVariant();
 512+
492513 // for title convertion
493 - if ( $isTitle ) return $this->convertTitle( $text );
 514+ if ( $isTitle ) return $this->convertTitle( $text, $plang );
494515
495 - $plang = $this->getPreferredVariant();
496516 $tarray = StringUtils::explode( $this->mMarkup['end'], $text );
497517 $text = '';
498518
Index: trunk/phase3/RELEASE-NOTES
@@ -84,6 +84,8 @@
8585 class "mw-searchresult"
8686 * (bug 15283) Interwiki imports can now fetch included templates
8787 * Treat svn:// URLs as external links by default
 88+* New function to convert namespace text for display (only applies on wiki with
 89+ LanguageConverter class)
8890
8991 === Bug fixes in 1.15 ===
9092 * (bug 16968) Special:Upload no longer throws useless warnings.

Comments

#Comment by Malafaya (talk | contribs)   16:26, 27 February 2009

It's suspected that this commit may have broken namespaces in the Gan Wikipedia (falling back to zh-hant). The Talk namespace seems to be pointing at User_Talk. (Try clicking on the talk page of an article)

#Comment by Siebrand (talk | contribs)   11:12, 1 March 2009

Possibly caused bugzilla:17726. Marking as FIXME for now.

#Comment by PhiLiP (talk | contribs)   12:52, 1 March 2009

Fixed in r47906.

Status & tagging log