Merge branch 'MDL-28724' of git://github.com/nebgor/moodle

This commit is contained in:
Sam Hemelryk 2011-09-12 17:24:49 +12:00
commit 16ff2aee7d
5 changed files with 112 additions and 18 deletions

View file

@ -42,6 +42,7 @@ $action = optional_param('action', '', PARAM_ACTION);
$id = optional_param('id', 0, PARAM_INT); $id = optional_param('id', 0, PARAM_INT);
$commentid = optional_param('commentid', 0, PARAM_INT); $commentid = optional_param('commentid', 0, PARAM_INT);
$newcontent = optional_param('newcontent', '', PARAM_CLEANHTML); $newcontent = optional_param('newcontent', '', PARAM_CLEANHTML);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
if (!$page = wiki_get_page($pageid)) { if (!$page = wiki_get_page($pageid)) {
print_error('incorrectpageid', 'wiki'); print_error('incorrectpageid', 'wiki');
@ -59,8 +60,26 @@ if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
} }
require_login($course->id, true, $cm); require_login($course->id, true, $cm);
$comm = new page_wiki_handlecomments($wiki, $subwiki, $cm); if ($action == 'add' || $action == 'edit') {
$comm->set_page($page); //just check sesskey
if (!confirm_sesskey()) {
print_error(get_string('invalidsesskey', 'wiki'));
}
$comm = new page_wiki_handlecomments($wiki, $subwiki, $cm);
$comm->set_page($page);
} else {
if(!$confirm) {
$comm = new page_wiki_deletecomment($wiki, $subwiki, $cm);
$comm->set_page($page);
$comm->set_url();
} else {
$comm = new page_wiki_handlecomments($wiki, $subwiki, $cm);
$comm->set_page($page);
if (!confirm_sesskey()) {
print_error(get_string('invalidsesskey', 'wiki'));
}
}
}
if ($action == 'delete') { if ($action == 'delete') {
$comm->set_action($action, $commentid, 0); $comm->set_action($action, $commentid, 0);

View file

@ -42,6 +42,8 @@ $string['defaultformat_help'] = 'This setting determines the default format used
* Creole - A common wiki markup language for which a small edit toolbar is available * Creole - A common wiki markup language for which a small edit toolbar is available
* Nwiki - Mediawiki-like markup language used in the contributed Nwiki module'; * Nwiki - Mediawiki-like markup language used in the contributed Nwiki module';
$string['deletecomment'] = 'Deleting comment'; $string['deletecomment'] = 'Deleting comment';
$string['deletecommentcheck'] = 'Delete comment';
$string['deletecommentcheckfull'] = 'Are you sure you want to delete the comment?';
$string['deleteupload'] = 'Delete'; $string['deleteupload'] = 'Delete';
$string['deletedbegins'] = 'Deleted begins'; $string['deletedbegins'] = 'Deleted begins';
$string['deletedends'] = 'Deleted ends'; $string['deletedends'] = 'Deleted ends';

View file

@ -761,6 +761,10 @@ class page_wiki_editcomment extends page_wiki {
$pageid = $this->page->id; $pageid = $this->page->id;
if ($this->format == 'html') { if ($this->format == 'html') {
$com = new stdClass();
$com->action = 'add';
$com->commentoptions = array('trusttext' => true, 'maxfiles' => 0);
$this->form->set_data($com);
$this->form->display(); $this->form->display();
} else { } else {
wiki_print_editor_wiki($this->page->id, null, $this->format, -1, null, false, null, 'addcomments'); wiki_print_editor_wiki($this->page->id, null, $this->format, -1, null, false, null, 'addcomments');
@ -773,18 +777,14 @@ class page_wiki_editcomment extends page_wiki {
require_once($CFG->dirroot . '/mod/wiki/editors/wiki_editor.php'); require_once($CFG->dirroot . '/mod/wiki/editors/wiki_editor.php');
if ($this->format == 'html') { if ($this->format == 'html') {
$commentoptions = array('trusttext' => true, 'maxfiles' => 0);
$com->action = 'edit'; $com->action = 'edit';
$com->entrycomment_editor['text'] = $com->content; $com->entrycomment_editor['text'] = $com->content;
$com->commentoptions = array('trusttext' => true, 'maxfiles' => 0);
$this->form->set_data($com, $commentoptions); $this->form->set_data($com);
$this->form->display(); $this->form->display();
} else { } else {
$action = 'edit'; wiki_print_editor_wiki($this->page->id, $com->content, $this->format, -1, null, false, array(), 'editcomments', $com->id);
$commentid = $com->id;
$pageid = $this->page->id;
$destination = $CFG->wwwroot . '/mod/wiki/instancecomments.php?pageid=' . $pageid . '&id=' . $commentid . '&action=' . $action;
wiki_print_editor_wiki($this->page->id, $com->content, $this->format, -1, null, false, array(), 'editcomments', $commentid);
} }
} }
@ -1859,16 +1859,88 @@ class page_wiki_restoreversion extends page_wiki {
* If true, restores the old version and redirects the user to the 'view' tab. * If true, restores the old version and redirects the user to the 'view' tab.
*/ */
private function print_restoreversion() { private function print_restoreversion() {
global $CFG, $OUTPUT; global $OUTPUT;
$version = wiki_get_version($this->version->id); $version = wiki_get_version($this->version->id);
$optionsyes = array('confirm'=>1, 'pageid'=>$this->page->id, 'versionid'=>$version->id, 'sesskey'=>sesskey());
$restoreurl = new moodle_url('/mod/wiki/restoreversion.php', $optionsyes);
$return = new moodle_url('/mod/wiki/viewversion.php', array('pageid'=>$this->page->id, 'versionid'=>$version->id));
echo $OUTPUT->heading(get_string('restoreconfirm', 'wiki', $version->version), 2); echo $OUTPUT->heading(get_string('restoreconfirm', 'wiki', $version->version), 2);
print_container_start(false, 'wiki_restoreform'); print_container_start(false, 'wiki_restoreform');
echo '<form class="wiki_restore_yes" action="' . $CFG->wwwroot . '/mod/wiki/restoreversion.php?pageid=' . $this->page->id . '&amp;versionid=' . $version->id . '" method="post" id="restoreversion">'; echo '<form class="wiki_restore_yes" action="' . $restoreurl . '" method="post" id="restoreversion">';
echo '<div><input type="submit" name="confirm" value="' . get_string('yes') . '" /></div>'; echo '<div><input type="submit" name="confirm" value="' . get_string('yes') . '" /></div>';
echo '</form>'; echo '</form>';
echo '<form class="wiki_restore_no" action="' . $CFG->wwwroot . '/mod/wiki/viewversion.php?pageid=' . $this->page->id . '&amp;versionid=' . $version->id . '" method="post">'; echo '<form class="wiki_restore_no" action="' . $return . '" method="post">';
echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>';
echo '</form>';
print_container_end();
}
}
/**
* Class that models the behavior of wiki's delete comment confirmation page
*
*/
class page_wiki_deletecomment extends page_wiki {
private $commentid;
function print_header() {
parent::print_header();
$this->print_pagetitle();
}
function print_content() {
$this->printconfirmdelete();
}
function set_url() {
global $PAGE;
$PAGE->set_url('/mod/wiki/instancecomments.php', array('pageid' => $this->page->id, 'commentid' => $this->commentid));
}
public function set_action($action, $commentid, $content) {
$this->action = $action;
$this->commentid = $commentid;
$this->content = $content;
}
protected function create_navbar() {
global $PAGE;
parent::create_navbar();
$PAGE->navbar->add(get_string('deletecommentcheck', 'wiki'));
}
protected function setup_tabs() {
parent::setup_tabs(array('linkedwhenactive' => 'comments', 'activetab' => 'comments'));
}
/**
* Prints the comment deletion confirmation form
*
* @param page $page The page whose version will be restored
* @param int $versionid The version to be restored
* @param bool $confirm If false, shows a yes/no confirmation page.
* If true, restores the old version and redirects the user to the 'view' tab.
*/
private function printconfirmdelete() {
global $OUTPUT;
$strdeletecheck = get_string('deletecommentcheck', 'wiki');
$strdeletecheckfull = get_string('deletecommentcheckfull', 'wiki');
//ask confirmation
$optionsyes = array('confirm'=>1, 'pageid'=>$this->page->id, 'action'=>'delete', 'commentid'=>$this->commentid, 'sesskey'=>sesskey());
$deleteurl = new moodle_url('/mod/wiki/instancecomments.php', $optionsyes);
$return = new moodle_url('/mod/wiki/comments.php', array('pageid'=>$this->page->id));
echo $OUTPUT->heading($strdeletecheckfull);
print_container_start(false, 'wiki_deletecommentform');
echo '<form class="wiki_deletecomment_yes" action="' . $deleteurl . '" method="post" id="deletecomment">';
echo '<div><input type="submit" name="confirmdeletecomment" value="' . get_string('yes') . '" /></div>';
echo '</form>';
echo '<form class="wiki_deletecomment_no" action="' . $return . '" method="post">';
echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>'; echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>';
echo '</form>'; echo '</form>';
print_container_end(); print_container_end();
@ -1876,7 +1948,6 @@ class page_wiki_restoreversion extends page_wiki {
} }
/** /**
*
* Class that models the behavior of wiki's * Class that models the behavior of wiki's
* save page * save page
* *

View file

@ -38,7 +38,7 @@ require_once($CFG->dirroot . '/mod/wiki/pagelib.php');
$pageid = required_param('pageid', PARAM_INT); $pageid = required_param('pageid', PARAM_INT);
$versionid = required_param('versionid', PARAM_INT); $versionid = required_param('versionid', PARAM_INT);
$confirm = optional_param('confirm', '', PARAM_ALPHA); $confirm = optional_param('confirm', 0, PARAM_BOOL);
if (!$page = wiki_get_page($pageid)) { if (!$page = wiki_get_page($pageid)) {
print_error('incorrectpageid', 'wiki'); print_error('incorrectpageid', 'wiki');
@ -63,7 +63,9 @@ require_login($course->id, true, $cm);
add_to_log($course->id, "restore", "restore", "view.php?id=$cm->id", "$wiki->id"); add_to_log($course->id, "restore", "restore", "view.php?id=$cm->id", "$wiki->id");
if ($confirm) { if ($confirm) {
if (!confirm_sesskey()) {
print_error(get_string('invalidsesskey', 'wiki'));
}
$wikipage = new page_wiki_confirmrestore($wiki, $subwiki, $cm); $wikipage = new page_wiki_confirmrestore($wiki, $subwiki, $cm);
$wikipage->set_page($page); $wikipage->set_page($page);
$wikipage->set_versionid($versionid); $wikipage->set_versionid($versionid);

View file

@ -145,15 +145,15 @@
border: thin black solid; border: thin black solid;
} }
.wiki_restore_yes { .wiki_restore_yes, .wiki_deletecomment_yes {
float: left; float: left;
} }
.wiki_restore_no { .wiki_restore_no, .wiki_deletecomment_no {
float: right; float: right;
} }
.wiki_restoreform { .wiki_restoreform, .wiki_deletecommentform {
width: 10%; width: 10%;
margin: auto; margin: auto;
} }