Permalink
Browse files

MDL-28724 wiki : Fixed bugs in wiki forms

  • Loading branch information...
1 parent 9e6ef6c commit 910671644c7aec6d1a707e1fb782129f2ab5b40c @nebgor nebgor committed with Sam Hemelryk Sep 12, 2011
Showing with 112 additions and 18 deletions.
  1. +21 −2 mod/wiki/instancecomments.php
  2. +2 −0 mod/wiki/lang/en/wiki.php
  3. +82 −11 mod/wiki/pagelib.php
  4. +4 −2 mod/wiki/restoreversion.php
  5. +3 −3 mod/wiki/styles.css
View
23 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);
View
2 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';
View
93 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 '<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 '</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 '</form>';
+ print_container_end();
+ }
+}
+
+/**
* Class that models the behavior of wiki's
* save page
*
View
6 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);
View
6 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;
}

0 comments on commit 9106716

Please sign in to comment.