From: Zheng Zhu Date: Sat, 25 Sep 2004 04:15:47 +0000 (+0000) Subject: first attempt to support multiple language variants in the MediaWiki: namespace. X-Git-Tag: 1.5.0alpha1~1809 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=ada3997051147a70a3ad864c6897381e2b427b10;p=lhc%2Fweb%2Fwiklou.git first attempt to support multiple language variants in the MediaWiki: namespace. --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index af18dfcd83..044848cae4 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -420,22 +420,29 @@ function wfMsgNoDBForContent( $key ) { */ function wfMsgReal( $key, $args, $useDB, $forContent=false ) { global $wgReplacementKeys, $wgParser, $wgMsgParserOptions; - + global $wgContLang, $wgLanguageCode; if($forContent) { - global $wgMessageCache, $wgContLang; + global $wgMessageCache; $cache = &$wgMessageCache; $lang = &$wgContLang; } else { - global $wgLang; - $cache = false; - $lang = &$wgLang; + if(in_array($wgLanguageCode, $wgContLang->getVariants())){ + global $wgLang, $wgMessageCache; + $cache = &$wgMessageCache; + $lang = $wgLang; + } + else { + global $wgLang; + $cache = false; + $lang = &$wgLang; + } } $fname = 'wfMsg'; wfProfileIn( $fname ); if ( is_object($cache) ) { - $message = $cache->get( $key, $useDB ); + $message = $cache->get( $key, $useDB, $forContent ); } elseif (is_object($lang)) { $message = $lang->getMessage( $key ); if(strstr($message, '{{' ) !== false) { diff --git a/includes/MessageCache.php b/includes/MessageCache.php index fd002f3fd6..e5a89e9453 100755 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -198,8 +198,17 @@ class MessageCache $this->mMemc->delete( $lockKey ); } - function get( $key, $useDB ) { - global $wgContLang, $wgContLanguageCode; + function get( $key, $useDB, $forcontent=true ) { + if($forcontent) { + global $wgContLang, $wgContLanguageCode; + $lang = $wgContLang; + $langcode = $wgContLanguageCode; + } + else { + global $wgLang, $wgLanguageCode; + $lang = $wgLang; + $langcode = $wgLanguageCode; + } # If uninitialised, someone is trying to call this halfway through Setup.php if ( !$this->mInitialised ) { return "<$key>"; @@ -207,7 +216,7 @@ class MessageCache $message = false; if ( !$this->mDisable && $useDB ) { - $title = $wgContLang->ucfirst( $key ); + $title = $lang->ucfirst( $key )."/$langcode"; # Try the cache @@ -234,12 +243,12 @@ class MessageCache # Try the array in the language object if ( !$message ) { wfSuppressWarnings(); - $message = $wgContLang->getMessage( $key ); + $message = $lang->getMessage( $key ); wfRestoreWarnings(); } # Try the English array - if ( !$message && $wgContLanguageCode != 'en' ) { + if ( !$message && $langcode != 'en' ) { wfSuppressWarnings(); $message = Language::getMessage( $key ); wfRestoreWarnings(); diff --git a/includes/Setup.php b/includes/Setup.php index 60b7f9e44f..bf574bc676 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -78,6 +78,7 @@ $wgRequest = new WebRequest(); wfProfileOut( $fname.'-includes' ); wfProfileIn( $fname.'-misc1' ); global $wgUser, $wgLang, $wgContLang, $wgOut, $wgTitle; +global $wgLangClass, $wgContLangClass; global $wgArticle, $wgDeferredUpdateList, $wgLinkCache; global $wgMemc, $wgMagicWords, $wgMwRedir, $wgDebugLogFile; global $wgMessageCache, $wgUseMemCached, $wgUseDatabaseMessages; diff --git a/includes/SpecialAllmessages.php b/includes/SpecialAllmessages.php index dd506e7798..6e0e7a924b 100644 --- a/includes/SpecialAllmessages.php +++ b/includes/SpecialAllmessages.php @@ -10,7 +10,7 @@ */ function wfSpecialAllmessages() { global $wgOut, $wgAllMessagesEn, $wgRequest, $wgMessageCache, $wgTitle; - + global $wgLanguageCode, $wgContLanguageCode, $wgContLang; $fname = "wfSpecialAllMessages"; wfProfileIn( $fname ); @@ -19,6 +19,14 @@ function wfSpecialAllmessages() { $mwMsg =& MagicWord::get( MAG_MSG ); $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) ); + + if($wgLanguageCode != $wgContLanguageCode && + !in_array($wgLanguageCode, $wgContLang->getVariants())) { + $err = wfMsg('allmessagesnotsupported'); + $wgOut->addHTML( $err ); + return; + } + $first = true; $sortedArray = $wgAllMessagesEn; ksort( $sortedArray ); @@ -27,8 +35,8 @@ function wfSpecialAllmessages() { foreach ( $sortedArray as $key => $enMsg ) { $messages[$key]['enmsg'] = $enMsg; - $messages[$key]['statmsg'] = wfMsgNoDbForContent( $key ); - $messages[$key]['msg'] = wfMsgForContent ( $key ); + $messages[$key]['statmsg'] = wfMsgNoDb( $key ); + $messages[$key]['msg'] = wfMsg ( $key ); } $wgMessageCache->enableTransform(); @@ -79,7 +87,7 @@ function makePhp($messages) { * */ function makeHTMLText( $messages ) { - global $wgLang, $wgUser; + global $wgLang, $wgUser, $wgLanguageCode; $fname = "makeHTMLText"; wfProfileIn( $fname ); @@ -114,7 +122,8 @@ function makeHTMLText( $messages ) { wfProfileIn( "$fname-output" ); foreach( $messages as $key => $m ) { - $title = $wgLang->ucfirst( $key ); + + $title = $wgLang->ucfirst( $key )."/$wgLanguageCode"; $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title ); $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title ); diff --git a/languages/Language.php b/languages/Language.php index ee7ea8e351..cedbba2927 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1398,6 +1398,7 @@ article [[Train]]. 'allmessages' => 'All system messages', 'allmessagestext' => 'This is a list of all system messages available in the MediaWiki: namespace.', +'allmessagesnotsupported' => 'Your current interface language is not supported by Special:AllMessages at this site', # Thumbnails diff --git a/languages/LanguageZh.php b/languages/LanguageZh.php index 2034e1fd45..f7b3b3ea2e 100644 --- a/languages/LanguageZh.php +++ b/languages/LanguageZh.php @@ -1,5 +1,6 @@ get($key1 = "$wgDBname:zhConvert:s2t"); diff --git a/maintenance/InitialiseMessages.inc b/maintenance/InitialiseMessages.inc index 64889477cc..b3810c91e2 100755 --- a/maintenance/InitialiseMessages.inc +++ b/maintenance/InitialiseMessages.inc @@ -12,8 +12,50 @@ * @subpackage Maintenance */ -/** */ + + function initialiseMessages( $overwrite = false, $messageArray = false ) { + global $wgContLang, $wgContLanguageCode; + global $wgContLangClass, $wgAllMessagesEn; + + $langclass = 'Language'. str_replace( '-', '_', ucfirst( $wgContLanguageCode ) ); + require_once("languages/$langclass.php"); + + $variants = $wgContLang->getVariants(); + if(!in_array($wgContLanguageCode, $variants)) + $variants[]=$wgContLanguageCode; + + if ( $messageArray ) { + $sortedArray = $messageArray; + } else { + $sortedArray = $wgAllMessagesEn; + } + + ksort( $sortedArray ); + + $messages=array(); + foreach ($variants as $v) { + $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) ); + $lang = new $langclass; + if(!is_object($lang)) { + die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?"); + } + foreach ($sortedArray as $key => $msg) { + $messages[$key."/$v"] = $lang->getMessage($key); + } + } + + initialiseMessagesReal( $overwrite, $messages ); +} + + + + + + + +/** */ +function initialiseMessagesReal( $overwrite = false, $messageArray = false ) { global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn; global $wgOut, $wgArticle, $wgUser; global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;