Index: trunk/phase3/tests/phpunit/languages/LanguageTest.php |
— | — | @@ -245,39 +245,45 @@ |
246 | 246 | ), |
247 | 247 | array( |
248 | 248 | 1024, |
249 | | - "1,024 B", |
250 | | - "1,024 bytes" |
251 | | - ), |
252 | | - array( |
253 | | - 1024 + 1, |
254 | 249 | "1 KB", |
255 | 250 | "1 kilobyte" |
256 | 251 | ), |
257 | 252 | array( |
258 | 253 | 1024 * 1024, |
259 | | - "1,024 KB", |
260 | | - "1,024 kilobyte" |
261 | | - ), |
262 | | - array( |
263 | | - ( 1024 * 1024 ) + 1, |
264 | 254 | "1 MB", |
265 | | - "1 megabyte" |
| 255 | + "1,024 megabytes" |
266 | 256 | ), |
267 | 257 | array( |
268 | 258 | 1024 * 1024 * 1024, |
269 | | - "1,024 MB", |
270 | | - "1,024 megabyte" |
| 259 | + "1 GB", |
| 260 | + "1 gigabytes" |
271 | 261 | ), |
272 | 262 | array( |
273 | | - ( 1024 * 1024 * 1024 ) + 1, |
274 | | - "1 GB", |
275 | | - "1 gigabyte" |
| 263 | + pow( 1024, 4 ), |
| 264 | + "1 TB", |
| 265 | + "1 terabyte" |
276 | 266 | ), |
277 | 267 | array( |
278 | | - ( 1024 * 1024 * 1024 * 1024 ) + 1, |
279 | | - "1,024 GB", |
280 | | - "1,024 gigabyte" |
| 268 | + pow( 1024, 5 ), |
| 269 | + "1 PB", |
| 270 | + "1 petabyte" |
281 | 271 | ), |
| 272 | + array( |
| 273 | + pow( 1024, 6 ), |
| 274 | + "1 EB", |
| 275 | + "1,024 exabyte" |
| 276 | + ), |
| 277 | + array( |
| 278 | + pow( 1024, 7 ), |
| 279 | + "1 ZB", |
| 280 | + "1 zetabyte" |
| 281 | + ), |
| 282 | + array( |
| 283 | + pow( 1024, 8 ), |
| 284 | + "1 YB", |
| 285 | + "1 yottabyte" |
| 286 | + ), |
| 287 | + // How big!? THIS BIG! |
282 | 288 | ); |
283 | 289 | } |
284 | 290 | } |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -3826,32 +3826,29 @@ |
3827 | 3827 | |
3828 | 3828 | /** |
3829 | 3829 | * Format a size in bytes for output, using an appropriate |
3830 | | - * unit (B, KB, MB or GB) according to the magnitude in question |
| 3830 | + * unit (B, KB, MB, GB, TB, PB, EB, ZB or YB) according to the magnitude in question |
3831 | 3831 | * |
3832 | 3832 | * @param $size int Size to format |
3833 | 3833 | * @return string Plain text (not HTML) |
3834 | 3834 | */ |
3835 | 3835 | function formatSize( $size ) { |
| 3836 | + $sizes = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' ); |
| 3837 | + $index = 0; |
| 3838 | + |
| 3839 | + $maxIndex = count( $sizes ) - 1; |
| 3840 | + while ( $size >= 1024 && $index < $maxIndex ) { |
| 3841 | + $index++; |
| 3842 | + $size /= 1024; |
| 3843 | + } |
| 3844 | + |
3836 | 3845 | // For small sizes no decimal places necessary |
3837 | 3846 | $round = 0; |
3838 | | - if ( $size > 1024 ) { |
3839 | | - $size = $size / 1024; |
3840 | | - if ( $size > 1024 ) { |
3841 | | - $size = $size / 1024; |
3842 | | - // For MB and bigger two decimal places are smarter |
3843 | | - $round = 2; |
3844 | | - if ( $size > 1024 ) { |
3845 | | - $size = $size / 1024; |
3846 | | - $msg = 'size-gigabytes'; |
3847 | | - } else { |
3848 | | - $msg = 'size-megabytes'; |
3849 | | - } |
3850 | | - } else { |
3851 | | - $msg = 'size-kilobytes'; |
3852 | | - } |
3853 | | - } else { |
3854 | | - $msg = 'size-bytes'; |
| 3847 | + if ( $index > 1 ) { |
| 3848 | + // For MB and bigger two decimal places are smarter |
| 3849 | + $round = 2; |
3855 | 3850 | } |
| 3851 | + $msg = "size-{$sizes[$index]}bytes"; |
| 3852 | + |
3856 | 3853 | $size = round( $size, $round ); |
3857 | 3854 | $text = $this->getMessageFromDB( $msg ); |
3858 | 3855 | return str_replace( '$1', $this->formatNum( $size ), $text ); |