From 39bb9b1f0005ff7143ed73f31954f435a9da7d56 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 21 Jan 2013 09:51:52 +0800 Subject: [PATCH] MDL-36472 files: Improved file area uploads error messages. --- lang/en/error.php | 4 ++-- lang/en/moodle.php | 14 ++++++++------ lib/form/dndupload.js | 6 +++--- lib/outputrequirementslib.php | 5 ++++- repository/repository_ajax.php | 10 +++++----- repository/upload/lib.php | 7 ++++--- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/lang/en/error.php b/lang/en/error.php index 0b951cda8744f..65622c6587105 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -349,8 +349,8 @@ $string['logfilenotavailable'] = 'Logs not available'; $string['loginasnoenrol'] = 'You cannot use enrol or unenrol when in course "Login as" session'; $string['loginasonecourse'] = 'You cannot enter this course.
You have to terminate the "Login as" session before entering any other course.'; -$string['maxbytes'] = 'This file is bigger than the maximum size'; -$string['maxareabytes'] = 'Not enough available space to store this file'; +$string['maxbytes'] = 'The file is larger than the maximum size allowed.'; +$string['maxareabytes'] = 'The file is larger than the space remaining in this area.'; $string['messagingdisable'] = 'Messaging is disabled on this site'; $string['mimetexisnotexist'] = 'Your system is not configured to run mimeTeX. You need to download the appropriate executable for you PHP_OS platform from http://moodle.org/download/mimetex/, or obtain the C source from http://www.forkosh.com/mimetex.zip, compile it and put the executable into your moodle/filter/tex/ directory.'; $string['mimetexnotexecutable'] = 'Custom mimetex is not executable!'; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 12842c9dbe952..9a3d7ffdea521 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -986,21 +986,23 @@ $string['markedthistopic'] = 'This topic is highlighted as the current topic'; $string['markthistopic'] = 'Highlight this topic as the current topic'; $string['matchingsearchandrole'] = 'Matching \'{$a->search}\' and {$a->role}'; -$string['maxsizeandattachments'] = 'Maximum size for new files: {$a->size}, maximum attachments: {$a->attachments}'; -$string['maxsizeandattachmentsandareasize'] = 'Maximum size for new files: {$a->size}, maximum attachments: {$a->attachments}, overall limit: {$a->areasize}'; -$string['maxsizeandareasize'] = 'Maximum size for new files: {$a->size}, overall limit: {$a->areasize}'; +$string['maxareabytesreached'] = 'The file (or the total size of several files) is larger than the space remaining in this area.'; +$string['maxbytesforfile'] = 'The file {$a} is larger than the maximum size allowed.'; +$string['maxfilesize'] = 'Maximum size for new files: {$a}'; $string['maxfilesreached'] = 'You are allowed to attach a maximum of {$a} file(s) to this item'; +$string['maximumchars'] = 'Maximum of {$a} characters'; $string['maximumgrade'] = 'Maximum grade'; $string['maximumgradex'] = 'Maximum grade: {$a}'; -$string['maximumchars'] = 'Maximum of {$a} characters'; $string['maximumshort'] = 'Max'; $string['maximumupload'] = 'Maximum upload size'; $string['maximumupload_help'] = 'This setting determines the largest size of file that can be uploaded to the course, limited by the site-wide setting set by an administrator. Activity modules also include a maximum upload size setting for further restricting the file size.'; $string['maxnumberweeks'] = 'Maximum for number of weeks/topics'; $string['maxnumberweeks_desc'] = 'This controls the maximum options that appears in the "Number of weeks/topics" setting for courses.'; -$string['maxsize'] = 'Max size: {$a}'; -$string['maxfilesize'] = 'Maximum size for new files: {$a}'; $string['maxnumcoursesincombo'] = 'Browse {$a->numberofcourses} courses.'; +$string['maxsize'] = 'Max size: {$a}'; +$string['maxsizeandareasize'] = 'Maximum size for new files: {$a->size}, overall limit: {$a->areasize}'; +$string['maxsizeandattachments'] = 'Maximum size for new files: {$a->size}, maximum attachments: {$a->attachments}'; +$string['maxsizeandattachmentsandareasize'] = 'Maximum size for new files: {$a->size}, maximum attachments: {$a->attachments}, overall limit: {$a->areasize}'; $string['memberincourse'] = 'People in the course'; $string['messagebody'] = 'Message body'; $string['messagedselectedusers'] = 'Selected users have been messaged and the recipient list has been reset.'; diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index ce473c005e3fa..084f922eac478 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -582,8 +582,8 @@ M.form_dndupload.init = function(Y, options) { var i; for (i=0; i 0 && files[i].size > this.options.maxbytes) { - // Check filesize before attempting to upload - this.print_msg(M.util.get_string('uploadformlimit', 'moodle', files[i].name), 'error'); + // Check filesize before attempting to upload. + this.print_msg(M.util.get_string('maxbytesforfile', 'moodle', files[i].name), 'error'); this.uploadqueue = []; // No uploads if one file is too big. return; } @@ -626,7 +626,7 @@ M.form_dndupload.init = function(Y, options) { if (sizereached > this.options.areamaxbytes) { this.uploadqueue = []; this.renamequeue = []; - this.print_msg(M.util.get_string('uploadformlimit', 'moodle', file.name), 'error'); + this.print_msg(M.util.get_string('maxareabytesreached', 'moodle'), 'error'); return false; } } diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index d4eff1ccc2a60..7126f1b83c49c 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -433,7 +433,10 @@ protected function find_module($component) { $module = array('name' => 'core_dndupload', 'fullpath' => '/lib/form/dndupload.js', 'requires' => array('node', 'event', 'json', 'core_filepicker'), - 'strings' => array(array('uploadformlimit', 'moodle'), array('droptoupload', 'moodle'), array('maxfilesreached', 'moodle'), array('dndenabled_inbox', 'moodle'), array('fileexists', 'moodle'))); + 'strings' => array(array('uploadformlimit', 'moodle'), array('droptoupload', 'moodle'), array('maxfilesreached', 'moodle'), + array('dndenabled_inbox', 'moodle'), array('fileexists', 'moodle'), array('maxbytesforfile', 'moodle'), + array('maxareabytesreached', 'moodle') + )); break; } diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index 96c83bb788afb..f679c785b95f7 100644 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -302,16 +302,16 @@ die(json_encode($err)); } - // Check if we exceed the max bytes of the area. - if (file_is_draft_area_limit_reached($itemid, $areamaxbytes, filesize($downloadedfile['path']))) { - throw new file_exception('maxareabytes'); - } - // Check if exceed maxbytes. if ($maxbytes != -1 && filesize($downloadedfile['path']) > $maxbytes) { throw new file_exception('maxbytes'); } + // Check if we exceed the max bytes of the area. + if (file_is_draft_area_limit_reached($itemid, $areamaxbytes, filesize($downloadedfile['path']))) { + throw new file_exception('maxareabytes'); + } + $info = repository::move_to_filepool($downloadedfile['path'], $record); if (empty($info)) { $info['e'] = get_string('error', 'moodle'); diff --git a/repository/upload/lib.php b/repository/upload/lib.php index d2c1fdda42c59..eed039eb1acd1 100644 --- a/repository/upload/lib.php +++ b/repository/upload/lib.php @@ -195,13 +195,14 @@ public function process_upload($saveas_filename, $maxbytes, $types = '*', $savep $record->itemid = 0; } + if (($maxbytes!==-1) && (filesize($_FILES[$elname]['tmp_name']) > $maxbytes)) { + throw new file_exception('maxbytes'); + } + if (file_is_draft_area_limit_reached($record->itemid, $areamaxbytes, filesize($_FILES[$elname]['tmp_name']))) { throw new file_exception('maxareabytes'); } - if (($maxbytes!==-1) && (filesize($_FILES[$elname]['tmp_name']) > $maxbytes)) { - throw new file_exception('maxbytes'); - } $record->contextid = $context->id; $record->userid = $USER->id;