MDL-36472 files: Improved file area uploads error messages.
authorFrederic Massart <fred@moodle.com>
Mon, 21 Jan 2013 01:51:52 +0000 (09:51 +0800)
committerFrederic Massart <fred@moodle.com>
Thu, 31 Jan 2013 07:09:44 +0000 (15:09 +0800)
lang/en/error.php
lang/en/moodle.php
lib/form/dndupload.js
lib/outputrequirementslib.php
repository/repository_ajax.php
repository/upload/lib.php

index 0b951cd..65622c6 100644 (file)
@@ -349,8 +349,8 @@ $string['listupdatefail'] = 'DB operation failed when editing list hierarchy';
 $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!';
index 12842c9..9a3d7ff 100644 (file)
@@ -986,21 +986,23 @@ $string['manageroles'] = 'Roles and permissions';
 $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.';
index ce473c0..084f922 100644 (file)
@@ -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;
                 }
@@ -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;
                 }
             }
index d4eff1c..7126f1b 100644 (file)
@@ -433,7 +433,10 @@ class page_requirements_manager {
                     $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;
             }
 
index 96c83bb..f679c78 100644 (file)
@@ -302,16 +302,16 @@ switch ($action) {
                     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');
index d2c1fdd..eed039e 100644 (file)
@@ -195,13 +195,14 @@ class repository_upload extends repository {
             $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;