From 6b8f82e412bd5caf30fa80620e77e4107f8baf67 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 30 Apr 2013 16:48:53 +0100 Subject: [PATCH 1/2] MDL-39422 course: prevent module names longer 255 chars To prevent ugly DB errors. --- course/yui/toolboxes/toolboxes.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/course/yui/toolboxes/toolboxes.js b/course/yui/toolboxes/toolboxes.js index dd83903db2f..18500d61656 100644 --- a/course/yui/toolboxes/toolboxes.js +++ b/course/yui/toolboxes/toolboxes.js @@ -509,7 +509,8 @@ YUI.add('moodle-course-toolboxes', function(Y) { 'name' : 'title', 'value' : titletext, 'autocomplete' : 'off', - 'aria-describedby' : 'id_editinstructions' + 'aria-describedby' : 'id_editinstructions', + 'maxLength' : '255' }) .addClass('titleeditor'); var editform = Y.Node.create('
') From 10abf35eace3f7b96dc8f06c7bac75b5af855c8d Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 30 Apr 2013 17:39:56 +0100 Subject: [PATCH 2/2] MDL-39422 mod_forms: prevent long coruse module names To prevent ugly DB errors. --- mod/assign/mod_form.php | 1 + mod/assignment/mod_form.php | 1 + mod/book/mod_form.php | 1 + mod/chat/mod_form.php | 1 + mod/choice/mod_form.php | 1 + mod/data/mod_form.php | 1 + mod/feedback/mod_form.php | 1 + mod/folder/mod_form.php | 1 + mod/glossary/mod_form.php | 1 + mod/imscp/mod_form.php | 1 + mod/lesson/mod_form.php | 1 + mod/lti/mod_form.php | 1 + mod/page/mod_form.php | 1 + mod/quiz/mod_form.php | 1 + mod/resource/mod_form.php | 1 + mod/scorm/mod_form.php | 1 + mod/url/mod_form.php | 1 + mod/wiki/mod_form.php | 1 + 18 files changed, 18 insertions(+) diff --git a/mod/assign/mod_form.php b/mod/assign/mod_form.php index 4b9929f6048..80b1b7e2399 100644 --- a/mod/assign/mod_form.php +++ b/mod/assign/mod_form.php @@ -57,6 +57,7 @@ class mod_assign_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('description', 'assign')); diff --git a/mod/assignment/mod_form.php b/mod/assignment/mod_form.php index 56b407d6ea6..bc0818fea2e 100644 --- a/mod/assignment/mod_form.php +++ b/mod/assignment/mod_form.php @@ -45,6 +45,7 @@ class mod_assignment_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('description', 'assignment')); diff --git a/mod/book/mod_form.php b/mod/book/mod_form.php index 8901645f5f1..6bf1dbc1373 100644 --- a/mod/book/mod_form.php +++ b/mod/book/mod_form.php @@ -45,6 +45,7 @@ class mod_book_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro, get_string('moduleintro')); $alloptions = book_get_numbering_types(); diff --git a/mod/chat/mod_form.php b/mod/chat/mod_form.php index 86025393207..294d2cdb0e4 100644 --- a/mod/chat/mod_form.php +++ b/mod/chat/mod_form.php @@ -22,6 +22,7 @@ class mod_chat_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('chatintro', 'chat')); diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php index 70812f68b41..04011a0a46a 100644 --- a/mod/choice/mod_form.php +++ b/mod/choice/mod_form.php @@ -22,6 +22,7 @@ class mod_choice_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('chatintro', 'chat')); diff --git a/mod/data/mod_form.php b/mod/data/mod_form.php index c5f71206306..f8451d2932a 100644 --- a/mod/data/mod_form.php +++ b/mod/data/mod_form.php @@ -22,6 +22,7 @@ class mod_data_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('intro', 'data')); diff --git a/mod/feedback/mod_form.php b/mod/feedback/mod_form.php index 6256de76c10..9edb6cf75ec 100644 --- a/mod/feedback/mod_form.php +++ b/mod/feedback/mod_form.php @@ -44,6 +44,7 @@ class mod_feedback_mod_form extends moodleform_mod { $mform->addElement('text', 'name', get_string('name', 'feedback'), array('size'=>'64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('description', 'feedback')); diff --git a/mod/folder/mod_form.php b/mod/folder/mod_form.php index 212cb125120..7500e2be07f 100644 --- a/mod/folder/mod_form.php +++ b/mod/folder/mod_form.php @@ -44,6 +44,7 @@ class mod_folder_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/glossary/mod_form.php b/mod/glossary/mod_form.php index 4db6c90e3e9..561053428cc 100644 --- a/mod/glossary/mod_form.php +++ b/mod/glossary/mod_form.php @@ -22,6 +22,7 @@ class mod_glossary_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true); diff --git a/mod/imscp/mod_form.php b/mod/imscp/mod_form.php index 450ab5d4543..e62453d5ffe 100644 --- a/mod/imscp/mod_form.php +++ b/mod/imscp/mod_form.php @@ -45,6 +45,7 @@ class mod_imscp_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index 7f82372b8fd..dd99e80f6b5 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -89,6 +89,7 @@ class mod_lesson_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Create a text box that can be enabled/disabled for lesson time limit $timedgrp = array(); diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php index ec1b5bf4c81..425c51886e0 100644 --- a/mod/lti/mod_form.php +++ b/mod/lti/mod_form.php @@ -67,6 +67,7 @@ class mod_lti_mod_form extends moodleform_mod { $mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size'=>'64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Adding the optional "intro" and "introformat" pair of fields $this->add_intro_editor(false, get_string('basicltiintro', 'lti')); $mform->setAdvanced('introeditor'); diff --git a/mod/page/mod_form.php b/mod/page/mod_form.php index 9ec12872d87..b36c1f11d2d 100644 --- a/mod/page/mod_form.php +++ b/mod/page/mod_form.php @@ -47,6 +47,7 @@ class mod_page_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index 9c71ac8f81c..83dde015fac 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -69,6 +69,7 @@ class mod_quiz_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Introduction. $this->add_intro_editor(false, get_string('introduction', 'quiz')); diff --git a/mod/resource/mod_form.php b/mod/resource/mod_form.php index 7b9d6454d97..b3173f13c9b 100644 --- a/mod/resource/mod_form.php +++ b/mod/resource/mod_form.php @@ -55,6 +55,7 @@ class mod_resource_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/scorm/mod_form.php b/mod/scorm/mod_form.php index a9f61e67a7c..f3adbf025ac 100644 --- a/mod/scorm/mod_form.php +++ b/mod/scorm/mod_form.php @@ -43,6 +43,7 @@ class mod_scorm_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Summary $this->add_intro_editor(true); diff --git a/mod/url/mod_form.php b/mod/url/mod_form.php index 47d42512bb9..bde836a7d19 100644 --- a/mod/url/mod_form.php +++ b/mod/url/mod_form.php @@ -45,6 +45,7 @@ class mod_url_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/wiki/mod_form.php b/mod/wiki/mod_form.php index ef5b26907e2..53b4fd07d1b 100644 --- a/mod/wiki/mod_form.php +++ b/mod/wiki/mod_form.php @@ -53,6 +53,7 @@ class mod_wiki_mod_form extends moodleform_mod { $mform->addElement('text', 'name', get_string('wikiname', 'wiki'), array('size' => '64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', $required, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Adding the optional "intro" and "introformat" pair of fields $this->add_intro_editor(true, get_string('wikiintro', 'wiki'));