From cfb212ed780a0ec8e282698fc149dde23095359d Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Fri, 14 Feb 2014 15:37:05 +0100 Subject: [PATCH] New API functions to print maximum file size - get_filesize_info() returns the file size in the desired unit - print_max_filesize() prints the span tag with maximum file size in desired unit, including tooltip in bytes Updated language strings, refactored code to use the new functions Issue #16970 --- bug_file_upload_inc.php | 5 +++-- bug_report_page.php | 5 +++-- core/print_api.php | 24 ++++++++++++++++++++++++ lang/strings_english.txt | 4 ++-- lang/strings_qqq.txt | 1 + proj_doc_add_page.php | 5 +++-- proj_doc_edit_page.php | 5 +++-- 7 files changed, 39 insertions(+), 10 deletions(-) diff --git a/bug_file_upload_inc.php b/bug_file_upload_inc.php index 39670a9d6c..208ad48e0b 100644 --- a/bug_file_upload_inc.php +++ b/bug_file_upload_inc.php @@ -69,8 +69,9 @@ -
- + +
+ diff --git a/bug_report_page.php b/bug_report_page.php index ae77cf20d3..c38b884c93 100644 --- a/bug_report_page.php +++ b/bug_report_page.php @@ -597,8 +597,9 @@ ?> -
- + +
+ diff --git a/core/print_api.php b/core/print_api.php index 1fe8b0b5f4..d402beb352 100644 --- a/core/print_api.php +++ b/core/print_api.php @@ -1866,3 +1866,27 @@ function print_timezone_option_list( $p_timezone ) { echo "\t\n"; } } + +/** + * Return file size information + * @param int $p_size + * @param string $p_unit + * @return string + */ +function get_filesize_info( $p_size, $p_unit ) { + return sprintf( lang_get( 'file_size_info' ), number_format( $p_size ), $p_unit ); +} + +/** + * Print maximum file size information + * @param int $p_size in bytes + * @param int $p_divider optional divider, defaults to 1000 + * @param string $p_unit optional language string of unit, defaults to KB + */ +function print_max_filesize( $p_size, $p_divider = 1000, $p_unit = 'kb' ) { + echo ''; + echo lang_get( 'max_file_size_label' ) + . lang_get( 'word_separator' ) + . get_filesize_info( $p_size / $p_divider, lang_get( $p_unit ) ); + echo ''; +} diff --git a/lang/strings_english.txt b/lang/strings_english.txt index d0b61461fe..7ea99706da 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -489,9 +489,8 @@ $s_select_file = 'Select File'; $s_select_files = 'Select Files'; $s_upload_file_button = 'Upload File'; $s_upload_files_button = 'Upload Files'; -$s_max_file_size = 'Maximum size'; $s_max_file_size_label = 'Maximum size:'; -$s_file_kb = 'KiB'; +$s_file_size_info = '%1$s %2$s'; # $1 = size, $2 = unit (e.g. kb, bytes) # bug_reopen.php $s_bug_reopened_msg = 'Issue has been reopened...'; @@ -1304,6 +1303,7 @@ $s_monitored_by = 'Monitored By'; $s_monitored_by_label = 'Monitored By:'; $s_attachments = 'attachment(s)'; $s_bytes = 'bytes'; +$s_kb = 'KB'; $s_attachment_missing = 'Attachment missing'; $s_attachment_count = 'Attachment count'; $s_view_attachments_for_issue = 'View %1$d attachment(s) for issue #%2$d'; diff --git a/lang/strings_qqq.txt b/lang/strings_qqq.txt index d52c57bd42..5b0149bc98 100644 --- a/lang/strings_qqq.txt +++ b/lang/strings_qqq.txt @@ -71,6 +71,7 @@ $s_add_new_relationship_button = '{{Identical|Add}}'; $s_on = 'Switch confition (for filter, for example)'; $s_off = 'Switch condition (for filter, for example)'; $s_show_all_tags = '{{Identical|All}}'; +$s_file_size_info = 'Displays file size information, where $1 is the size and $2 is the unit'; $MANTIS_ERROR[ERROR_PLUGIN_GENERIC] = 'If we need to specify the number of expected parameter in string, we just need to write something like "Lalal %2$s bububu %1$d", where 1 and 2 - the index number in argument list (actually, expected in original message)'; diff --git a/proj_doc_add_page.php b/proj_doc_add_page.php index df37274ee5..bffcdd92ad 100644 --- a/proj_doc_add_page.php +++ b/proj_doc_add_page.php @@ -86,8 +86,9 @@ - *
- + * +
+ diff --git a/proj_doc_edit_page.php b/proj_doc_edit_page.php index 9abc89d4d3..0c3374a9c9 100644 --- a/proj_doc_edit_page.php +++ b/proj_doc_edit_page.php @@ -124,8 +124,9 @@ -
- + +
+