diff --git a/grade/grading/form/rubric/lib.php b/grade/grading/form/rubric/lib.php index 98aeaf963de..71b38ecad2b 100644 --- a/grade/grading/form/rubric/lib.php +++ b/grade/grading/form/rubric/lib.php @@ -453,7 +453,7 @@ class gradingform_rubric_controller extends gradingform_controller { global $CFG; return array( 'maxfiles' => -1, - 'maxbytes' => get_max_upload_file_size($CFG->maxbytes), + 'maxbytes' => get_user_max_upload_file_size($context, $CFG->maxbytes), 'context' => $context, ); } diff --git a/lang/en/role.php b/lang/en/role.php index 971722c4fb2..a8058ade8cb 100644 --- a/lang/en/role.php +++ b/lang/en/role.php @@ -120,6 +120,7 @@ $string['course:changeshortname'] = 'Change course short name'; $string['course:changesummary'] = 'Change course summary'; $string['course:enrolconfig'] = 'Configure enrol instances in courses'; $string['course:enrolreview'] = 'Review course enrolments'; +$string['course:ignorefilesizelimits'] = 'Use files larger than any file size restrictions'; $string['course:manageactivities'] = 'Manage activities'; $string['course:managefiles'] = 'Manage files'; $string['course:managegrades'] = 'Manage grades'; diff --git a/lib/db/access.php b/lib/db/access.php index 173659ee02a..121750c02bd 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -854,6 +854,14 @@ $capabilities = array( ) ), + 'moodle/course:ignorefilesizelimits' => array( + + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + ) + ), + 'moodle/course:manageactivities' => array( 'riskbitmask' => RISK_XSS, diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 1f2ce25cc24..f6d968d2841 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -69,7 +69,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { } } if (!empty($options['maxbytes'])) { - $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']); + $this->_options['maxbytes'] = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $options['maxbytes']); } if (empty($options['return_types'])) { $this->_options['return_types'] = (FILE_INTERNAL | FILE_REFERENCE); @@ -129,8 +129,8 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { * @param int $maxbytes file size */ function setMaxbytes($maxbytes) { - global $CFG; - $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $maxbytes); + global $CFG, $PAGE; + $this->_options['maxbytes'] = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $maxbytes); } /** @@ -354,7 +354,7 @@ class form_filemanager implements renderable { if (!empty($this->options->maxbytes) && $this->options->maxbytes > 0) { $maxbytes = $this->options->maxbytes; } - $this->options->maxbytes = get_max_upload_file_size($CFG->maxbytes, $coursebytes, $maxbytes); + $this->options->maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursebytes, $maxbytes); // building file picker options $params = new stdClass(); diff --git a/lib/form/filepicker.php b/lib/form/filepicker.php index c3fad282485..bcee75d22a8 100644 --- a/lib/form/filepicker.php +++ b/lib/form/filepicker.php @@ -79,7 +79,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input { if (!empty($PAGE->course)) { $coursemaxbytes = $PAGE->course->maxbytes; } - $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $coursemaxbytes, $fpmaxbytes); + $this->_options['maxbytes'] = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $coursemaxbytes, $fpmaxbytes); $this->_type = 'filepicker'; parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes); } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 266a67d4321..708c613c8b3 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5841,6 +5841,32 @@ function get_max_upload_file_size($sitebytes=0, $coursebytes=0, $modulebytes=0) return $minimumsize; } +/** + * Returns the maximum size for uploading files for the current user + * + * This function takes in account @see:get_max_upload_file_size() the user's capabilities + * + * @param context $context The context in which to check user capabilities + * @param int $sizebytes Set maximum size + * @param int $coursebytes Current course $course->maxbytes (in bytes) + * @param int $modulebytes Current module ->maxbytes (in bytes) + * @param stdClass The user + * @return int The maximum size for uploading files. + */ +function get_user_max_upload_file_size($context, $sitebytes=0, $coursebytes=0, $modulebytes=0, $user=null) { + global $USER; + + if (empty($user)) { + $user = $USER; + } + + if (has_capability('moodle/course:ignorefilesizelimits', $context, $user)) { + return -1; + } + + return get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes); +} + /** * Returns an array of possible sizes in local language * diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index ea453a68a47..11d8e78b520 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -2114,7 +2114,7 @@ abstract class lesson_page extends lesson_base { $context = $PAGE->context; } if ($maxbytes === null) { - $maxbytes =get_max_upload_file_size(); + $maxbytes = get_user_max_upload_file_size($context); } $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$maxbytes), $context, 'mod_lesson', 'page_contents', $properties->id); $DB->update_record("lesson_pages", $properties); diff --git a/repository/filepicker.php b/repository/filepicker.php index 4dab067602d..ebd9c9f93d5 100644 --- a/repository/filepicker.php +++ b/repository/filepicker.php @@ -93,7 +93,8 @@ if ($repository = $DB->get_record_sql($sql, array($repo_id))) { } } -$moodle_maxbytes = get_max_upload_file_size(); +$context = context::instance_by_id($contextid); +$moodle_maxbytes = get_user_max_upload_file_size($context); // to prevent maxbytes greater than moodle maxbytes setting if ($maxbytes == 0 || $maxbytes>=$moodle_maxbytes) { $maxbytes = $moodle_maxbytes; diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index 0299e2fd268..45f0662c3c7 100644 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -82,7 +82,7 @@ if (!$repository = $DB->get_record_sql($sql, array($repo_id))) { // Check permissions repository::check_capability($contextid, $repository); -$moodle_maxbytes = get_max_upload_file_size(); +$moodle_maxbytes = get_user_max_upload_file_size($context); // to prevent maxbytes greater than moodle maxbytes setting if ($maxbytes == 0 || $maxbytes>=$moodle_maxbytes) { $maxbytes = $moodle_maxbytes;