Update IPSet use statements
[lhc/web/wiklou.git] / languages / Language.php
index 7ef441b..27c9faf 100644 (file)
@@ -3313,12 +3313,25 @@ class Language {
         */
        function commafy( $number ) {
                $digitGroupingPattern = $this->digitGroupingPattern();
+               $minimumGroupingDigits = $this->minimumGroupingDigits();
                if ( $number === null ) {
                        return '';
                }
 
                if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) {
-                       // default grouping is at thousands,  use the same for ###,###,### pattern too.
+                       // Default grouping is at thousands, use the same for ###,###,### pattern too.
+                       // In some languages it's conventional not to insert a thousands separator
+                       // in numbers that are four digits long (1000-9999).
+                       if ( $minimumGroupingDigits ) {
+                               // Number of '#' characters after last comma in the grouping pattern.
+                               // The pattern is hardcoded here, but this would vary for different patterns.
+                               $primaryGroupingSize = 3;
+                               // Maximum length of a number to suppress digit grouping for.
+                               $maximumLength = $minimumGroupingDigits + $primaryGroupingSize - 1;
+                               if ( preg_match( '/^\-?\d{1,' . $maximumLength . '}(\.\d+)?$/', $number ) ) {
+                                       return $number;
+                               }
+                       }
                        return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $number ) ) );
                } else {
                        // Ref: http://cldr.unicode.org/translation/number-patterns
@@ -3381,6 +3394,13 @@ class Language {
                return self::$dataCache->getItem( $this->mCode, 'separatorTransformTable' );
        }
 
+       /**
+        * @return int|null
+        */
+       function minimumGroupingDigits() {
+               return self::$dataCache->getItem( $this->mCode, 'minimumGroupingDigits' );
+       }
+
        /**
         * Take a list of strings and build a locale-friendly comma-separated
         * list, using the local comma-separator message.
@@ -3469,15 +3489,16 @@ class Language {
         * @return string
         */
        function truncate( $string, $length, $ellipsis = '...', $adjustLength = true ) {
+               # Check if there is no need to truncate
+               if ( strlen( $string ) <= abs( $length ) ) {
+                       return $string; // no need to truncate
+               }
                # Use the localized ellipsis character
                if ( $ellipsis == '...' ) {
                        $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
                }
-               # Check if there is no need to truncate
                if ( $length == 0 ) {
                        return $ellipsis; // convention
-               } elseif ( strlen( $string ) <= abs( $length ) ) {
-                       return $string; // no need to truncate
                }
                $stringOriginal = $string;
                # If ellipsis length is >= $length then we can't apply $adjustLength