diff --git a/mod/wiki/instancecomments.php b/mod/wiki/instancecomments.php index cec3f4a864601..80aa4277faf22 100644 --- a/mod/wiki/instancecomments.php +++ b/mod/wiki/instancecomments.php @@ -42,6 +42,7 @@ $id = optional_param('id', 0, PARAM_INT); $commentid = optional_param('commentid', 0, PARAM_INT); $newcontent = optional_param('newcontent', '', PARAM_CLEANHTML); +$confirm = optional_param('confirm', 0, PARAM_BOOL); if (!$page = wiki_get_page($pageid)) { print_error('incorrectpageid', 'wiki'); @@ -59,8 +60,26 @@ } require_login($course->id, true, $cm); -$comm = new page_wiki_handlecomments($wiki, $subwiki, $cm); -$comm->set_page($page); +if ($action == 'add' || $action == 'edit') { + //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') { $comm->set_action($action, $commentid, 0); diff --git a/mod/wiki/lang/en/wiki.php b/mod/wiki/lang/en/wiki.php index e2ce4682af2f4..bbe4e64df4de3 100644 --- a/mod/wiki/lang/en/wiki.php +++ b/mod/wiki/lang/en/wiki.php @@ -42,6 +42,8 @@ * 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'; $string['deletecomment'] = 'Deleting comment'; +$string['deletecommentcheck'] = 'Delete comment'; +$string['deletecommentcheckfull'] = 'Are you sure you want to delete the comment?'; $string['deleteupload'] = 'Delete'; $string['deletedbegins'] = 'Deleted begins'; $string['deletedends'] = 'Deleted ends'; diff --git a/mod/wiki/pagelib.php b/mod/wiki/pagelib.php index 0c7c8b98813d1..751a001352800 100644 --- a/mod/wiki/pagelib.php +++ b/mod/wiki/pagelib.php @@ -761,6 +761,10 @@ private function add_comment_form() { $pageid = $this->page->id; 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(); } else { wiki_print_editor_wiki($this->page->id, null, $this->format, -1, null, false, null, 'addcomments'); @@ -773,18 +777,14 @@ private function edit_comment_form($com) { require_once($CFG->dirroot . '/mod/wiki/editors/wiki_editor.php'); if ($this->format == 'html') { - $commentoptions = array('trusttext' => true, 'maxfiles' => 0); $com->action = 'edit'; $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(); } else { - $action = 'edit'; - $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); + wiki_print_editor_wiki($this->page->id, $com->content, $this->format, -1, null, false, array(), 'editcomments', $com->id); } } @@ -1859,24 +1859,95 @@ protected function setup_tabs() { * If true, restores the old version and redirects the user to the 'view' tab. */ private function print_restoreversion() { - global $CFG, $OUTPUT; + global $OUTPUT; $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); print_container_start(false, 'wiki_restoreform'); - echo '
'; + echo ''; echo '
'; echo '
'; - echo '
'; + echo ''; echo '
'; echo '
'; 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 '
'; + echo '
'; + echo '
'; + echo '
'; + echo '
'; + echo '
'; + print_container_end(); + } +} + +/** * Class that models the behavior of wiki's * save page * diff --git a/mod/wiki/restoreversion.php b/mod/wiki/restoreversion.php index 4abd2e57f5737..a959b322565ee 100644 --- a/mod/wiki/restoreversion.php +++ b/mod/wiki/restoreversion.php @@ -38,7 +38,7 @@ $pageid = required_param('pageid', 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)) { print_error('incorrectpageid', 'wiki'); @@ -63,7 +63,9 @@ add_to_log($course->id, "restore", "restore", "view.php?id=$cm->id", "$wiki->id"); if ($confirm) { - + if (!confirm_sesskey()) { + print_error(get_string('invalidsesskey', 'wiki')); + } $wikipage = new page_wiki_confirmrestore($wiki, $subwiki, $cm); $wikipage->set_page($page); $wikipage->set_versionid($versionid); diff --git a/mod/wiki/styles.css b/mod/wiki/styles.css index b76bb8f9e72e6..18e0391422e8a 100644 --- a/mod/wiki/styles.css +++ b/mod/wiki/styles.css @@ -145,15 +145,15 @@ border: thin black solid; } -.wiki_restore_yes { +.wiki_restore_yes, .wiki_deletecomment_yes { float: left; } -.wiki_restore_no { +.wiki_restore_no, .wiki_deletecomment_no { float: right; } -.wiki_restoreform { +.wiki_restoreform, .wiki_deletecommentform { width: 10%; margin: auto; }