Skip to content

Commit

Permalink
MDL-28724 wiki : Fixed bugs in wiki forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Aparup Banerjee committed Sep 12, 2011
1 parent 4f65f98 commit 1fc6a60
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 18 deletions.
23 changes: 21 additions & 2 deletions mod/wiki/instancecomments.php
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions mod/wiki/lang/en/wiki.php
Expand Up @@ -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';
Expand Down
93 changes: 82 additions & 11 deletions mod/wiki/pagelib.php
Expand Up @@ -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');
Expand All @@ -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);
}

}
Expand Down Expand Up @@ -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
*
Expand Down
6 changes: 4 additions & 2 deletions mod/wiki/restoreversion.php
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions mod/wiki/styles.css
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1fc6a60

Please sign in to comment.