From 1f28d18c75e4d45abc07289b1bb4525d61234830 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Sat, 23 Dec 2006 13:13:13 +0000 Subject: [PATCH] * (bug 8214) Output file size limit and actual file size in appropriate units on Special:Upload * Introduce Linker::formatSize(); will do sizes from B through to GB incl. * "largefile" renamed to "large-file" due to backwards-incompatible changes --- RELEASE-NOTES | 2 ++ includes/Linker.php | 31 +++++++++++++++++++++++++++++++ includes/SpecialUpload.php | 7 ++++--- languages/messages/MessagesEn.php | 8 +++++++- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e07055d0ad..bd41f84da3 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/Linker.php b/includes/Linker.php index 33e26cc02b..22b294ef43 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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 ) ); + } + } + ?> diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index 011cfa6533..d2fd839cd2 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -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 .= '
  • '.wfMsgHtml( 'largefile', $wgUploadSizeWarning, $this->mUploadSize ).'
  • '; + $skin =& $wgUser->getSkin(); + $wsize = $skin->formatSize( $wgUploadSizeWarning ); + $asize = $skin->formatSize( $this->mUploadSize ); + $warning .= '
  • ' . wfMsgHtml( 'large-file', $wsize, $asize ) . '
  • '; } if ( $this->mUploadSize == 0 ) { $warning .= '
  • '.wfMsgHtml( 'emptyfile' ).'
  • '; diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 6e9af9f9cc..32dea4fc4a 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', + ); ?> -- 2.20.1