From: Zheng Zhu Date: Thu, 9 Dec 2004 03:00:49 +0000 (+0000) Subject: Added optional setting to allow UI messages act as content. X-Git-Tag: 1.5.0alpha1~1121 X-Git-Url: http://git.cyclocoop.org/wiki/Target_page?a=commitdiff_plain;h=b6f4bb64ea883bd0a556b791328d4b3a9de5063a;p=lhc%2Fweb%2Fwiklou.git Added optional setting to allow UI messages act as content. --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index eb49b00bea..8ed7cad222 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -865,6 +865,24 @@ $wgLoggedInGroupId = 2; $wgWhitelistRead = array ( ':Accueil', ':Main_Page'); +/* +When translating messages with wfMsg(), it is not always clear what should +be considered UI messages and what shoud be content messages. + +For example, for regular wikipedia site like en, there should be only one +'mainpage', therefore when getting the link of 'mainpage', we should +treate it as content of the site and call wfMsgForContent(), while for +rendering the text of the link, we call wfMsg(). The code in default +behaves this way. However, sites like common do offer different versions +of 'mainpage' and the like for different languages. This array provides a +way to override the default behavior. For example, to allow language specific +mainpage and community portal, set + +$wgForceUIMsgAsContentMsg = array( 'mainpage', 'portal-url' ); + +*/ +$wgForceUIMsgAsContentMsg = array(); + /** * Authentication plugin. */ diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 188e2c40eb..524ee08412 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -342,9 +342,14 @@ function wfMsg( $key ) { * Get a message from anywhere, for the content */ function wfMsgForContent( $key ) { + global $wgForceUIMsgAsContentMsg; $args = func_get_args(); array_shift( $args ); - return wfMsgReal( $key, $args, true, true ); + $forcontent = true; + if( is_array( $wgForceUIMsgAsContentMsg ) && + in_array( $key, $wgForceUIMsgAsContentMsg ) ) + $forcontent = false; + return wfMsgReal( $key, $args, true, $forcontent ); } /** @@ -360,9 +365,14 @@ function wfMsgNoDB( $key ) { * Get a message from the language file, for the content */ function wfMsgNoDBForContent( $key ) { + global $wgForceUIMsgAsContentMsg; $args = func_get_args(); array_shift( $args ); - return wfMsgReal( $key, $args, false, true ); + $forcontent = true; + if( is_array( $wgForceUIMsgAsContentMsg ) && + in_array( $key, $wgForceUIMsgAsContentMsg ) ) + $forcontent = false; + return wfMsgReal( $key, $args, false, $forcontent ); } diff --git a/maintenance/InitialiseMessages.inc b/maintenance/InitialiseMessages.inc index 1866e71546..3e3b200dfe 100755 --- a/maintenance/InitialiseMessages.inc +++ b/maintenance/InitialiseMessages.inc @@ -10,12 +10,14 @@ * @subpackage Maintenance */ - +require_once('languages/Names.php'); function initialiseMessages( $overwrite = false, $messageArray = false ) { global $wgContLang, $wgContLanguageCode; global $wgContLangClass, $wgAllMessagesEn; global $wgDisableLangConversion; + global $wgForceUIMsgAsContentMsg; + global $wgLanguageNames; global $IP; # overwrite language conversion option so that all variants @@ -51,6 +53,22 @@ function initialiseMessages( $overwrite = false, $messageArray = false ) { } } + /* + initialize all messages in $wgForceUIMsgAsContentMsg for all + languages in Names.php + */ + if( is_array( $wgForceUIMsgAsContentMsg ) ) { + foreach( $wgForceUIMsgAsContentMsg as $uikey ) { + foreach( $wgLanguageNames as $code => $name) { + if( $code == $wgContLanguageCode ) + continue; + $msg = $wgContLang->getMessage( $uikey ); + if( $msg ) + $messages[$uikey. '/' . $code] = $msg; + } + } + } + initialiseMessagesReal( $overwrite, $messages ); }