Commit e2d7687f authored by skodak's avatar skodak
Browse files

MDL-18902 reimplemented trusstext support in forum + standardising format column for text fields

parent 614aa8b0
......@@ -267,7 +267,7 @@
fwrite ($bf,full_tag("MAILED",8,false,$for_pos->mailed));
fwrite ($bf,full_tag("SUBJECT",8,false,$for_pos->subject));
fwrite ($bf,full_tag("MESSAGE",8,false,$for_pos->message));
fwrite ($bf,full_tag("FORMAT",8,false,$for_pos->format));
fwrite ($bf,full_tag("FORMAT",8,false,$for_pos->messageformat));
fwrite ($bf,full_tag("ATTACHMENT",8,false,$for_pos->attachment));
fwrite ($bf,full_tag("TOTALSCORE",8,false,$for_pos->totalscore));
fwrite ($bf,full_tag("MAILNOW",8,false,$for_pos->mailnow));
......
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/forum/db" VERSION="20080908" COMMENT="XMLDB file for Moodle mod/forum"
<XMLDB PATH="mod/forum/db" VERSION="20090420" COMMENT="XMLDB file for Moodle mod/forum"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
......@@ -69,9 +69,10 @@
<FIELD NAME="modified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="created" NEXT="mailed"/>
<FIELD NAME="mailed" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="modified" NEXT="subject"/>
<FIELD NAME="subject" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="mailed" NEXT="message"/>
<FIELD NAME="message" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="subject" NEXT="format"/>
<FIELD NAME="format" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="message" NEXT="attachment"/>
<FIELD NAME="attachment" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="format" NEXT="totalscore"/>
<FIELD NAME="message" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="subject" NEXT="messageformat"/>
<FIELD NAME="messageformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="message" NEXT="messagetrust"/>
<FIELD NAME="messagetrust" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="messageformat" NEXT="attachment"/>
<FIELD NAME="attachment" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="messagetrust" NEXT="totalscore"/>
<FIELD NAME="totalscore" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="attachment" NEXT="mailnow"/>
<FIELD NAME="mailnow" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="totalscore"/>
</FIELDS>
......
......@@ -176,8 +176,51 @@ function xmldb_forum_upgrade($oldversion) {
upgrade_mod_savepoint($result, 2008090800, 'forum');
}
if ($result && $oldversion < 2009042000) {
/// Rename field format on table forum_posts to messageformat
$table = new xmldb_table('forum_posts');
$field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null, null, '0', 'message');
/// Launch rename field format
$dbman->rename_field($table, $field, 'messageformat');
/// forum savepoint reached
upgrade_mod_savepoint($result, 2009042000, 'forum');
}
if ($result && $oldversion < 2009042001) {
/// Define field messagetrust to be added to forum_posts
$table = new xmldb_table('forum_posts');
$field = new xmldb_field('messagetrust', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'messageformat');
/// Launch add field messagetrust
$dbman->add_field($table, $field);
/// forum savepoint reached
upgrade_mod_savepoint($result, 2009042001, 'forum');
}
if ($result && $oldversion < 2009042002) {
$trustmark = '#####TRUSTTEXT#####';
$rs = $DB->get_recordset_sql("SELECT * FROM {forum_posts} WHERE message LIKE '$trustmark%'");
foreach ($rs as $post) {
if (strpos($post->entrycomment, $trustmark) !== 0) {
// probably lowercase in some DBs
continue;
}
$post->message = trusttext_strip($post->message);
$post->messagetrust = 1;
$DB->update_record('forum_posts', $post);
}
$rs->close();
/// forum savepoint reached
upgrade_mod_savepoint($result, 2009042002, 'forum');
}
return $result;
}
......
......@@ -58,14 +58,14 @@ function forum_add_instance($forum) {
if ($forum->type == 'single') { // Create related discussion.
$discussion = new object();
$discussion->course = $forum->course;
$discussion->forum = $forum->id;
$discussion->name = $forum->name;
$discussion->intro = $forum->intro;
$discussion->assessed = $forum->assessed;
$discussion->format = $forum->format;
$discussion->mailnow = false;
$discussion->groupid = -1;
$discussion->course = $forum->course;
$discussion->forum = $forum->id;
$discussion->name = $forum->name;
$discussion->intro = $forum->intro;
$discussion->assessed = $forum->assessed;
$discussion->messageformat = $forum->messageformat;
$discussion->mailnow = false;
$discussion->groupid = -1;
$message = '';
......@@ -132,14 +132,14 @@ function forum_update_instance($forum) {
} else {
// try to recover by creating initial discussion - MDL-16262
$discussion = new object();
$discussion->course = $forum->course;
$discussion->forum = $forum->id;
$discussion->name = $forum->name;
$discussion->intro = $forum->intro;
$discussion->assessed = $forum->assessed;
$discussion->format = $forum->type;
$discussion->mailnow = false;
$discussion->groupid = -1;
$discussion->course = $forum->course;
$discussion->forum = $forum->id;
$discussion->name = $forum->name;
$discussion->intro = $forum->intro;
$discussion->assessed = $forum->assessed;
$discussion->messageformat = $forum->messageformat;
$discussion->mailnow = false;
$discussion->groupid = -1;
forum_add_discussion($discussion, null, $message);
......@@ -959,7 +959,7 @@ function forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfro
}
$posttext .= "\n".$strbynameondate."\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= format_text_email(trusttext_strip($post->message), $post->format);
$posttext .= format_text_email($post->message, $post->messageformat);
$posttext .= "\n\n";
$posttext .= forum_print_attachments($post, $cm, "text");
......@@ -2856,7 +2856,7 @@ function forum_make_mail_post($course, $cm, $forum, $discussion, $post, $userfro
// format the post body
$options = new object();
$options->para = true;
$formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $course->id);
$formattedtext = format_text($post->message, $post->messageformat, $options, $course->id);
$output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';
......@@ -3122,11 +3122,11 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
}
$options = new object();
$options->para = false;
$options->trusttext = true;
$options->para = false;
$options->trusted = $post->messagetrust;
if ($link and (strlen(strip_tags($post->message)) > $CFG->forum_longpost)) {
// Print shortened version
echo format_text(forum_shorten_post($post->message), $post->format, $options, $course->id);
echo format_text(forum_shorten_post($post->message), $post->messageformat, $options, $course->id);
$numwords = count_words(strip_tags($post->message));
echo '<div class="posting"><a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'">';
echo get_string('readtherest', 'forum');
......@@ -3135,9 +3135,9 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
// Print whole message
echo '<div class="posting">';
if ($highlight) {
echo highlight($highlight, format_text($post->message, $post->format, $options, $course->id));
echo highlight($highlight, format_text($post->message, $post->messageformat, $options, $course->id));
} else {
echo format_text($post->message, $post->format, $options, $course->id);
echo format_text($post->message, $post->messageformat, $options, $course->id);
}
echo '</div>';
echo $attachedimages;
......@@ -4238,19 +4238,20 @@ function forum_add_discussion($discussion, $mform=null, &$message=null) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$post = new object();
$post->discussion = 0;
$post->parent = 0;
$post->userid = $USER->id;
$post->created = $timenow;
$post->modified = $timenow;
$post->mailed = 0;
$post->subject = $discussion->name;
$post->message = $discussion->intro;
$post->attachments = $discussion->attachments;
$post->forum = $forum->id; // speedup
$post->course = $forum->course; // speedup
$post->format = $discussion->format;
$post->mailnow = $discussion->mailnow;
$post->discussion = 0;
$post->parent = 0;
$post->userid = $USER->id;
$post->created = $timenow;
$post->modified = $timenow;
$post->mailed = 0;
$post->subject = $discussion->name;
$post->message = $discussion->intro;
$post->messageformat = $discussion->messageformat;
$post->messagetrust = $discussion->messagetrust;
$post->attachments = $discussion->attachments;
$post->forum = $forum->id; // speedup
$post->course = $forum->course; // speedup
$post->mailnow = $discussion->mailnow;
if (! $post->id = $DB->insert_record("forum_posts", $post) ) {
return 0;
......@@ -7425,7 +7426,7 @@ class forum_portfolio_caller extends portfolio_module_caller_base {
// format the post body
$options = new object();
$options->para = true;
$formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $this->get('course')->id);
$formattedtext = format_text($post->message, $post->messageformat, $options, $this->get('course')->id);
$output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';
......
......@@ -98,13 +98,15 @@
// Load up the $post variable.
$post = new object();
$post->course = $course->id;
$post->forum = $forum->id;
$post->discussion = 0; // ie discussion # not defined yet
$post->parent = 0;
$post->subject = '';
$post->userid = $USER->id;
$post->message = '';
$post->course = $course->id;
$post->forum = $forum->id;
$post->discussion = 0; // ie discussion # not defined yet
$post->parent = 0;
$post->subject = '';
$post->userid = $USER->id;
$post->message = '';
$post->messageformat = FORMAT_HTML; // TODO: better default
$post->messagetrust = 0;
if (isset($groupid)) {
$post->groupid = $groupid;
......@@ -226,7 +228,7 @@
$post->forum = $forum->id;
$post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid;
trusttext_prepare_edit($post->message, $post->format, can_use_html_editor(), $modcontext);
$post = trusttext_pre_edit($post, 'message', $modcontext);
unset($SESSION->fromdiscussion);
......@@ -464,7 +466,7 @@
if ($USER->id != $post->userid) { // Not the original author, so add a message to the end
$data->date = userdate($post->modified);
if ($post->format == FORMAT_HTML) {
if ($post->messageformat == FORMAT_HTML) {
$data->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$post->course.'">'.
fullname($USER).'</a>';
$post->message .= '<p>(<span class="edited">'.get_string('editedby', 'forum', $data).'</span>)</p>';
......@@ -502,7 +504,7 @@
'subject'=>$post->subject,
'message'=>array(
'text'=>$currenttext,
'format'=>empty($post->format) ? FORMAT_HTML : $post->format, //TODO: add some better default
'format'=>empty($post->messageformat) ? FORMAT_HTML : $post->messageformat, //TODO: add some better default
'itemid'=>$draftid_editor
),
'subscribe'=>$subscribe?1:0,
......@@ -541,10 +543,10 @@
$errordestination = $SESSION->fromurl;
}
trusttext_after_edit($fromform->message['text'], $modcontext);
$fromform->format = $fromform->message['format'];
$fromform->itemid = $fromform->message['itemid'];
$fromform->message = $fromform->message['text'];
$fromform->itemid = $fromform->message['itemid'];
$fromform->message = $fromform->message['text'];
$fromform->messageformat = $fromform->message['format'];
$fromform->messagetrust = trusttext_trusted($modcontext);
if ($fromform->edit) { // Updating a post
unset($fromform->groupid);
......@@ -611,7 +613,7 @@
} else if ($fromform->discussion) { // Adding a new post to an existing discussion
unset($fromform->groupid);
$message = '';
$addpost=$fromform;
$addpost = $fromform;
$addpost->forum=$forum->id;
if ($fromform->id = forum_add_new_post($addpost, $mform_post, $message)) {
......
......@@ -141,7 +141,7 @@
$sd->name = $forum->name;
$sd->intro = $forum->intro;
$sd->assessed = $forum->assessed;
$sd->format = $defaultformat;
$sd->messageformat = $defaultformat;
$sd->mailnow = false;
//Insert dicussion/post data
$sdid = forum_add_discussion($sd, $sd->intro, $forum);
......@@ -470,7 +470,7 @@
$post->mailed = backup_todb($pos_info['#']['MAILED']['0']['#']);
$post->subject = backup_todb($pos_info['#']['SUBJECT']['0']['#']);
$post->message = backup_todb($pos_info['#']['MESSAGE']['0']['#']);
$post->format = backup_todb($pos_info['#']['FORMAT']['0']['#']);
$post->messageformat = backup_todb($pos_info['#']['FORMAT']['0']['#']);
$post->attachment = backup_todb($pos_info['#']['ATTACHMENT']['0']['#']);
$post->totalscore = backup_todb($pos_info['#']['TOTALSCORE']['0']['#']);
$post->mailnow = backup_todb($pos_info['#']['MAILNOW']['0']['#']);
......@@ -665,7 +665,7 @@
$status = true;
//Convert forum_posts->message
if ($records = $DB->get_records_sql("SELECT p.id, p.message, p.format
if ($records = $DB->get_records_sql("SELECT p.id, p.message, p.messageformat
FROM {forum_posts} p,
{forum_discussions} d,
{forum} f,
......@@ -673,7 +673,7 @@
WHERE d.id = p.discussion AND
f.id = d.forum AND
f.course = ? AND
p.format = ".FORMAT_WIKI. " AND
p.messageformat = ".FORMAT_WIKI. " AND
b.backup_code = ? AND
b.table_name = 'forum_posts' AND
b.new_id = p.id", array($restore->course_id, $restore->backup_unique_code))) {
......@@ -683,7 +683,7 @@
//Convert to Markdown
$wtm = new WikiToMarkdown();
$record->message = $wtm->convert($record->message, $restore->course_id);
$record->format = FORMAT_MARKDOWN;
$record->messageformat = FORMAT_MARKDOWN;
$status = $DB->update_record('forum_posts', $record);
//Do some output
$i++;
......
......@@ -166,7 +166,8 @@
u.lastname AS userlastname,
p.message AS postmessage,
p.created AS postcreated,
p.format AS postformat
p.messageformat AS postformat,
p.messagetrust AS posttrust
FROM {forum_discussions} d,
{forum_posts} p,
{user} u
......@@ -181,7 +182,7 @@
$user = NULL;
$formatoptions = new object;
$formatoptions->trusttext = true;
$formatoptions->trusted = $rec->posttrust;
foreach ($recs as $rec) {
unset($item);
......@@ -222,7 +223,8 @@
p.subject AS postsubject,
p.message AS postmessage,
p.created AS postcreated,
p.format AS postformat
p.messageformat AS postformat,
p.messagetrust AS posttrust
FROM {forum_discussions} d,
{forum_posts} p,
{user} u
......@@ -235,7 +237,7 @@
$user = NULL;
$formatoptions = new object;
$formatoptions->trusttext = true;
$formatoptions->trusted = $rec->posttrust;
foreach ($recs as $rec) {
unset($item);
......
......@@ -212,9 +212,9 @@
$missing_terms = "";
$options = new object();
$options->trusttext = true;
$options->trusted = $post->messagetrust;
$message = highlight($strippedsearch,
format_text($post->message, $post->format, $options, $course->id),
format_text($post->message, $post->messageformat, $options, $course->id),
0, '<fgw9sdpq4>', '</fgw9sdpq4>');
foreach ($searchterms as $searchterm) {
......
......@@ -5,8 +5,8 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2008090800;
$module->requires = 2008090800; // Requires this Moodle version
$module->version = 2009042002;
$module->requires = 2009041700; // Requires this Moodle version
$module->cron = 60;
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment