Skip to content

Commit

Permalink
MDL-36472 files: Improved file area uploads error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Jan 31, 2013
1 parent b3778a0 commit 39bb9b1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lang/en/error.php
Expand Up @@ -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.<br /> 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 <a href="http://moodle.org/download/mimetex/">http://moodle.org/download/mimetex/</a>, or obtain the C source from <a href="http://www.forkosh.com/mimetex.zip"> http://www.forkosh.com/mimetex.zip</a>, compile it and put the executable into your moodle/filter/tex/ directory.';
$string['mimetexnotexecutable'] = 'Custom mimetex is not executable!';
Expand Down
14 changes: 8 additions & 6 deletions lang/en/moodle.php
Expand Up @@ -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 href="{$a->link}">{$a->numberofcourses} courses</a>.';
$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.';
Expand Down
6 changes: 3 additions & 3 deletions lib/form/dndupload.js
Expand Up @@ -582,8 +582,8 @@ M.form_dndupload.init = function(Y, options) {
var i;
for (i=0; i<files.length; i++) {
if (this.options.maxbytes > 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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/outputrequirementslib.php
Expand Up @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions repository/repository_ajax.php
Expand Up @@ -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');
Expand Down
7 changes: 4 additions & 3 deletions repository/upload/lib.php
Expand Up @@ -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;

Expand Down

0 comments on commit 39bb9b1

Please sign in to comment.