* (bug 8214) Output file size limit and actual file size in appropriate units on...
authorRob Church <robchurch@users.mediawiki.org>
Sat, 23 Dec 2006 13:13:13 +0000 (13:13 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Sat, 23 Dec 2006 13:13:13 +0000 (13:13 +0000)
* Introduce Linker::formatSize(); will do sizes from B through to GB incl.
* "largefile" renamed to "large-file" due to backwards-incompatible changes

RELEASE-NOTES
includes/Linker.php
includes/SpecialUpload.php
languages/messages/MessagesEn.php

index e07055d..bd41f84 100644 (file)
@@ -391,6 +391,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   the links in the sitenotice
 * (bug 8271) Show full time and date on viewer for individual deleted
   revisions
+* (bug 8214) Output file size limit and actual file size in appropriate units
+  on Special:Upload
 
 == Languages updated ==
 
index 33e26cc..22b294e 100644 (file)
@@ -1146,5 +1146,36 @@ class Linker {
                wfProfileOut( __METHOD__  );
                return $outText;
        }
+       
+       /**
+        * 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
+        */
+       public function formatSize( $size ) {
+               global $wgLang;
+               if( $size > 1024 ) {
+                       $size = $size / 1024;
+                       if( $size > 1024 ) {
+                               $size = $size / 1024;
+                               if( $size > 1024 ) {
+                                       $size = $size / 1024;
+                                       $msg = 'size-gigabytes';
+                               } else {
+                                       $msg = 'size-megabytes';
+                               }
+                       } else {
+                               $msg = 'size-kilobytes';
+                       }
+               } else {
+                       $msg = 'size-bytes';
+               }
+               $size = round( $size, 0 );
+               return wfMsgHtml( $msg, $wgLang->formatNum( $size ) );
+       }
+       
 }
+
 ?>
index 011cfa6..d2fd839 100644 (file)
@@ -402,9 +402,10 @@ class UploadForm {
 
                        global $wgUploadSizeWarning;
                        if ( $wgUploadSizeWarning && ( $this->mUploadSize > $wgUploadSizeWarning ) ) {
-                               # TODO: Format $wgUploadSizeWarning to something that looks better than the raw byte
-                               # value, perhaps add GB,MB and KB suffixes?
-                               $warning .= '<li>'.wfMsgHtml( 'largefile', $wgUploadSizeWarning, $this->mUploadSize ).'</li>';
+                               $skin =& $wgUser->getSkin();
+                               $wsize = $skin->formatSize( $wgUploadSizeWarning );
+                               $asize = $skin->formatSize( $this->mUploadSize );
+                               $warning .= '<li>' . wfMsgHtml( 'large-file', $wsize, $asize ) . '</li>';
                        }
                        if ( $this->mUploadSize == 0 ) {
                                $warning .= '<li>'.wfMsgHtml( 'emptyfile' ).'</li>';
index 6e9af9f..32dea4f 100644 (file)
@@ -1302,7 +1302,7 @@ To include the image in a page, use a link in the form
 'illegalfilename'      => 'The filename "$1" contains characters that are not allowed in page titles. Please rename the file and try uploading it again.',
 'badfilename'  => 'File name has been changed to "$1".',
 'badfiletype'  => "\".$1\" is not a recommended image file format.",
-'largefile'            => 'It is recommended that files do not exceed $1 bytes in size; this file is $2 bytes',
+'large-file' => 'It is recommended that files are no larger than $1; this file is $2.',
 'largefileserver' => 'This file is bigger than the server is configured to allow.',
 'emptyfile'            => 'The file you uploaded seems to be empty. This might be due to a typo in the file name. Please check whether you really want to upload this file.',
 'fileexists'           => 'A file with this name exists already, please check $1 if you are not sure if you want to change it.',
@@ -2678,6 +2678,12 @@ Please confirm that really want to recreate this page.',
 *205.188.146.144/30
 *207.200.112.0/21',
 
+# Size units
+'size-bytes' => '$1 B',
+'size-kilobytes' => '$1 KB',
+'size-megabytes' => '$1 MB',
+'size-gigabytes' => '$1 GB',
+
 );
 
 ?>