more fixes for languages with no language files; allow UI customization for all langu...
authorZheng Zhu <zhengzhu@users.mediawiki.org>
Tue, 7 Dec 2004 20:22:22 +0000 (20:22 +0000)
committerZheng Zhu <zhengzhu@users.mediawiki.org>
Tue, 7 Dec 2004 20:22:22 +0000 (20:22 +0000)
includes/GlobalFunctions.php
includes/Setup.php
includes/SpecialAllmessages.php
includes/SpecialPreferences.php
languages/Language.php
maintenance/InitialiseMessages.inc

index 943fe15..188e2c4 100644 (file)
@@ -378,46 +378,16 @@ function wfMsgReal( $key, $args, $useDB, $forContent=false ) {
        $fname = 'wfMsgReal';
        wfProfileIn( $fname );
 
-       if( $forContent ) {
-               /**
-                * Message is needed for page content, and needs
-                * to be consistent with the site's configured
-                * language. It might be part of a page title,
-                * or a link, or text that will go into the
-                * parser cache and be served back to other 
-                * visitors.
-                */
-               $cache = &$wgMessageCache;
-               $lang = &$wgContLang;
-       } else {
-               /**
-                * Message is for display purposes only.
-                * The user may have selected a conversion-based
-                * language variant or a separate user interface
-                * language; if so use that.
-                */
-               if ( is_object( $wgContLang ) ) {
-                       if( in_array( $wgLanguageCode, $wgContLang->getVariants() ) ) {
-                               $cache = &$wgMessageCache;
-                               $lang = &$wgLang;
-                       } else {
-                               $cache = false;
-                               $lang = &$wgLang;
-                       }
+       if( is_object( $wgMessageCache ) ) {
+               $message = $wgMessageCache->get( $key, $useDB, $forContent );
+    }
+       else {
+               if( $forContent ) {
+                       $lang = &$wgContLang;
                } else {
-                       $cache = false;
-                       $lang = false;
+                       $lang = &$wgLang;
                }
-       }
-
 
-       if( is_object( $cache ) ) {
-               $message = $cache->get( $key, $useDB, $forContent );
-       } else {
-               if ( !is_object( $lang ) ) {
-                       $lang = new Language;
-               }
-       
                wfSuppressWarnings();
                $message = $lang->getMessage( $key );
                wfRestoreWarnings();
index 1f351c3..d609498 100644 (file)
@@ -239,28 +239,29 @@ if( $wgCommandLineMode ) {
 wfProfileOut( $fname.'-User' );
 wfProfileIn( $fname.'-language2' );
 
-function setupLangObj(&$langclass, $langcode) {
+function setupLangObj(&$langclass) {
        global $wgUseLatin1, $IP;
 
-
        if( ! class_exists( $langclass ) ) {
-               # Default to English/UTF-8
-               require_once( "$IP/languages/LanguageUtf8.php" );
-               $langclass = 'LanguageUtf8';
+               # Default to English/UTF-8, or for non-UTF-8, to latin-1
+               $baseclass = 'LanguageUtf8';
+               if( $wgUseLatin1 )
+                       $baseclass = 'LanguageLatin1';
+               require_once( "$IP/languages/$baseclass.php" );
+               $lc = strtolower(substr($langclass, 8));
+               $snip = "
+                       class $langclass extends $baseclass {
+                               function getVariants() {
+                                       return array(\"$lc\");
+                               }
+
+                       }";
+
+               eval($snip);
        }
 
        $lang = new $langclass();
-       if ( !is_object($lang) ) {
-               print "No language class ($wgLang)\N";
-       }
 
-       if( $wgUseLatin1 ) {
-               # For non-UTF-8 latin-1 downconversion
-               require_once( "$IP/languages/LanguageLatin1.php" );
-               $xxx = new LanguageLatin1( $lang );
-               unset( $lang );
-               $lang = $xxx;
-       }
        return $lang;
 }
 
@@ -270,8 +271,7 @@ function setupLangObj(&$langclass, $langcode) {
 $wgContLanguageCode = $wgLanguageCode;
 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
 
-$wgContLang = setupLangObj( $wgContLangClass, $wgContLangClass );
-$n = get_class($wgContLang);
+$wgContLang = setupLangObj( $wgContLangClass );
 
 // set default user option from content language
 if( !$wgUser->mDataLoaded ) {
@@ -286,10 +286,12 @@ $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
 if( $wgLangClass == $wgContLangClass ) {
        $wgLang = &$wgContLang;
 } else {
-       require_once("$IP/languages/$wgLangClass.php");
-       $wgLang = setupLangObj( $wgLangClass, $wgLanguageCode );
-}
+       wfSuppressWarnings();
+       include_once("$IP/languages/$wgLangClass.php");
+       wfRestoreWarnings();
 
+       $wgLang = setupLangObj( $wgLangClass );
+}
 
 wfProfileOut( $fname.'-language' );
 wfProfileIn( $fname.'-MessageCache' );
index 1fe5408..a58f9f0 100644 (file)
@@ -13,12 +13,6 @@ function wfSpecialAllmessages() {
        global $wgLanguageCode, $wgContLanguageCode, $wgContLang;
        global $wgUseDatabaseMessages;
 
-       if($wgLanguageCode != $wgContLanguageCode &&
-               !in_array($wgLanguageCode, $wgContLang->getVariants())) {
-               $err = wfMsg('allmessagesnotsupportedUI', $wgLanguageCode);
-               $wgOut->addHTML( $err );
-               return;
-       }
        if(!$wgUseDatabaseMessages) {
                $wgOut->addHTML(wfMsg('allmessagesnotsupportedDB'));
                return;
@@ -94,7 +88,7 @@ function makePhp($messages) {
  *
  */
 function makeHTMLText( $messages ) {
-       global $wgLang, $wgUser, $wgLanguageCode, $wgContLanguageCode;
+       global $wgLang, $wgUser, $wgLanguageCode, $wgContLanguageCode, $wgContLang;
        $fname = "makeHTMLText";
        wfProfileIn( $fname );
        
@@ -128,11 +122,13 @@ function makeHTMLText( $messages ) {
        wfProfileOut( "$fname-check" );
 
        wfProfileIn( "$fname-output" );
+
        foreach( $messages as $key => $m ) {
 
                $title = $wgLang->ucfirst( $key );
                if($wgLanguageCode != $wgContLanguageCode)
                        $title.="/$wgLanguageCode";
+
                $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
                $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
 
index dbb452d..962cc33 100644 (file)
@@ -323,7 +323,7 @@ class PreferencesForm {
                global $wgUser, $wgOut, $wgLang, $wgContLang, $wgUseDynamicDates, $wgValidSkinNames;
                global $wgAllowRealName, $wgImageLimits;
                global $wgLanguageNames, $wgDisableLangConversion;
-
+               global $wgContLanguageCode;
                $wgOut->setPageTitle( wfMsg( 'preferences' ) );
                $wgOut->setArticleRelated( false );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
@@ -417,7 +417,7 @@ class PreferencesForm {
                        global $IP;
                        /* only add languages that have a file */
                        $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php";
-                       if(file_exists($langfile)) {
+                       if(file_exists($langfile) || $code == $wgContLanguageCode) {
                                $sel = ($code == $this->mUserLanguage)? 'selected="selected"' : '';
                                $wgOut->addHtml("\t<option value=\"$code\" $sel>$code - $name</option>\n");
                        }
index 329a4d1..1b95b97 100644 (file)
@@ -2184,20 +2184,14 @@ class Language {
                // utf8 if the language does not have a language file)
                $v = $this->getVariants();
                if( !empty( $v ) ) {
-                       foreach ($v as $v2) {
-                               if($v2 != 'utf8') {
-                                       $lang = $v2;
-                                       break;
-                               }
-                       }
+                       return $v[0];
                }
                if($lang != '')
                        return $lang;
 
                // get it from the class name
                $lang = strtolower( substr( get_class( $this ), 8 ) );
-               if($lang == 'utf8')
-                       $lang = 'en';
+
                return $lang;
        }
 
index 9a9ea04..1866e71 100755 (executable)
@@ -19,7 +19,7 @@ function initialiseMessages( $overwrite = false, $messageArray = false ) {
        global $IP;
 
        # overwrite language conversion option so that all variants 
-       # of the selected language are initialised
+       # of the messages are initialised
        $wgDisableLangConversion = false;
 
        if ( $messageArray ) {
@@ -31,35 +31,25 @@ function initialiseMessages( $overwrite = false, $messageArray = false ) {
        ksort( $sortedArray );
        $messages=array();
 
-       /* check special case where the language does 
-          not have a language file 
-       */
-       if( get_class($wgContLang) != 'language'.strtolower($wgContLanguageCode) ) {
+       $variants = $wgContLang->getVariants();
+       if(!in_array($wgContLanguageCode, $variants))
+               $variants[]=$wgContLanguageCode;
+
+       foreach ($variants as $v) {
+               $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
+               if( !class_exists($langclass) ) {
+                       die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
+               }
+               $lang = new $langclass;
+
+               if($v==$wgContLanguageCode)
+                       $suffix='';
+               else
+                       $suffix="/$v";
                foreach ($sortedArray as $key => $msg) {
-                       $messages[$key] = $wgContLang->getMessage($key);
+                       $messages[$key.$suffix] = $lang->getMessage($key);
                }
        }
-       else {
-               $variants = $wgContLang->getVariants();
-               if(!in_array($wgContLanguageCode, $variants))
-                       $variants[]=$wgContLanguageCode;
-
-               foreach ($variants as $v) {
-                       $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
-                       if( !class_exists($langclass) ) {
-                               die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
-                       }
-                       $lang = new $langclass;
-
-                       if($v==$wgContLanguageCode)
-                               $suffix='';
-                       else
-                               $suffix="/$v";
-                       foreach ($sortedArray as $key => $msg) {
-                               $messages[$key.$suffix] = $lang->getMessage($key);
-                       }
-               }
-       }       
 
        initialiseMessagesReal( $overwrite, $messages );
 }