From 4fb3df32ac68403cd256bac555d5f432ffeb6203 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 d3a98116a55..09550956f09 100644 --- a/course/yui/toolboxes/toolboxes.js +++ b/course/yui/toolboxes/toolboxes.js @@ -517,7 +517,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 a74cd331609ab52bb69e3c23497dcd6bd7d177d1 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 7e781c2f51f..4101ab11283 100644 --- a/mod/assign/mod_form.php +++ b/mod/assign/mod_form.php @@ -54,6 +54,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 31a5d6243a4..7d5b999ff20 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 8cca80fd67d..59fce157bdc 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 76a72dbfa97..ff56b7a537a 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 1dc61b7363e..02ab56ac590 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 0362aed1d61..50163f6e619 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 cd3c2efbe9f..06eeccc7792 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 377c07da100..6e75dce2d19 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 ebb9154c8db..6d576f42e26 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 a7b98a1fd3c..297baa08b6b 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 66b5ce8e248..9d4482a1d8e 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 c6588229cc7..be0636472c2 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 072e318c25d..97188baa00e 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 fd1196e7613..9c9cf0a885a 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'));