Merge branch 'MDL-65015-master' of git://github.com/cescobedo/moodle

This commit is contained in:
Adrian Greeve
2019-04-11 10:14:23 +08:00
10 changed files with 64 additions and 15 deletions
+2 -1
View File
@@ -4,7 +4,7 @@ require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/message/lib.php');
require_once('user_message_form.php');
$msg = optional_param('msg', '', PARAM_CLEANHTML);
$msg = optional_param('msg', '', PARAM_RAW);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
admin_externalpage_setup('userbulk');
@@ -45,6 +45,7 @@ if ($msgform->is_cancelled()) {
$options->para = false;
$options->newlines = true;
$options->smiley = false;
$options->trusted = trusttext_trusted(\context_system::instance());
$msg = format_text($formdata->messagebody['text'], $formdata->messagebody['format'], $options);
+5 -1
View File
@@ -122,6 +122,9 @@ class message {
/** @var int The time the message was created.*/
private $timecreated;
/** @var boolean Mark trust content. */
private $fullmessagetrust;
/** @var array a list of properties that is allowed for each message. */
private $properties = array(
'courseid',
@@ -144,7 +147,8 @@ class message {
'savedmessageid',
'attachment',
'attachname',
'timecreated'
'timecreated',
'fullmessagetrust'
);
/** @var array property to store any additional message processor specific content */
Regular → Executable
+1
View File
@@ -603,6 +603,7 @@
<FIELD NAME="fullmessagehtml" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="smallmessage" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="fullmessagetrust" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+15
View File
@@ -2973,5 +2973,20 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2019040600.04);
}
if ($oldversion < 2019041000.02) {
// Define field fullmessagetrust to be added to messages.
$table = new xmldb_table('messages');
$field = new xmldb_field('fullmessagetrust', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'timecreated');
// Conditionally launch add field fullmessagetrust.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2019041000.02);
}
return true;
}
+16
View File
@@ -154,6 +154,22 @@ function message_send(\core\message\message $eventdata) {
$tabledata->smallmessage = $eventdata->smallmessage;
$tabledata->timecreated = time();
// The Trusted Content system.
// Texts created or uploaded by such users will be marked as trusted and will not be cleaned before display.
if (trusttext_active()) {
// Individual conversations are always in system context.
$messagecontext = \context_system::instance();
// We need to know the type of conversation and the contextid if it is a group conversation.
if ($conv = $DB->get_record('message_conversations', ['id' => $conversationid], 'id, type, contextid')) {
if ($conv->type == \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP && $conv->contextid) {
$messagecontext = \context::instance_by_id($conv->contextid);
}
}
$tabledata->fullmessagetrust = trusttext_trusted($messagecontext);
} else {
$tabledata->fullmessagetrust = false;
}
if ($messageid = message_handle_phpunit_redirection($eventdata, $table, $tabledata)) {
return $messageid;
}
+6 -4
View File
@@ -549,8 +549,8 @@ class api {
$typesql = !is_null($type) ? " AND mc.type = :convtype " : "";
$sql = "SELECT m.id as messageid, mc.id as id, mc.name as conversationname, mc.type as conversationtype, m.useridfrom,
m.smallmessage, m.fullmessage, m.fullmessageformat, m.fullmessagehtml, m.timecreated, mc.component,
mc.itemtype, mc.itemid, mc.contextid, mca.action as ismuted
m.smallmessage, m.fullmessage, m.fullmessageformat, m.fullmessagetrust, m.fullmessagehtml, m.timecreated,
mc.component, mc.itemtype, mc.itemid, mc.contextid, mca.action as ismuted
FROM {message_conversations} mc
INNER JOIN {message_conversation_members} mcm
ON (mcm.conversationid = mc.id AND mcm.userid = :userid3)
@@ -1917,12 +1917,14 @@ class api {
$eventdata->notification = 0;
$messageid = message_send($eventdata);
$messagerecord = $DB->get_record('messages', ['id' => $messageid], 'id, useridfrom, fullmessage, timecreated');
$messagerecord = $DB->get_record('messages', ['id' => $messageid], 'id, useridfrom, fullmessage,
timecreated, fullmessagetrust');
$message = (object) [
'id' => $messagerecord->id,
'useridfrom' => $messagerecord->useridfrom,
'text' => $messagerecord->fullmessage,
'timecreated' => $messagerecord->timecreated
'timecreated' => $messagerecord->timecreated,
'fullmessagetrust' => $messagerecord->fullmessagetrust
];
return $message;
}
+4 -2
View File
@@ -58,7 +58,8 @@ class helper {
$hash = self::get_conversation_hash([$userid, $otheruserid]);
$sql = "SELECT m.id, m.useridfrom, m.subject, m.fullmessage, m.fullmessagehtml,
m.fullmessageformat, m.smallmessage, m.timecreated, muaread.timecreated AS timeread
m.fullmessageformat, m.fullmessagetrust, m.smallmessage, m.timecreated,
mc.contextid, muaread.timecreated AS timeread
FROM {message_conversations} mc
INNER JOIN {messages} m
ON m.conversationid = mc.id
@@ -131,7 +132,8 @@ class helper {
global $DB;
$sql = "SELECT m.id, m.useridfrom, m.subject, m.fullmessage, m.fullmessagehtml,
m.fullmessageformat, m.smallmessage, m.timecreated, muaread.timecreated AS timeread
m.fullmessageformat, m.fullmessagetrust, m.smallmessage, m.timecreated,
mc.contextid, muaread.timecreated AS timeread
FROM {message_conversations} mc
INNER JOIN {messages} m
ON m.conversationid = mc.id
+13 -6
View File
@@ -94,7 +94,8 @@ class core_message_external extends external_api {
$message['textformat']);
$createdmessage->text = message_format_message_text((object) [
'smallmessage' => $createdmessage->text,
'fullmessageformat' => external_validate_format($message['textformat'])
'fullmessageformat' => external_validate_format($message['textformat']),
'fullmessagetrust' => $createdmessage->fullmessagetrust
]);
$messages[] = $createdmessage;
}
@@ -203,10 +204,6 @@ class core_message_external extends external_api {
}
if ($success) {
$resultmsg['msgid'] = $success;
$resultmsg['text'] = message_format_message_text((object) [
'smallmessage' => $message['text'],
'fullmessageformat' => external_validate_format($message['textformat'])
]);
$resultmsg['timecreated'] = time();
$messageids[] = $success;
} else {
@@ -221,11 +218,21 @@ class core_message_external extends external_api {
}
if (!empty($messageids)) {
$messagerecords = $DB->get_records_list('messages', 'id', $messageids, '', 'id, conversationid');
$messagerecords = $DB->get_records_list(
'messages',
'id',
$messageids,
'',
'id, conversationid, smallmessage, fullmessageformat, fullmessagetrust');
$resultmessages = array_map(function($resultmessage) use ($messagerecords, $USER) {
$id = $resultmessage['msgid'];
$resultmessage['conversationid'] = isset($messagerecords[$id]) ? $messagerecords[$id]->conversationid : null;
$resultmessage['useridfrom'] = $USER->id;
$resultmessage['text'] = message_format_message_text((object) [
'smallmessage' => $messagerecords[$id]->smallmessage,
'fullmessageformat' => external_validate_format($messagerecords[$id]->fullmessageformat),
'fullmessagetrust' => $messagerecords[$id]->fullmessagetrust
]);
return $resultmessage;
}, $resultmessages);
}
+1
View File
@@ -114,6 +114,7 @@ function message_format_message_text($message, $forcetexttohtml = false) {
$options = new stdClass();
$options->para = false;
$options->blanktarget = true;
$options->trusted = isset($message->fullmessagetrust) ? $message->fullmessagetrust : false;
$format = $message->fullmessageformat;
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2019041000.01; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2019041000.02; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.