Localisation updates from Betawiki.
[lhc/web/wiklou.git] / languages / Language.php
index dacb2aa..338c348 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /**
- * @package MediaWiki
- * @subpackage Language
+ * @addtogroup Language
  */
 
 if( !defined( 'MEDIAWIKI' ) ) {
@@ -9,21 +8,9 @@ if( !defined( 'MEDIAWIKI' ) ) {
        exit( 1 );
 }
 
-#
-# In general you should not make customizations in these language files
-# directly, but should use the MediaWiki: special namespace to customize
-# user interface messages through the wiki.
-# See http://meta.wikipedia.org/wiki/MediaWiki_namespace
-#
-# NOTE TO TRANSLATORS: Do not copy this whole file when making translations!
-# A lot of common constants and a base class with inheritable methods are
-# defined here, which should not be redefined. See the other LanguageXx.php
-# files for examples.
-#
-
 # Read language names
 global $wgLanguageNames;
-require_once( 'Names.php' );
+require_once( dirname(__FILE__) . '/Names.php' ) ;
 
 global $wgInputEncoding, $wgOutputEncoding;
 
@@ -51,7 +38,7 @@ class FakeConverter {
        function markNoConversion($text, $noParse=false) {return $text;}
        function convertCategoryKey( $key ) {return $key; }
        function convertLinkToAllVariants($text){ return array( $this->mLang->getCode() => $text); }
-       function setNoTitleConvert(){}
+       function armourMath($text){ return $text; }
 }
 
 #--------------------------------------------------------------------------
@@ -60,9 +47,10 @@ class FakeConverter {
 
 class Language {
        var $mConverter, $mVariants, $mCode, $mLoaded = false;
+       var $mMagicExtensions = array(), $mMagicHookDone = false;
 
        static public $mLocalisationKeys = array( 'fallback', 'namespaceNames',
-               'quickbarSettings', 'skinNames', 'mathNames', 
+               'skinNames', 'mathNames', 
                'bookstoreList', 'magicWords', 'messages', 'rtl', 'digitTransformTable', 
                'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension',
                'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases', 
@@ -102,6 +90,13 @@ class Language {
                'sep', 'oct', 'nov', 'dec'
        );
 
+       static public $mIranianCalendarMonthMsgs = array(
+               'iranian-calendar-m1', 'iranian-calendar-m2', 'iranian-calendar-m3',
+               'iranian-calendar-m4', 'iranian-calendar-m5', 'iranian-calendar-m6',
+               'iranian-calendar-m7', 'iranian-calendar-m8', 'iranian-calendar-m9',
+               'iranian-calendar-m10', 'iranian-calendar-m11', 'iranian-calendar-m12'
+       );
+
        /**
         * Create a language object for a given language code
         */
@@ -163,6 +158,11 @@ class Language {
                return User::getDefaultOptions();
        }
 
+       function getFallbackLanguageCode() {
+               $this->load();
+               return $this->fallback;
+       }
+
        /**
         * Exports $wgBookstoreListEn
         * @return array
@@ -224,7 +224,22 @@ class Language {
        }
 
        /**
-        * Get a namespace key by value, case insensetive.
+        * Get a namespace key by value, case insensitive.
+        * Only matches namespace names for the current language, not the
+        * canonical ones defined in Namespace.php.
+        *
+        * @param string $text
+        * @return mixed An integer if $text is a valid value otherwise false
+        */
+       function getLocalNsIndex( $text ) {
+               $this->load();
+               $lctext = $this->lc($text);
+               return isset( $this->mNamespaceIds[$lctext] ) ? $this->mNamespaceIds[$lctext] : false;
+       }
+
+       /**
+        * Get a namespace key by value, case insensitive.  Canonical namespace
+        * names override custom ones defined for the current language.
         *
         * @param string $text
         * @return mixed An integer if $text is a valid value otherwise false
@@ -232,6 +247,7 @@ class Language {
        function getNsIndex( $text ) {
                $this->load();
                $lctext = $this->lc($text);
+               if( ( $ns = Namespace::getCanonicalIndex( $lctext ) ) !== null ) return $ns;
                return isset( $this->mNamespaceIds[$lctext] ) ? $this->mNamespaceIds[$lctext] : false;
        }
 
@@ -254,8 +270,13 @@ class Language {
        }
 
        function getQuickbarSettings() {
-               $this->load();
-               return $this->quickbarSettings;
+               return array(
+                       $this->getMessage( 'qbsettings-none' ),
+                       $this->getMessage( 'qbsettings-fixedleft' ),
+                       $this->getMessage( 'qbsettings-fixedright' ),
+                       $this->getMessage( 'qbsettings-floatingleft' ),
+                       $this->getMessage( 'qbsettings-floatingright' )
+               );
        }
 
        function getSkinNames() {
@@ -290,7 +311,12 @@ class Language {
 
        function getDefaultUserOptionOverrides() {
                $this->load();
-               return $this->defaultUserOptionOverrides;
+               # XXX - apparently some languageas get empty arrays, didn't get to it yet -- midom
+               if (is_array($this->defaultUserOptionOverrides)) {
+                       return $this->defaultUserOptionOverrides;
+               } else {
+                       return array();
+               }
        }
 
        function getExtraUserToggles() {
@@ -306,16 +332,17 @@ class Language {
         * Get language names, indexed by code.
         * If $customisedOnly is true, only returns codes with a messages file
         */
-       function getLanguageNames( $customisedOnly = false ) {
+       public static function getLanguageNames( $customisedOnly = false ) {
                global $wgLanguageNames;
                if ( !$customisedOnly ) {
                        return $wgLanguageNames;
                }
                
                global $IP;
-               $messageFiles = glob( "$IP/languages/messages/Messages*.php" );
                $names = array();
-               foreach ( $messageFiles as $file ) {
+               $dir = opendir( "$IP/languages/messages" );
+               while( false !== ( $file = readdir( $dir ) ) ) {
+                       $m = array();
                        if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $file, $m ) ) {
                                $code = str_replace( '_', '-', strtolower( $m[1] ) );
                                if ( isset( $wgLanguageNames[$code] ) ) {
@@ -323,6 +350,7 @@ class Language {
                                }
                        }
                }
+               closedir( $dir );
                return $names;
        }
 
@@ -372,6 +400,11 @@ class Language {
                return $this->getMessageFromDB( self::$mWeekdayAbbrevMsgs[$key-1] );
        }
 
+       function getIranianCalendarMonthName( $key ) {
+               return $this->getMessageFromDB( self::$mIranianCalendarMonthMsgs[$key-1] );
+       }
+
+
        /**
         * Used by date() and time() to adjust the time output.
         * @public
@@ -394,8 +427,12 @@ class Language {
                if ( $tz === '' ) {
                        # Global offset in minutes.
                        if( isset($wgLocalTZoffset) ) {
-                               $hrDiff = $wgLocalTZoffset % 60;
-                               $minDiff = $wgLocalTZoffset - ($hrDiff * 60);
+                               if( $wgLocalTZoffset >= 0 ) {
+                                       $hrDiff = floor($wgLocalTZoffset / 60);
+                               } else {
+                                       $hrDiff = ceil($wgLocalTZoffset / 60);
+                               }
+                               $minDiff = $wgLocalTZoffset % 60;
                        }
                } elseif ( strpos( $tz, ':' ) !== false ) {
                        $tzArray = explode( ':', $tz );
@@ -408,7 +445,8 @@ class Language {
                # No difference ? Return time unchanged
                if ( 0 == $hrDiff && 0 == $minDiff ) { return $ts; }
 
-               # Generate an adjusted date
+               wfSuppressWarnings(); // E_STRICT system time bitching
+               # Generate an adjusted date
                $t = mktime( (
                  (int)substr( $ts, 8, 2) ) + $hrDiff, # Hours
                  (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes
@@ -416,7 +454,11 @@ class Language {
                  (int)substr( $ts, 4, 2 ), # Month
                  (int)substr( $ts, 6, 2 ), # Day
                  (int)substr( $ts, 0, 4 ) ); #Year
-               return date( 'YmdHis', $t );
+               
+               $date = date( 'YmdHis', $t );
+               wfRestoreWarnings();
+               
+               return $date;
        }
 
        /**
@@ -434,6 +476,11 @@ class Language {
         *    xx   Literal x
         *    xg   Genitive month name
         *
+        *    xij  j (day number) in Iranian calendar
+        *    xiF  F (month name) in Iranian calendar
+        *    xin  n (month number) in Iranian calendar
+        *    xiY  Y (full year) in Iranian calendar
+        *
         * Characters enclosed in double quotes will be considered literal (with
         * the quotes themselves removed). Unmatched quotes will be considered
         * literal quotes. Example:
@@ -442,6 +489,9 @@ class Language {
         * i's"                   => 20'11"
         *
         * Backslash escaping is also supported.
+        *
+        * Input timestamp is assumed to be pre-normalized to the desired local
+        * time zone, if any.
         * 
         * @param string $format
         * @param string $ts 14-character timestamp
@@ -454,13 +504,18 @@ class Language {
                $roman = false;
                $unix = false;
                $rawToggle = false;
+               $iranian = false;
                for ( $p = 0; $p < strlen( $format ); $p++ ) {
                        $num = false;
                        $code = $format[$p];
                        if ( $code == 'x' && $p < strlen( $format ) - 1 ) {
                                $code .= $format[++$p];
                        }
-                       
+
+                       if ( $code === 'xi' && $p < strlen( $format ) - 1 ) {
+                               $code .= $format[++$p];
+                       }
+
                        switch ( $code ) {
                                case 'xx':
                                        $s .= 'x';
@@ -482,35 +537,43 @@ class Language {
                                        break;
                                case 'D':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $s .= $this->getWeekdayAbbreviation( date( 'w', $unix ) + 1 );
+                                       $s .= $this->getWeekdayAbbreviation( gmdate( 'w', $unix ) + 1 );
                                        break;
                                case 'j':
                                        $num = intval( substr( $ts, 6, 2 ) );
                                        break;
+                               case 'xij':
+                                       if ( !$iranian ) $iranian = self::tsToIranian( $ts );
+                                       $num = $iranian[2];
+                                       break;
                                case 'l':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $s .= $this->getWeekdayName( date( 'w', $unix ) + 1 );
+                                       $s .= $this->getWeekdayName( gmdate( 'w', $unix ) + 1 );
                                        break;
                                case 'N':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $w = date( 'w', $unix );
+                                       $w = gmdate( 'w', $unix );
                                        $num = $w ? $w : 7;
                                        break;
                                case 'w':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $num = date( 'w', $unix );
+                                       $num = gmdate( 'w', $unix );
                                        break;
                                case 'z':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $num = date( 'z', $unix );
+                                       $num = gmdate( 'z', $unix );
                                        break;
                                case 'W':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $num = date( 'W', $unix );
-                                       break;                                  
+                                       $num = gmdate( 'W', $unix );
+                                       break;
                                case 'F':
                                        $s .= $this->getMonthName( substr( $ts, 4, 2 ) );
                                        break;
+                               case 'xiF':
+                                       if ( !$iranian ) $iranian = self::tsToIranian( $ts );
+                                       $s .= $this->getIranianCalendarMonthName( $iranian[1] );
+                                       break;
                                case 'm':
                                        $num = substr( $ts, 4, 2 );
                                        break;
@@ -520,17 +583,25 @@ class Language {
                                case 'n':
                                        $num = intval( substr( $ts, 4, 2 ) );
                                        break;
+                               case 'xin':
+                                       if ( !$iranian ) $iranian = self::tsToIranian( $ts );
+                                       $num = $iranian[1];
+                                       break;
                                case 't':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $num = date( 't', $unix );
+                                       $num = gmdate( 't', $unix );
                                        break;
                                case 'L':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $num = date( 'L', $unix );
-                                       break;                                  
+                                       $num = gmdate( 'L', $unix );
+                                       break;
                                case 'Y':
                                        $num = substr( $ts, 0, 4 );
                                        break;
+                               case 'xiY':
+                                       if ( !$iranian ) $iranian = self::tsToIranian( $ts );
+                                       $num = $iranian[0];
+                                       break;
                                case 'y':
                                        $num = substr( $ts, 2, 2 );
                                        break;
@@ -562,11 +633,11 @@ class Language {
                                        break;
                                case 'c':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $s .= date( 'c', $unix );
+                                       $s .= gmdate( 'c', $unix );
                                        break;
                                case 'r':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
-                                       $s .= date( 'r', $unix );
+                                       $s .= gmdate( 'r', $unix );
                                        break;
                                case 'U':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
@@ -615,6 +686,64 @@ class Language {
                return $s;
        }
 
+       private static $GREG_DAYS = array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
+       private static $IRANIAN_DAYS = array( 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29 );
+       /**
+        * Algorithm by Roozbeh Pournader and Mohammad Toossi to convert 
+        * Gregorian dates to Iranian dates. Originally written in C, it
+        * is released under the terms of GNU Lesser General Public
+        * License. Conversion to PHP was performed by Niklas Laxström.
+        * 
+        * Link: http://www.farsiweb.info/jalali/jalali.c
+        */
+       private static function tsToIranian( $ts ) {
+               $gy = substr( $ts, 0, 4 ) -1600;
+               $gm = substr( $ts, 4, 2 ) -1;
+               $gd = substr( $ts, 6, 2 ) -1;
+
+               # Days passed from the beginning (including leap years)
+               $gDayNo = 365*$gy
+                       + floor(($gy+3) / 4)
+                       - floor(($gy+99) / 100)
+                       + floor(($gy+399) / 400);
+
+
+               // Add days of the past months of this year
+               for( $i = 0; $i < $gm; $i++ ) {
+                       $gDayNo += self::$GREG_DAYS[$i];
+               }
+
+               // Leap years
+               if ( $gm > 1 && (($gy%4===0 && $gy%100!==0 || ($gy%400==0)))) {
+                       $gDayNo++;
+               }
+
+               // Days passed in current month
+               $gDayNo += $gd;
+               
+               $jDayNo = $gDayNo - 79;
+
+               $jNp = floor($jDayNo / 12053);
+               $jDayNo %= 12053;
+
+               $jy = 979 + 33*$jNp + 4*floor($jDayNo/1461);
+               $jDayNo %= 1461;
+
+               if ( $jDayNo >= 366 ) {
+                       $jy += floor(($jDayNo-1)/365);
+                       $jDayNo = floor(($jDayNo-1)%365);
+               }
+
+               for ( $i = 0; $i < 11 && $jDayNo >= self::$IRANIAN_DAYS[$i]; $i++ ) {
+                       $jDayNo -= self::$IRANIAN_DAYS[$i];
+               }
+
+               $jm= $i+1;
+               $jd= $jDayNo+1;
+
+               return array($jy, $jm, $jd);
+       }
+
        /**
         * Roman number formatting up to 3000
         */
@@ -743,6 +872,9 @@ class Language {
        */
        function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false) {
                $this->load();
+
+               $ts = wfTimestamp( TS_MW, $ts );
+
                if ( $adj ) { 
                        $ts = $this->userAdjust( $ts, $timecorrection ); 
                }
@@ -767,7 +899,7 @@ class Language {
 
        function iconv( $in, $out, $string ) {
                # For most languages, this is a wrapper for iconv
-               return iconv( $in, $out, $string );
+               return iconv( $in, $out . '//IGNORE', $string );
        }
 
        // callback functions for uc(), lc(), ucwords(), ucwordbreaks()
@@ -803,15 +935,17 @@ class Language {
        }
 
        function uc( $str, $first = false ) {
-               if ( function_exists( 'mb_strtoupper' ) )
-                       if ( $first )
-                               if ( self::isMultibyte( $str ) )
+               if ( function_exists( 'mb_strtoupper' ) ) {
+                       if ( $first ) {
+                               if ( self::isMultibyte( $str ) ) {
                                        return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
-                               else
+                               } else {
                                        return ucfirst( $str );
-                       else
+                               }
+                       } else {
                                return self::isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
-               else
+                       }
+               } else {
                        if ( self::isMultibyte( $str ) ) {
                                list( $wikiUpperChars ) = $this->getCaseMaps();
                                $x = $first ? '^' : '';
@@ -820,8 +954,10 @@ class Language {
                                        array($this,"ucCallback"),
                                        $str
                                );
-                       } else
+                       } else {
                                return $first ? ucfirst( $str ) : strtoupper( $str );
+                       }
+               }
        }
        
        function lcfirst( $str ) {
@@ -954,6 +1090,11 @@ class Language {
         * @return string
         */
        function stripForSearch( $string ) {
+               global $wgDBtype;
+               if ( $wgDBtype != 'mysql' ) {
+                       return $string;
+               }
+
                # MySQL fulltext index doesn't grok utf-8, so we
                # need to fold cases and convert to hex
 
@@ -987,6 +1128,7 @@ class Language {
         * @return string
         */
        function firstChar( $s ) {
+               $matches = array();
                preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
                '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})/', $s, $matches);
 
@@ -1076,8 +1218,8 @@ class Language {
 
        # Fill a MagicWord object with data from here
        function getMagic( &$mw ) {
-               if ( !isset( $this->mMagicExtensions ) ) {
-                       $this->mMagicExtensions = array();
+               if ( !$this->mMagicHookDone ) {
+                       $this->mMagicHookDone = true;
                        wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
                }
                if ( isset( $this->mMagicExtensions[$mw->mId] ) ) {
@@ -1100,6 +1242,27 @@ class Language {
                $mw->mSynonyms = array_slice( $rawEntry, 1 );
        }
 
+       /**
+        * Add magic words to the extension array
+        */
+       function addMagicWordsByLang( $newWords ) {
+               $code = $this->getCode();
+               $fallbackChain = array();
+               while ( $code && !in_array( $code, $fallbackChain ) ) {
+                       $fallbackChain[] = $code;
+                       $code = self::getFallbackFor( $code );
+               }
+               if ( !in_array( 'en', $fallbackChain ) ) {
+                       $fallbackChain[] = 'en';
+               }
+               $fallbackChain = array_reverse( $fallbackChain );
+               foreach ( $fallbackChain as $code ) {
+                       if ( isset( $newWords[$code] ) ) {
+                               $this->mMagicExtensions = $newWords[$code] + $this->mMagicExtensions;
+                       }
+               }
+       }
+
        /**
         * Get special page names, as an associative array
         *   case folded alias => real name
@@ -1108,7 +1271,7 @@ class Language {
                $this->load();
                if ( !isset( $this->mExtendedSpecialPageAliases ) ) {
                        $this->mExtendedSpecialPageAliases = $this->specialPageAliases;
-                       wfRunHooks( 'LangugeGetSpecialPageAliases', 
+                       wfRunHooks( 'LanguageGetSpecialPageAliases', 
                                array( &$this->mExtendedSpecialPageAliases, $this->getCode() ) );
                }
                return $this->mExtendedSpecialPageAliases;
@@ -1166,6 +1329,17 @@ class Language {
                return $number;
        }
 
+       function parseFormattedNumber( $number ) {
+               $s = $this->digitTransformTable();
+               if (!is_null($s)) { $number = strtr($number, array_flip($s)); }
+
+               $s = $this->separatorTransformTable();
+               if (!is_null($s)) { $number = strtr($number, array_flip($s)); }
+
+               $number = strtr( $number, array (',' => '') );
+               return $number;
+       }
+
        /**
         * Adds commas to a given number
         *
@@ -1208,13 +1382,21 @@ class Language {
                return $s;
        }
 
-       # Crop a string from the beginning or end to a certain number of bytes.
-       # (Bytes are used because our storage has limited byte lengths for some
-       # columns in the database.) Multibyte charsets will need to make sure that
-       # only whole characters are included!
-       #
-       # $length does not include the optional ellipsis.
-       # If $length is negative, snip from the beginning
+       /**
+        * Truncate a string to a specified length in bytes, appending an optional
+        * string (e.g. for ellipses)
+        *
+        * The database offers limited byte lengths for some columns in the database;
+        * multi-byte character sets mean we need to ensure that only whole characters
+        * are included, otherwise broken characters can be passed to the user
+        *
+        * If $length is negative, the string will be truncated from the beginning
+        *       
+        * @param string $string String to truncate
+        * @param int $length Maximum length (excluding ellipses)
+        * @param string $ellipses String to append to the truncated text
+        * @return string
+        */
        function truncate( $string, $length, $ellipsis = "" ) {
                if( $length == 0 ) {
                        return $ellipsis;
@@ -1225,6 +1407,7 @@ class Language {
                if( $length > 0 ) {
                        $string = substr( $string, 0, $length );
                        $char = ord( $string[strlen( $string ) - 1] );
+                       $m = array();
                        if ($char >= 0xc0) {
                                # We got the first byte only of a multibyte char; remove it.
                                $string = substr( $string, 0, -1 );
@@ -1264,7 +1447,7 @@ class Language {
 
        /**
         * Plural form transformations, needed for some languages.
-        * For example, where are 3 form of plural in Russian and Polish,
+        * For example, there are 3 form of plural in Russian and Polish,
         * depending on "count mod 10". See [[w:Plural]]
         * For English it is pretty simple.
         *
@@ -1277,10 +1460,12 @@ class Language {
         * @param string $wordform1
         * @param string $wordform2
         * @param string $wordform3 (optional)
+        * @param string $wordform4 (optional)
+        * @param string $wordform5 (optional)
         * @return string
         */
-       function convertPlural( $count, $w1, $w2, $w3) {
-               return $count == '1' ? $w1 : $w2;
+       function convertPlural( $count, $w1, $w2, $w3, $w4, $w5) {
+               return ( $count == '1' || $count == '-1' ) ? $w1 : $w2;
        }
 
        /**
@@ -1301,9 +1486,9 @@ class Language {
                        if ( strpos($option, ":") === false )
                                continue;
                        list($show, $value) = explode(":", $option);
-                       if ( strcmp ( $str, $value) == 0 )
-                               return '<span title="' . htmlspecialchars($str). '">' .
-                                       htmlspecialchars( trim( $show ) ) . '</span>';
+                       if ( strcmp ( $str, $value) == 0 ) {
+                               return htmlspecialchars( trim( $show ) );
+                       }
                }
 
                return $str;
@@ -1340,16 +1525,16 @@ class Language {
                return $this->mConverter->parserConvert( $text, $parser );
        }
 
-       # Tell the converter that it shouldn't convert titles
-       function setNoTitleConvert(){
-               $this->mConverter->setNotitleConvert();
-       }
-
        # Check if this is a language with variants
        function hasVariants(){
                return sizeof($this->getVariants())>1;
        }
 
+       # Put custom tags (e.g. -{ }-) around math to prevent conversion
+       function armourMath($text){ 
+               return $this->mConverter->armourMath($text);
+       }
+
 
        /**
         * Perform output conversion on a string, and encode for safe HTML output.
@@ -1510,7 +1695,7 @@ class Language {
                        $cache = wfGetPrecompiledData( self::getFileName( "Messages", $code, '.ser' ) );
                        if ( $cache ) {
                                self::$mLocalisationCache[$code] = $cache;
-                               wfDebug( "Got localisation for $code from precompiled data file\n" );
+                               wfDebug( "Language::loadLocalisation(): got localisation for $code from precompiled data file\n" );
                                wfProfileOut( __METHOD__ );
                                return self::$mLocalisationCache[$code]['deps'];
                        }
@@ -1519,21 +1704,19 @@ class Language {
                        $memcKey = wfMemcKey('localisation', $code );
                        $cache = $wgMemc->get( $memcKey );
                        if ( $cache ) {
-                               $expired = false;
                                # Check file modification times
                                foreach ( $cache['deps'] as $file => $mtime ) {
                                        if ( !file_exists( $file ) || filemtime( $file ) > $mtime ) {
-                                               $expired = true;
                                                break;
                                        }
                                }
                                if ( self::isLocalisationOutOfDate( $cache ) ) {
                                        $wgMemc->delete( $memcKey );
                                        $cache = false;
-                                       wfDebug( "Localisation cache for $code had expired due to update of $file\n" );
+                                       wfDebug( "Language::loadLocalisation(): localisation cache for $code had expired due to update of $file\n" );
                                } else {
                                        self::$mLocalisationCache[$code] = $cache;
-                                       wfDebug( "Got localisation for $code from cache\n" );
+                                       wfDebug( "Language::loadLocalisation(): got localisation for $code from cache\n" );
                                        wfProfileOut( __METHOD__ );
                                        return $cache['deps'];
                                }
@@ -1552,14 +1735,14 @@ class Language {
                # Load the primary localisation from the source file
                $filename = self::getMessagesFileName( $code );
                if ( !file_exists( $filename ) ) {
-                       wfDebug( "No localisation file for $code, using implicit fallback to en\n" );
+                       wfDebug( "Language::loadLocalisation(): no localisation file for $code, using implicit fallback to en\n" );
                        $cache = array();
                        $deps = array();
                } else {
                        $deps = array( $filename => filemtime( $filename ) );
                        require( $filename );
                        $cache = compact( self::$mLocalisationKeys );   
-                       wfDebug( "Got localisation for $code from source\n" );
+                       wfDebug( "Language::loadLocalisation(): got localisation for $code from source\n" );
                }
 
                if ( !empty( $fallback ) ) {
@@ -1683,7 +1866,7 @@ class Language {
         * Do any necessary post-cache-load settings adjustment
         */
        function fixUpSettings() {
-               global $wgExtraNamespaces, $wgMetaNamespace, $wgMetaNamespaceTalk, $wgMessageCache, 
+               global $wgExtraNamespaces, $wgMetaNamespace, $wgMetaNamespaceTalk,
                        $wgNamespaceAliases, $wgAmericanDates;
                wfProfileIn( __METHOD__ );
                if ( $wgExtraNamespaces ) {
@@ -1756,6 +1939,70 @@ class Language {
                wfProfileOut( __METHOD__ );
                return array( $wikiUpperChars, $wikiLowerChars );
        }
-}
 
-?>
+       function formatTimePeriod( $seconds ) {
+               if ( $seconds < 10 ) {
+                       return $this->formatNum( sprintf( "%.1f", $seconds ) ) . wfMsg( 'seconds-abbrev' );
+               } elseif ( $seconds < 60 ) {
+                       return $this->formatNum( round( $seconds ) ) . wfMsg( 'seconds-abbrev' );
+               } elseif ( $seconds < 3600 ) {
+                       return $this->formatNum( floor( $seconds / 60 ) ) . wfMsg( 'minutes-abbrev' ) . 
+                               $this->formatNum( round( fmod( $seconds, 60 ) ) ) . wfMsg( 'seconds-abbrev' );
+               } else {
+                       $hours = floor( $seconds / 3600 );
+                       $minutes = floor( ( $seconds - $hours * 3600 ) / 60 );
+                       $secondsPart = round( $seconds - $hours * 3600 - $minutes * 60 );
+                       return $this->formatNum( $hours ) . wfMsg( 'hours-abbrev' ) . 
+                               $this->formatNum( $minutes ) . wfMsg( 'minutes-abbrev' ) .
+                               $this->formatNum( $secondsPart ) . wfMsg( 'seconds-abbrev' );
+               }
+       }
+
+       function formatBitrate( $bps ) {
+               $units = array( 'bps', 'kbps', 'Mbps', 'Gbps' );
+               if ( $bps <= 0 ) {
+                       return $this->formatNum( $bps ) . $units[0];
+               }
+               $unitIndex = floor( log10( $bps ) / 3 );
+               $mantissa = $bps / pow( 1000, $unitIndex );
+               if ( $mantissa < 10 ) {
+                       $mantissa = round( $mantissa, 1 );
+               } else {
+                       $mantissa = round( $mantissa );
+               }
+               return $this->formatNum( $mantissa ) . $units[$unitIndex];
+       }
+
+       /**
+        * Format a size in bytes for output, using an appropriate
+        * unit (B, KB, MB or GB) according to the magnitude in question
+        *
+        * @param $size Size to format
+        * @return string Plain text (not HTML)
+        */
+       function formatSize( $size ) {
+               // For small sizes no decimal places necessary
+               $round = 0;
+               if( $size > 1024 ) {
+                       $size = $size / 1024;
+                       if( $size > 1024 ) {
+                               $size = $size / 1024;
+                               // For MB and bigger two decimal places are smarter
+                               $round = 2;
+                               if( $size > 1024 ) {
+                                       $size = $size / 1024;
+                                       $msg = 'size-gigabytes';
+                               } else {
+                                       $msg = 'size-megabytes';
+                               }
+                       } else {
+                               $msg = 'size-kilobytes';
+                       }
+               } else {
+                       $msg = 'size-bytes';
+               }
+               $size = round( $size, $round );
+               $text = $this->getMessageFromDB( $msg );
+               return str_replace( '$1', $this->formatNum( $size ), $text );
+       }
+}