Misc EOL w/s and spaces-instead-of-tabs fixes. One day I'll get around to nagging...
[lhc/web/wiklou.git] / languages / Language.php
index 8e62c3b..8047bc0 100644 (file)
@@ -19,14 +19,6 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 global $wgLanguageNames;
 require_once( dirname( __FILE__ ) . '/Names.php' );
 
-global $wgInputEncoding, $wgOutputEncoding;
-
-/**
- * These are always UTF-8, they exist only for backwards compatibility
- */
-$wgInputEncoding    = 'UTF-8';
-$wgOutputEncoding      = 'UTF-8';
-
 if ( function_exists( 'mb_strtoupper' ) ) {
        mb_internal_encoding( 'UTF-8' );
 }
@@ -73,7 +65,11 @@ class Language {
         */
        var $transformData = array();
 
+       /**
+        * @var LocalisationCache
+        */
        static public $dataCache;
+
        static public $mLangObjCache = array();
 
        static public $mWeekdayMsgs = array(
@@ -156,14 +152,14 @@ class Language {
                static $recursionLevel = 0;
 
                // Protect against path traversal below
-               if ( !Language::isValidCode( $code ) 
-                       || strcspn( $code, ":/\\\000" ) !== strlen( $code ) ) 
+               if ( !Language::isValidCode( $code )
+                       || strcspn( $code, ":/\\\000" ) !== strlen( $code ) )
                {
                        throw new MWException( "Invalid language code \"$code\"" );
                }
 
                if ( !Language::isValidBuiltInCode( $code ) ) {
-                       // It's not possible to customise this code with class files, so 
+                       // It's not possible to customise this code with class files, so
                        // just return a Language object. This is to support uselang= hacks.
                        $lang = new Language;
                        $lang->setCode( $code );
@@ -202,18 +198,18 @@ class Language {
        }
 
        /**
-        * Returns true if a language code string is of a valid form, whether or 
-        * not it exists. This includes codes which are used solely for 
+        * Returns true if a language code string is of a valid form, whether or
+        * not it exists. This includes codes which are used solely for
         * customisation via the MediaWiki namespace.
         */
        public static function isValidCode( $code ) {
-               return 
+               return
                        strcspn( $code, ":/\\\000" ) === strlen( $code )
                        && !preg_match( Title::getTitleInvalidRegex(), $code );
        }
 
        /**
-        * Returns true if a language code is of a valid form for the purposes of 
+        * Returns true if a language code is of a valid form for the purposes of
         * internal customisation of MediaWiki, via Messages*.php.
         */
        public static function isValidBuiltInCode( $code ) {
@@ -260,15 +256,6 @@ class Language {
         */
        function initContLang() { }
 
-       /**
-        * @deprecated Use User::getDefaultOptions()
-        * @return array
-        */
-       function getDefaultUserOptions() {
-               wfDeprecated( __METHOD__ );
-               return User::getDefaultOptions();
-       }
-
        function getFallbackLanguageCode() {
                if ( $this->mCode === 'en' ) {
                        return false;
@@ -495,10 +482,6 @@ class Language {
                );
        }
 
-       function getMathNames() {
-               return self::$dataCache->getItem( $this->mCode, 'mathNames' );
-       }
-
        function getDatePreferences() {
                return self::$dataCache->getItem( $this->mCode, 'datePreferences' );
        }
@@ -608,6 +591,14 @@ class Language {
                return $this->getMessageFromDB( self::$mMonthMsgs[$key - 1] );
        }
 
+       function getMonthNamesArray() {
+               $monthNames = array( '' );
+               for ( $i=1; $i < 13; $i++ ) {
+                       $monthNames[] = $this->getMonthName( $i );
+               }
+               return $monthNames;
+       }
+
        function getMonthNameGen( $key ) {
                return $this->getMessageFromDB( self::$mMonthGenMsgs[$key - 1] );
        }
@@ -616,6 +607,14 @@ class Language {
                return $this->getMessageFromDB( self::$mMonthAbbrevMsgs[$key - 1] );
        }
 
+       function getMonthAbbreviationsArray() {
+               $monthNames = array('');
+               for ( $i=1; $i < 13; $i++ ) {
+                       $monthNames[] = $this->getMonthAbbreviation( $i );
+               }
+               return $monthNames;
+       }
+
        function getWeekdayName( $key ) {
                return $this->getMessageFromDB( self::$mWeekdayMsgs[$key - 1] );
        }
@@ -1863,7 +1862,8 @@ class Language {
                        return $s;
                }
 
-               $isutf8 = ( $s == iconv("UTF-8","UTF-8//IGNORE", $s));
+               $isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
+                               '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
                if ( $isutf8 ) {
                        return $s;
                }
@@ -2427,7 +2427,7 @@ class Language {
                }
                # Do not truncate if the ellipsis makes the string longer/equal (bug 22181).
                # This check is *not* redundant if $adjustLength, due to the single case where
-               # LEN($ellipsis) > ABS($limit arg); $stringOriginal could be shorter than $string. 
+               # LEN($ellipsis) > ABS($limit arg); $stringOriginal could be shorter than $string.
                if ( strlen( $string ) < strlen( $stringOriginal ) ) {
                        return $string;
                } else {
@@ -2478,7 +2478,7 @@ class Language {
                return $string;
        }
 
-       /*
+       /**
         * Truncate a string of valid HTML to a specified length in bytes,
         * appending an optional string (e.g. for ellipses), and return valid HTML
         *
@@ -2610,7 +2610,7 @@ class Language {
                return $skipCount;
        }
 
-       /*
+       /**
         * truncateHtml() helper function
         * (a) push or pop $tag from $openTags as needed
         * (b) clear $tag value
@@ -2697,7 +2697,7 @@ class Language {
 
        /**
         * Checks that convertPlural was given an array and pads it to requested
-        * amound of forms by copying the last one.
+        * amount of forms by copying the last one.
         *
         * @param $count Integer: How many forms should there be at least
         * @param $forms Array of forms given to convertPlural
@@ -2719,11 +2719,25 @@ class Language {
         * @see LanguageFi.php for example implementation
         */
        function translateBlockExpiry( $str ) {
-               foreach( SpecialBlock::getSuggestedDurations( $this ) as $show => $value ){
+               $duration = SpecialBlock::getSuggestedDurations( $this );
+               foreach( $duration as $show => $value ){
                        if ( strcmp( $str, $value ) == 0 ) {
                                return htmlspecialchars( trim( $show ) );
                        }
                }
+
+               // Since usually only infinite or indefinite is only on list, so try
+               // equivalents if still here.
+               $indefs = array( 'infinite', 'infinity', 'indefinite' );
+               if ( in_array( $str, $indefs ) ) {
+                       foreach( $indefs as $val ) {
+                               $show = array_search( $val, $duration, true );
+                               if ( $show !== false ) {
+                                       return htmlspecialchars( trim( $show ) );
+                               }
+                       }
+               }
+               // If all else fails, return the original string.
                return $str;
        }
 
@@ -2831,7 +2845,7 @@ class Language {
         * into an array of all possible variants of the text:
         *  'variant' => text in that variant
         *
-        * @deprecated Use autoConvertToAllVariants()
+        * @deprecated since 1.17 Use autoConvertToAllVariants()
         */
        function convertLinkToAllVariants( $text ) {
                return $this->mConverter->convertLinkToAllVariants( $text );
@@ -2904,12 +2918,12 @@ class Language {
         */
        static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
                // Protect against path traversal
-               if ( !Language::isValidCode( $code ) 
-                       || strcspn( $code, ":/\\\000" ) !== strlen( $code ) ) 
+               if ( !Language::isValidCode( $code )
+                       || strcspn( $code, ":/\\\000" ) !== strlen( $code ) )
                {
                        throw new MWException( "Invalid language code \"$code\"" );
                }
-               
+
                return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
        }