favicon fix
[lhc/web/wiklou.git] / languages / Language.php
index 990fed5..a32b374 100644 (file)
@@ -70,7 +70,7 @@ class Language {
                'defaultDateFormat', 'extraUserToggles' );
 
        static public $mMergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames', 
-               'dateFormats', 'defaultUserOptionOverrides' );
+               'dateFormats', 'defaultUserOptionOverrides', 'magicWords' );
 
        static public $mMergeableListKeys = array( 'extraUserToggles' );
 
@@ -120,7 +120,7 @@ class Language {
                        }
                }
 
-               if ( $recursionLevel > 50 ) {
+               if ( $recursionLevel > 5 ) {
                        throw new MWException( "Language fallback loop detected when creating class $class\n" );
                }       
 
@@ -244,7 +244,7 @@ class Language {
         * @return string
         */
        function getVariantname( $code ) {
-               return wfMsg( "variantname-$code" );
+               return $this->getMessageFromDB( "variantname-$code" );
        }
 
        function specialPage( $name ) {
@@ -276,6 +276,11 @@ class Language {
                return $this->dateFormats;
        }
 
+       function getDefaultDateFormat() {
+               $this->load();
+               return $this->defaultDateFormat;
+       }
+
        function getDatePreferenceMigrationMap() {
                $this->load();
                return $this->datePreferenceMigrationMap;
@@ -292,7 +297,7 @@ class Language {
        }
 
        function getUserToggle( $tog ) {
-               return wfMsg( "tog-$tog" );
+               return $this->getMessageFromDB( "tog-$tog" );
        }
 
        /**
@@ -320,8 +325,8 @@ class Language {
        }
 
        /**
-        * Ugly hack to get a message maybe from the MediaWiki namespace, if this 
-        * language object is the content or user language. 
+        * Ugly hack to get a message maybe from the MediaWiki namespace, if this
+        * language object is the content or user language.
         */
        function getMessageFromDB( $msg ) {
                global $wgContLang, $wgLang;
@@ -571,11 +576,11 @@ class Language {
 
        /**
         * Calculate the day of the week for a 14-character timestamp
-        * 0 for Sunday through to 6 for Saturday
+        * 1 for Sunday through to 7 for Saturday
         * This takes about 100us on a slow computer
         */
        static function calculateWeekday( $ts ) {
-               return date( 'w', wfTimestamp( TS_UNIX, $ts ) );
+               return date( 'w', wfTimestamp( TS_UNIX, $ts ) ) + 1;
        }
 
        /**
@@ -760,7 +765,7 @@ class Language {
        }
 
        function isMultibyte( $str ) {
-               return (bool)preg_match( '/^[\x80-\xff]/', $str );
+               return (bool)preg_match( '/[\x80-\xff]/', $str );
        }
 
        function checkTitleEncoding( $s ) {
@@ -884,16 +889,27 @@ class Language {
         *
         * @return string
         */
-       function getDirMark() { return $this->isRTL() ? "\xE2\x80\x8F" : "\xE2\x80\x8E"; }
+       function getDirMark() {
+               return $this->isRTL() ? "\xE2\x80\x8F" : "\xE2\x80\x8E";
+       }
+
+       /**
+        * An arrow, depending on the language direction
+        *
+        * @return string
+        */
+       function getArrow() {
+               return $this->isRTL() ? '←' : '→';
+       }
 
        /**
         * To allow "foo[[bar]]" to extend the link over the whole word "foobar"
         *
         * @return bool
         */
-       function linkPrefixExtension() { 
+       function linkPrefixExtension() {
                $this->load();
-               return $this->linkPrefixExtension; 
+               return $this->linkPrefixExtension;
        }
 
        function &getMagicWords() {
@@ -1010,7 +1026,7 @@ class Language {
                        if ($i == $m) {
                                $s = $l[$i];
                        } else if ($i == $m - 1) {
-                               $s = $l[$i] . ' ' . wfMsg('and') . ' ' . $s;
+                               $s = $l[$i] . ' ' . $this->getMessageFromDB( 'and' ) . ' ' . $s;
                        } else {
                                $s = $l[$i] . ', ' . $s;
                        }
@@ -1101,7 +1117,7 @@ class Language {
         */
        function translateBlockExpiry( $str ) {
 
-               $scBlockExpiryOptions = wfMsg( 'ipboptions' );
+               $scBlockExpiryOptions = $this->getMessageFromDB( 'ipboptions' );
 
                if ( $scBlockExpiryOptions == '-') {
                        return $str;
@@ -1346,7 +1362,7 @@ class Language {
                                throw new MWException( "Error: Circular fallback reference in language code $code" );
                        }
                        $recursionGuard[$code] = true;
-                       $newDeps = self::loadLocalisation( $fallback );
+                       $newDeps = self::loadLocalisation( $fallback, $disableCache );
                        unset( $recursionGuard[$code] );
 
                        $secondary = self::$mLocalisationCache[$fallback];
@@ -1428,6 +1444,14 @@ class Language {
                return self::$mLocalisationCache[$code]['messages'];
        }
 
+       /** 
+        * Get a message for a given language
+        */
+       static function getMessageFor( $key, $code ) {
+               self::loadLocalisation( $code );
+               return @self::$mLocalisationCache[$code]['messages'][$key];
+       }
+
        /**
         * Load localisation data for this object
         */
@@ -1466,11 +1490,9 @@ class Language {
                        # Allowing full message-style parsing would make simple requests 
                        # such as action=raw much more expensive than they need to be. 
                        # This will hopefully cover most cases.
-                       if ( preg_match( '/{{grammar:(.*?)\|(.*?)}}/i', $talk, $m ) ) {
-                               $talk = str_replace( ' ', '_', 
-                                       $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) )
-                               );
-                       }
+                       $talk = preg_replace_callback( '/{{grammar:(.*?)\|(.*?)}}/i', 
+                               array( &$this, 'replaceGrammarInNamespace' ), $talk );
+                       $talk = str_replace( ' ', '_', $talk );
                        $this->namespaceNames[NS_PROJECT_TALK] = $talk;
                }
                
@@ -1503,6 +1525,10 @@ class Language {
                wfProfileOut( __METHOD__ );
        }
 
+       function replaceGrammarInNamespace( $m ) {
+               return $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) );
+       }
+
        static function getCaseMaps() {
                static $wikiUpperChars, $wikiLowerChars;
                global $IP;
@@ -1522,6 +1548,4 @@ class Language {
        }
 }
 
-/** @deprecated */
-class LanguageUtf8 extends Language {}
 ?>