Skip to content

Commit

Permalink
Merge branch 'MDL-40493-master' of git://github.com/damyon/moodle
Browse files Browse the repository at this point in the history
Conflicts:
	lib/db/install.xml
	lib/db/upgrade.php
	version.php
  • Loading branch information
danpoltawski committed Oct 8, 2013
2 parents 7bfc69b + 3d27180 commit 4f0eaf1
Show file tree
Hide file tree
Showing 26 changed files with 181 additions and 200 deletions.
4 changes: 2 additions & 2 deletions admin/tool/behat/tests/behat/manipulate_forms.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Feature: Forms manipulation
And I follow "Admin User"
And I follow "Edit profile"
When I fill in "First name" with "Field value"
And I select "Use standard web forms" from "When editing text"
And I select "Plain text area" from "Text editor"
And I check "Unmask"
Then the "First name" field should match "Field value" value
And the "When editing text" select box should contain "Use standard web forms"
And the "Text editor" select box should contain "Plain text area"
And the "Unmask" checkbox should be checked
And I uncheck "Unmask"
And the "Unmask" checkbox should not be checked
Expand Down
13 changes: 0 additions & 13 deletions admin/tool/uploaduser/user_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,6 @@ function definition () {
$mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
$mform->setDefault('autosubscribe', 1);

$editors = editors_get_enabled();
if (count($editors) > 1) {
$choices = array();
$choices['0'] = get_string('texteditor');
$choices['1'] = get_string('htmleditor');
$mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
$mform->setDefault('htmleditor', 1);
} else {
$mform->addElement('hidden', 'htmleditor');
$mform->setDefault('htmleditor', 1);
$mform->setType('htmleditor', PARAM_INT);
}

$mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="25"');
$mform->setType('city', PARAM_TEXT);
if (empty($CFG->defaultcity)) {
Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/backup_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ protected function define_structure() {
'confirmed', 'policyagreed', 'deleted',
'lang', 'theme', 'timezone', 'firstaccess',
'lastaccess', 'lastlogin', 'currentlogin',
'mailformat', 'maildigest', 'maildisplay', 'htmleditor',
'mailformat', 'maildigest', 'maildisplay',
'autosubscribe', 'trackforums', 'timecreated',
'timemodified', 'trustbitmask');

Expand Down
10 changes: 10 additions & 0 deletions backup/util/dbops/restore_dbops.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,16 @@ public static function create_included_users($basepath, $restoreid, $userid) {
$status = $DB->insert_record('user_preferences', $preference);
}
}
// Special handling for htmleditor which was converted to a preference.
if (isset($user->htmleditor)) {
if ($user->htmleditor == 0) {
$preference = new stdClass();
$preference->userid = $newuserid;
$preference->name = 'htmleditor';
$preference->value = 'textarea';
$status = $DB->insert_record('user_preferences', $preference);
}
}

// Create user files in pool (profile, icon, private) by context
restore_dbops::send_files_to_pool($basepath, $restoreid, 'user', 'icon', $recuser->parentitemid, $userid);
Expand Down
22 changes: 9 additions & 13 deletions grade/edit/tree/grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,17 @@
if ($grade = $DB->get_record('grade_grades', array('itemid' => $grade_item->id, 'userid' => $userid))) {

// always clean existing feedback - grading should not have XSS risk
if (can_use_html_editor()) {
if (empty($grade->feedback)) {
$grade->feedback = '';
} else {
$options = new stdClass();
$options->smiley = false;
$options->filter = false;
$options->noclean = false;
$options->para = false;
$grade->feedback = format_text($grade->feedback, $grade->feedbackformat, $options);
}
$grade->feedbackformat = FORMAT_HTML;
if (empty($grade->feedback)) {
$grade->feedback = '';
} else {
$grade->feedback = clean_text($grade->feedback, $grade->feedbackformat);
$options = new stdClass();
$options->smiley = false;
$options->filter = false;
$options->noclean = false;
$options->para = false;
$grade->feedback = format_text($grade->feedback, $grade->feedbackformat, $options);
}
$grade->feedbackformat = FORMAT_HTML;

$grade->locked = $grade->locked > 0 ? 1:0;
$grade->overridden = $grade->overridden > 0 ? 1:0;
Expand Down
1 change: 0 additions & 1 deletion lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,6 @@
$string['upwards'] = 'upwards';
$string['useblogassociations'] = 'Enable associations';
$string['useexternalyui'] = 'Use online YUI libraries';
$string['usehtmleditor'] = 'Use HTML editor';
$string['user'] = 'User';
$string['userbulk'] = 'Bulk user actions';
$string['userlist'] = 'Browse list of users';
Expand Down
3 changes: 2 additions & 1 deletion lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
$string['days'] = 'days';
$string['decodinginternallinks'] = 'Decoding internal links';
$string['default'] = 'Default';
$string['defaulteditor'] = 'Default editor';
$string['defaultcoursestudent'] = 'Student';
$string['defaultcoursestudentdescription'] = 'Students generally have fewer privileges within a course.';
$string['defaultcoursestudents'] = 'Students';
Expand Down Expand Up @@ -1743,7 +1744,7 @@
$string['teacheronly'] = 'for the {$a} only';
$string['teacherroles'] = '{$a} roles';
$string['teachers'] = 'Teachers';
$string['textediting'] = 'When editing text';
$string['textediting'] = 'Text editor';
$string['texteditor'] = 'Use standard web forms';
$string['textformat'] = 'Plain text format';
$string['thanks'] = 'Thanks';
Expand Down
3 changes: 1 addition & 2 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3841,8 +3841,7 @@ public function write_setting($data) {
public function output_html($data, $query='') {
global $CFG;

$CFG->adminusehtmleditor = can_use_html_editor();
$return = '<div class="form-htmlarea">'.print_textarea($CFG->adminusehtmleditor, 15, 60, 0, 0, $this->get_full_name(), $data, 0, true, 'summary') .'</div>';
$return = '<div class="form-htmlarea">'.print_textarea(true, 15, 60, 0, 0, $this->get_full_name(), $data, 0, true, 'summary') .'</div>';

return format_admin_setting($this, $this->visiblename, $return, $this->description, false, '', NULL, $query);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/db/install.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20131008" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20131001" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -786,7 +786,6 @@
<FIELD NAME="mailformat" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="maildigest" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="maildisplay" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="2" SEQUENCE="false"/>
<FIELD NAME="htmleditor" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="autosubscribe" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="trackforums" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand Down
18 changes: 18 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2642,5 +2642,23 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2013100800.01);
}

if ($oldversion < 2013100800.02) {
$sql = "INSERT INTO {user_preferences}(userid, name, value)
SELECT id, 'htmleditor', 'textarea' FROM {user} u where u.htmleditor = 0";
$DB->execute($sql);

// Define field htmleditor to be dropped from user
$table = new xmldb_table('user');
$field = new xmldb_field('htmleditor');

// Conditionally launch drop field requested
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2013100800.02);
}

return true;
}
44 changes: 23 additions & 21 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=fa
* When using this function, you should
*
* @global object
* @param bool $usehtmleditor Enables the use of the htmleditor for this field.
* @param bool $unused No longer used.
* @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
* @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
* @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored.
Expand All @@ -1495,7 +1495,7 @@ function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=fa
* @param string $id CSS ID to add to the textarea element.
* @return string|void depending on the value of $return
*/
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
/// $width and height are legacy fields and no longer used as pixels like they used to be.
/// However, you can set them to zero to override the mincols and minrows values below.

Expand All @@ -1512,29 +1512,19 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
$id = 'edit-'.$name;
}

if ($usehtmleditor) {
if ($height && ($rows < $minrows)) {
$rows = $minrows;
}
if ($width && ($cols < $mincols)) {
$cols = $mincols;
}
if ($height && ($rows < $minrows)) {
$rows = $minrows;
}

if ($usehtmleditor) {
editors_head_setup();
$editor = editors_get_preferred_editor(FORMAT_HTML);
$editor->use_editor($id, array('legacy'=>true));
} else {
$editorclass = '';
if ($width && ($cols < $mincols)) {
$cols = $mincols;
}

editors_head_setup();
$editor = editors_get_preferred_editor(FORMAT_HTML);
$editor->use_editor($id, array('legacy'=>true));

$str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
if ($usehtmleditor) {
$str .= htmlspecialchars($value); // needed for editing of cleaned text!
} else {
$str .= s($value);
}
$str .= htmlspecialchars($value); // needed for editing of cleaned text!
$str .= '</textarea>'."\n";

if ($return) {
Expand Down Expand Up @@ -4692,3 +4682,15 @@ function badges_get_issued_badge_info($hash) {
$assertion = new core_badges_assertion($hash);
return $assertion->get_badge_assertion();
}

/**
* Does the user want and can edit using rich text html editor?
* This function does not make sense anymore because a user can directly choose their preferred editor.
*
* @deprecated since 2.6
* @return bool
*/
function can_use_html_editor() {
debugging('can_use_html_editor has been deprecated please update your code to assume it returns true.', DEBUG_DEVELOPER);
return true;
}
72 changes: 11 additions & 61 deletions lib/editorlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ function editors_get_preferred_editor($format = NULL) {

$enabled = editors_get_enabled();

$preventhtml = (count($enabled) > 1 and empty($USER->htmleditor));
$preference = get_user_preferences('htmleditor', '', $USER);

if (isset($enabled[$preference])) {
// Edit the list of editors so the users preferred editor is first in the list.
$editor = $enabled[$preference];
unset($enabled[$preference]);
array_unshift($enabled, $editor);
}

// now find some plugin that supports format and is available
$editor = false;
Expand All @@ -46,27 +53,11 @@ function editors_get_preferred_editor($format = NULL) {
// bad luck, this editor is not compatible
continue;
}
if ($preventhtml and $format == FORMAT_HTML and $e->get_preferred_format() == FORMAT_HTML) {
// this is really not what we want but we could use it if nothing better found
$editor = $e;
continue;
}
if (!$supports = $e->get_supported_formats()) {
// buggy editor!
continue;
}
if (is_null($format)) {
// format does not matter
if ($preventhtml and $e->get_preferred_format() == FORMAT_HTML) {
// this is really not what we want but we could use it if nothing better found
$editor = $e;
continue;
} else {
$editor = $e;
break;
}
}
if (in_array($format, $supports)) {
if (is_null($format) || in_array($format, $supports)) {
// editor supports this format, yay!
$editor = $e;
break;
Expand All @@ -87,22 +78,7 @@ function editors_get_preferred_editor($format = NULL) {
function editors_get_preferred_format() {
global $USER;

$editors = editors_get_enabled();
if (count($editors) == 1) {
$editor = reset($editors);
return $editor->get_preferred_format();
}

foreach ($editors as $editor) {
if (empty($USER->htmleditor) and $editor->get_preferred_format() == FORMAT_HTML) {
// we do not prefer this one
continue;
}
return $editor->get_preferred_format();
}

// user did not want html editor, but there is no other choice, sorry
$editor = reset($editors);
$editor = editors_get_preferred_editor();
return $editor->get_preferred_format();
}

Expand Down Expand Up @@ -172,7 +148,7 @@ function editors_head_setup() {
global $CFG;

if (empty($CFG->texteditors)) {
$CFG->texteditors = 'tinymce,textarea';
$CFG->texteditors = 'tinymce,atto,textarea';
}
$active = explode(',', $CFG->texteditors);

Expand Down Expand Up @@ -236,29 +212,3 @@ public abstract function use_editor($elementid, array $options=null, $fpoptions
public function head_setup() {
}
}

//=== TO BE DEPRECATED in 2.1 =====================

/**
* Does the user want and can edit using rich text html editor?
* @todo Deprecate: eradicate completely, replace with something else in the future
* @return bool
*/
function can_use_html_editor() {
global $USER;

$editors = editors_get_enabled();
if (count($editors) > 1) {
if (empty($USER->htmleditor)) {
return false;
}
}

foreach ($editors as $editor) {
if ($editor->get_preferred_format() == FORMAT_HTML) {
return true;
}
}

return false;
}
23 changes: 3 additions & 20 deletions lib/form/htmleditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
/** @var string defines the type of editor */
var $_type;

/** @var bool Does the user want and can edit using rich text html editor */
var $_canUseHtmlEditor;

/** @var array default options for html editor, which can be overridden */
var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0);
var $_options=array('rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0);

/**
* Constructor
Expand All @@ -71,16 +68,7 @@ function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $opti
}
}
}
if ($this->_options['canUseHtmlEditor']=='detect'){
$this->_options['canUseHtmlEditor']=can_use_html_editor();
}
if ($this->_options['canUseHtmlEditor']){
$this->_type='htmleditor';
//$this->_elementTemplateType='wide';
}else{
$this->_type='textarea';
}
$this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
$this->_type='htmleditor';

editors_head_setup();
}
Expand All @@ -91,16 +79,11 @@ function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $opti
* @return string
*/
function toHtml(){
//if ($this->_canUseHtmlEditor && !$this->_flagFrozen){
// $script = '';
//} else {
// $script='';
//}
if ($this->_flagFrozen) {
return $this->getFrozenHtml();
} else {
return $this->_getTabs() .
print_textarea($this->_canUseHtmlEditor,
print_textarea(true,
$this->_options['rows'],
$this->_options['cols'],
$this->_options['width'],
Expand Down
Loading

0 comments on commit 4f0eaf1

Please sign in to comment.