Added optional setting to allow UI messages act as content.
authorZheng Zhu <zhengzhu@users.mediawiki.org>
Thu, 9 Dec 2004 03:00:49 +0000 (03:00 +0000)
committerZheng Zhu <zhengzhu@users.mediawiki.org>
Thu, 9 Dec 2004 03:00:49 +0000 (03:00 +0000)
includes/DefaultSettings.php
includes/GlobalFunctions.php
maintenance/InitialiseMessages.inc

index eb49b00..8ed7cad 100644 (file)
@@ -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.
  */
index 188e2c4..524ee08 100644 (file)
@@ -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 );
 }
 
 
index 1866e71..3e3b200 100755 (executable)
  * @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 );
 }