r5478 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5477‎ | r5478 | r5479 >
Date:04:15, 25 September 2004
Author:zhengzhu
Status:old
Tags:
Comment:
first attempt to support multiple language variants in the MediaWiki: namespace.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/MessageCache.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/SpecialAllmessages.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/LanguageZh.php (modified) (history)
  • /trunk/phase3/maintenance/InitialiseMessages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/InitialiseMessages.inc
@@ -12,8 +12,50 @@
1313 * @subpackage Maintenance
1414 */
1515
 16+
 17+
 18+function initialiseMessages( $overwrite = false, $messageArray = false ) {
 19+ global $wgContLang, $wgContLanguageCode;
 20+ global $wgContLangClass, $wgAllMessagesEn;
 21+
 22+ $langclass = 'Language'. str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
 23+ require_once("languages/$langclass.php");
 24+
 25+ $variants = $wgContLang->getVariants();
 26+ if(!in_array($wgContLanguageCode, $variants))
 27+ $variants[]=$wgContLanguageCode;
 28+
 29+ if ( $messageArray ) {
 30+ $sortedArray = $messageArray;
 31+ } else {
 32+ $sortedArray = $wgAllMessagesEn;
 33+ }
 34+
 35+ ksort( $sortedArray );
 36+
 37+ $messages=array();
 38+ foreach ($variants as $v) {
 39+ $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
 40+ $lang = new $langclass;
 41+ if(!is_object($lang)) {
 42+ die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
 43+ }
 44+ foreach ($sortedArray as $key => $msg) {
 45+ $messages[$key."/$v"] = $lang->getMessage($key);
 46+ }
 47+ }
 48+
 49+ initialiseMessagesReal( $overwrite, $messages );
 50+}
 51+
 52+
 53+
 54+
 55+
 56+
 57+
1658 /** */
17 -function initialiseMessages( $overwrite = false, $messageArray = false ) {
 59+function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
1860 global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn;
1961 global $wgOut, $wgArticle, $wgUser;
2062 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
Index: trunk/phase3/includes/SpecialAllmessages.php
@@ -10,7 +10,7 @@
1111 */
1212 function wfSpecialAllmessages() {
1313 global $wgOut, $wgAllMessagesEn, $wgRequest, $wgMessageCache, $wgTitle;
14 -
 14+ global $wgLanguageCode, $wgContLanguageCode, $wgContLang;
1515 $fname = "wfSpecialAllMessages";
1616 wfProfileIn( $fname );
1717
@@ -19,6 +19,14 @@
2020 $mwMsg =& MagicWord::get( MAG_MSG );
2121
2222 $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) );
 23+
 24+ if($wgLanguageCode != $wgContLanguageCode &&
 25+ !in_array($wgLanguageCode, $wgContLang->getVariants())) {
 26+ $err = wfMsg('allmessagesnotsupported');
 27+ $wgOut->addHTML( $err );
 28+ return;
 29+ }
 30+
2331 $first = true;
2432 $sortedArray = $wgAllMessagesEn;
2533 ksort( $sortedArray );
@@ -27,8 +35,8 @@
2836
2937 foreach ( $sortedArray as $key => $enMsg ) {
3038 $messages[$key]['enmsg'] = $enMsg;
31 - $messages[$key]['statmsg'] = wfMsgNoDbForContent( $key );
32 - $messages[$key]['msg'] = wfMsgForContent ( $key );
 39+ $messages[$key]['statmsg'] = wfMsgNoDb( $key );
 40+ $messages[$key]['msg'] = wfMsg ( $key );
3341 }
3442
3543 $wgMessageCache->enableTransform();
@@ -79,7 +87,7 @@
8088 *
8189 */
8290 function makeHTMLText( $messages ) {
83 - global $wgLang, $wgUser;
 91+ global $wgLang, $wgUser, $wgLanguageCode;
8492 $fname = "makeHTMLText";
8593 wfProfileIn( $fname );
8694
@@ -114,7 +122,8 @@
115123
116124 wfProfileIn( "$fname-output" );
117125 foreach( $messages as $key => $m ) {
118 - $title = $wgLang->ucfirst( $key );
 126+
 127+ $title = $wgLang->ucfirst( $key )."/$wgLanguageCode";
119128 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
120129 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
121130
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -420,22 +420,29 @@
421421 */
422422 function wfMsgReal( $key, $args, $useDB, $forContent=false ) {
423423 global $wgReplacementKeys, $wgParser, $wgMsgParserOptions;
424 -
 424+ global $wgContLang, $wgLanguageCode;
425425 if($forContent) {
426 - global $wgMessageCache, $wgContLang;
 426+ global $wgMessageCache;
427427 $cache = &$wgMessageCache;
428428 $lang = &$wgContLang;
429429 }
430430 else {
431 - global $wgLang;
432 - $cache = false;
433 - $lang = &$wgLang;
 431+ if(in_array($wgLanguageCode, $wgContLang->getVariants())){
 432+ global $wgLang, $wgMessageCache;
 433+ $cache = &$wgMessageCache;
 434+ $lang = $wgLang;
 435+ }
 436+ else {
 437+ global $wgLang;
 438+ $cache = false;
 439+ $lang = &$wgLang;
 440+ }
434441 }
435442
436443 $fname = 'wfMsg';
437444 wfProfileIn( $fname );
438445 if ( is_object($cache) ) {
439 - $message = $cache->get( $key, $useDB );
 446+ $message = $cache->get( $key, $useDB, $forContent );
440447 } elseif (is_object($lang)) {
441448 $message = $lang->getMessage( $key );
442449 if(strstr($message, '{{' ) !== false) {
Index: trunk/phase3/includes/MessageCache.php
@@ -198,8 +198,17 @@
199199 $this->mMemc->delete( $lockKey );
200200 }
201201
202 - function get( $key, $useDB ) {
203 - global $wgContLang, $wgContLanguageCode;
 202+ function get( $key, $useDB, $forcontent=true ) {
 203+ if($forcontent) {
 204+ global $wgContLang, $wgContLanguageCode;
 205+ $lang = $wgContLang;
 206+ $langcode = $wgContLanguageCode;
 207+ }
 208+ else {
 209+ global $wgLang, $wgLanguageCode;
 210+ $lang = $wgLang;
 211+ $langcode = $wgLanguageCode;
 212+ }
204213 # If uninitialised, someone is trying to call this halfway through Setup.php
205214 if ( !$this->mInitialised ) {
206215 return "<$key>";
@@ -207,7 +216,7 @@
208217
209218 $message = false;
210219 if ( !$this->mDisable && $useDB ) {
211 - $title = $wgContLang->ucfirst( $key );
 220+ $title = $lang->ucfirst( $key )."/$langcode";
212221
213222
214223 # Try the cache
@@ -234,12 +243,12 @@
235244 # Try the array in the language object
236245 if ( !$message ) {
237246 wfSuppressWarnings();
238 - $message = $wgContLang->getMessage( $key );
 247+ $message = $lang->getMessage( $key );
239248 wfRestoreWarnings();
240249 }
241250
242251 # Try the English array
243 - if ( !$message && $wgContLanguageCode != 'en' ) {
 252+ if ( !$message && $langcode != 'en' ) {
244253 wfSuppressWarnings();
245254 $message = Language::getMessage( $key );
246255 wfRestoreWarnings();
Index: trunk/phase3/includes/Setup.php
@@ -78,6 +78,7 @@
7979 wfProfileOut( $fname.'-includes' );
8080 wfProfileIn( $fname.'-misc1' );
8181 global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle;
 82+global $wgLangClass, $wgContLangClass;
8283 global $wgArticle, $wgDeferredUpdateList, $wgLinkCache;
8384 global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile;
8485 global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages;
Index: trunk/phase3/languages/Language.php
@@ -1398,6 +1398,7 @@
13991399
14001400 'allmessages' => 'All system messages',
14011401 'allmessagestext' => 'This is a list of all system messages available in the MediaWiki: namespace.',
 1402+'allmessagesnotsupported' => 'Your current interface language is not supported by Special:AllMessages at this site',
14021403
14031404 # Thumbnails
14041405
Index: trunk/phase3/languages/LanguageZh.php
@@ -1,5 +1,6 @@
22 <?php
33 require_once( "LanguageZh_cn.php");
 4+require_once( "LanguageZh_tw.php");
45
56 /* caching the conversion tables */
67 $zhSimp2Trad = $wgMemc->get($key1 = "$wgDBname:zhConvert:s2t");

Status & tagging log