* (bug 15717) Set $separatorTransformTable for language 'eu'
[lhc/web/wiklou.git] / languages / Language.php
index bfef4e5..5648f6c 100644 (file)
@@ -39,7 +39,7 @@ class FakeConverter {
        function parserConvert($t, $p) {return $t;}
        function getVariants() { return array( $this->mLang->getCode() ); }
        function getPreferredVariant() {return $this->mLang->getCode(); }
-       function findVariantLink(&$l, &$n) {}
+       function findVariantLink(&$l, &$n, $forTemplate = false) {}
        function getExtraHashOptions() {return '';}
        function getParsedTitle() {return '';}
        function markNoConversion($text, $noParse=false) {return $text;}
@@ -57,15 +57,17 @@ class Language {
        var $mMagicExtensions = array(), $mMagicHookDone = false;
 
        static public $mLocalisationKeys = array( 'fallback', 'namespaceNames',
-               'skinNames', 'mathNames', 
-               'bookstoreList', 'magicWords', 'messages', 'rtl', 'digitTransformTable', 
+               'skinNames', 'mathNames',
+               'bookstoreList', 'magicWords', 'messages', 'rtl', 'digitTransformTable',
                'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension',
-               'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases', 
-               'dateFormats', 'datePreferences', 'datePreferenceMigrationMap', 
-               'defaultDateFormat', 'extraUserToggles', 'specialPageAliases' );
+               'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
+               'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
+               'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
+               'imageFiles'
+       );
 
-       static public $mMergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames', 
-               'dateFormats', 'defaultUserOptionOverrides', 'magicWords' );
+       static public $mMergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames',
+               'dateFormats', 'defaultUserOptionOverrides', 'magicWords', 'imageFiles' );
 
        static public $mMergeableListKeys = array( 'extraUserToggles' );
 
@@ -174,6 +176,15 @@ class Language {
                }
        }
 
+       /**
+        * Reduce memory usage
+        */
+       function __destruct() {
+               foreach ( $this as $name => $value ) {
+                       unset( $this->$name );
+               }
+       }
+
        /**
         * Hook which will be called if this is the content language.
         * Descendants can use this to register hook functions or modify globals
@@ -339,6 +350,11 @@ class Language {
                return $this->datePreferenceMigrationMap;
        }
 
+       function getImageFile( $image ) {
+               $this->load();
+               return $this->imageFiles[$image];
+       }
+
        function getDefaultUserOptionOverrides() {
                $this->load();
                # XXX - apparently some languageas get empty arrays, didn't get to it yet -- midom
@@ -386,21 +402,13 @@ class Language {
        }
 
        /**
-        * Ugly hack to get a message maybe from the MediaWiki namespace, if this
-        * language object is the content or user language.
+        * Get a message from the MediaWiki namespace.
+        *
+        * @param $msg String: message name
+        * @return string
         */
        function getMessageFromDB( $msg ) {
-               global $wgContLang, $wgLang;
-               if ( $wgContLang->getCode() == $this->getCode() ) {
-                       # Content language
-                       return wfMsgForContent( $msg );
-               } elseif ( $wgLang->getCode() == $this->getCode() ) {
-                       # User language
-                       return wfMsg( $msg );
-               } else {
-                       # Neither, get from localisation
-                       return $this->getMessage( $msg );
-               }
+               return wfMsgExt( $msg, array( 'parsemag', 'language' => $this ) );
        }
 
        function getLanguageName( $code ) {
@@ -904,6 +912,9 @@ class Language {
         * (abu-mami@kaluach.net, http://www.kaluach.net), who permitted
         * to translate the relevant functions into PHP and release them under
         * GNU GPL.
+        *
+        * The months are counted from Tishrei = 1. In a leap year, Adar I is 13
+        * and Adar II is 14. In a non-leap year, Adar is 6.
         */
        private static function tsToHebrew( $ts ) {
                # Parse date
@@ -1679,7 +1690,9 @@ class Language {
                        } else {
                                # Fall back to English if local list is incomplete
                                $magicWords =& Language::getMagicWords();
-                               if ( !isset($magicWords[$mw->mId]) ) { throw new MWException("Magic word not found" ); }
+                               if ( !isset($magicWords[$mw->mId]) ) {
+                                       throw new MWException("Magic word '{$mw->mId}' not found" ); 
+                               }
                                $rawEntry = $magicWords[$mw->mId];
                        }
                }
@@ -1731,14 +1744,14 @@ class Language {
 
                                // Fail fast
                                if ( !file_exists($file) )
-                                       throw new MWException( 'Aliases file does not exist' );
+                                       throw new MWException( "Aliases file does not exist: $file" );
 
                                $aliases = array();
                                require($file);
 
                                // Check the availability of aliases
                                if ( !isset($aliases['en']) )
-                                       throw new MWException( 'Malformed aliases file' );
+                                       throw new MWException( "Malformed aliases file: $file" );
 
                                // Merge all aliases in fallback chain
                                $code = $this->getCode();
@@ -1800,10 +1813,11 @@ class Language {
          * </code>
          *
          * See LanguageGu.php for the Gujarati implementation and
-         * LanguageIs.php for the , => . and . => , implementation.
+         * $separatorTransformTable on MessageIs.php for
+         * the , => . and . => , implementation.
          *
          * @todo check if it's viable to use localeconv() for the decimal
-         *       seperator thing.
+         *       separator thing.
          * @param $number Mixed: the string to be formatted, should be an integer
          *        or a floating point number.
          * @param $nocommafy Bool: set to true for special numbers like dates
@@ -1877,6 +1891,29 @@ class Language {
                }
                return $s;
        }
+       
+       /**
+        * Take a list of strings and build a locale-friendly comma-separated
+        * list, using the local comma-separator message.
+        * @param $list array of strings to put in a comma list
+        * @return string
+        */
+       function commaList( $list, $forContent = false ) {
+               return implode(
+                       $list,
+                       wfMsgExt( 'comma-separator', array( 'escapenoentities', 'language' => $this ) ) );
+       }
+       
+       /**
+        * Same as commaList, but separate it with the pipe instead.
+        * @param $list array of strings to put in a pipe list
+        * @return string
+        */
+       function pipeList( $list ) {
+               return implode(
+                       $list,
+                       wfMsgExt( 'pipe-separator', array( 'escapenoentities', 'language' => $this ) ) );
+       }
 
        /**
         * Truncate a string to a specified length in bytes, appending an optional
@@ -1960,7 +1997,7 @@ class Language {
                if ( !count($forms) ) { return ''; }
                $forms = $this->preConvertPlural( $forms, 2 );
 
-               return ( abs($count) == 1 ) ? $forms[0] : $forms[1];
+               return ( $count == 1 ) ? $forms[0] : $forms[1];
        }
 
        /**
@@ -2086,8 +2123,8 @@ class Language {
         * @param $nt Mixed: the title object of the link
         * @return null the input parameters may be modified upon return
         */
-       function findVariantLink( &$link, &$nt ) {
-               $this->mConverter->findVariantLink($link, $nt);
+       function findVariantLink( &$link, &$nt, $forTemplate = false ) {
+               $this->mConverter->findVariantLink($link, $nt, $forTemplate );
        }
 
        /**