enhance size tooltip on changelist
[lhc/web/wiklou.git] / languages / Language.php
index c313182..56367db 100644 (file)
@@ -1045,7 +1045,7 @@ class Language {
                                        if ( !$unix ) {
                                                $unix = wfTimestamp( TS_UNIX, $ts );
                                        }
-                                       $num = date( 'o', $unix );
+                                       $num = gmdate( 'o', $unix );
                                        break;
                                case 'Y':
                                        $num = substr( $ts, 0, 4 );
@@ -2729,6 +2729,9 @@ class Language {
         */
        function commafy( $_ ) {
                $digitGroupingPattern = $this->digitGroupingPattern();
+               if ( $_ === null ) {
+                       return '';
+               }
 
                if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) {
                        // default grouping is at thousands,  use the same for ###,###,### pattern too.
@@ -2739,7 +2742,7 @@ class Language {
                        if ( intval( $_ ) < 0 ) {
                                // For negative numbers apply the algorithm like positive number and add sign.
                                $sign =  "-";
-                               $_ = substr( $_,1 );
+                               $_ = substr( $_, 1 );
                        }
                        $numberpart = array();
                        $decimalpart = array();
@@ -3806,52 +3809,62 @@ class Language {
        }
 
        /**
+        * Format a bitrate for output, using an appropriate
+        * unit (bps, kbps, Mbps, Gbps, Tbps, Pbps, Ebps, Zbps or Ybps) according to the magnitude in question
+        *
         * @param $bps int
         * @return string
         */
        function formatBitrate( $bps ) {
-               $units = array( 'bps', 'kbps', 'Mbps', 'Gbps' );
+               $units = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' );
                if ( $bps <= 0 ) {
-                       return $this->formatNum( $bps ) . $units[0];
+                       return str_replace( '$1', $this->formatNum( $bps ), $this->getMessageFromDB( 'bitrate-bits' ) );
                }
                $unitIndex = (int)floor( log10( $bps ) / 3 );
                $mantissa = $bps / pow( 1000, $unitIndex );
+
+               $maxIndex = count( $units ) - 1;
+
+               if ( $unitIndex  > $maxIndex ) {
+                       // Prevent code falling off end of $units array
+                       $mantissa *= ( $unitIndex - $maxIndex ) * 1000;
+                       $unitIndex = $maxIndex;
+               }
                if ( $mantissa < 10 ) {
                        $mantissa = round( $mantissa, 1 );
                } else {
                        $mantissa = round( $mantissa );
                }
-               return $this->formatNum( $mantissa ) . $units[$unitIndex];
+               $msg = "bitrate-{$units[$unitIndex]}bits";
+               $text = $this->getMessageFromDB( $msg );
+               return str_replace( '$1', $this->formatNum( $mantissa ), $text );
        }
 
        /**
         * Format a size in bytes for output, using an appropriate
-        * unit (B, KB, MB or GB) according to the magnitude in question
+        * unit (B, KB, MB, GB, TB, PB, EB, ZB or YB) according to the magnitude in question
         *
         * @param $size int Size to format
         * @return string Plain text (not HTML)
         */
        function formatSize( $size ) {
+               $sizes = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' );
+               $index = 0;
+
+               $maxIndex = count( $sizes ) - 1;
+               while ( $size >= 1024 && $index < $maxIndex ) {
+                       $index++;
+                       $size /= 1024;
+               }
+
                // 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';
+               if ( $index > 1 ) {
+                       // For MB and bigger two decimal places are smarter
+                       $round = 2;
                }
+               $msg = "size-{$sizes[$index]}bytes";
+
                $size = round( $size, $round );
                $text = $this->getMessageFromDB( $msg );
                return str_replace( '$1', $this->formatNum( $size ), $text );
@@ -3889,7 +3902,7 @@ class Language {
 
                # Make 'previous' link
                $prev = wfMessage( 'prevn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
-               if( $offset > 0 ) {
+               if ( $offset > 0 ) {
                        $plink = $this->numLink( $title, max( $offset - $limit, 0 ), $limit,
                                $query, $prev, 'prevn-title', 'mw-prevlink' );
                } else {
@@ -3898,7 +3911,7 @@ class Language {
 
                # Make 'next' link
                $next = wfMessage( 'nextn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
-               if( $atend ) {
+               if ( $atend ) {
                        $nlink = htmlspecialchars( $next );
                } else {
                        $nlink = $this->numLink( $title, $offset + $limit, $limit,
@@ -3907,7 +3920,7 @@ class Language {
 
                # Make links to set number of items per page
                $numLinks = array();
-               foreach( array( 20, 50, 100, 250, 500 ) as $num ) {
+               foreach ( array( 20, 50, 100, 250, 500 ) as $num ) {
                        $numLinks[] = $this->numLink( $title, $offset, $num,
                                $query, $this->formatNum( $num ), 'shown-title', 'mw-numlink' );
                }