Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-28724 wiki : Fixed bugs in wiki forms

  • Loading branch information...
commit 910671644c7aec6d1a707e1fb782129f2ab5b40c 1 parent 9e6ef6c
Aparup Banerjee nebgor authored samhemelryk committed
23 mod/wiki/instancecomments.php
@@ -42,6 +42,7 @@
42 42 $id = optional_param('id', 0, PARAM_INT);
43 43 $commentid = optional_param('commentid', 0, PARAM_INT);
44 44 $newcontent = optional_param('newcontent', '', PARAM_CLEANHTML);
  45 +$confirm = optional_param('confirm', 0, PARAM_BOOL);
45 46
46 47 if (!$page = wiki_get_page($pageid)) {
47 48 print_error('incorrectpageid', 'wiki');
@@ -59,8 +60,26 @@
59 60 }
60 61 require_login($course->id, true, $cm);
61 62
62   -$comm = new page_wiki_handlecomments($wiki, $subwiki, $cm);
63   -$comm->set_page($page);
  63 +if ($action == 'add' || $action == 'edit') {
  64 + //just check sesskey
  65 + if (!confirm_sesskey()) {
  66 + print_error(get_string('invalidsesskey', 'wiki'));
  67 + }
  68 + $comm = new page_wiki_handlecomments($wiki, $subwiki, $cm);
  69 + $comm->set_page($page);
  70 +} else {
  71 + if(!$confirm) {
  72 + $comm = new page_wiki_deletecomment($wiki, $subwiki, $cm);
  73 + $comm->set_page($page);
  74 + $comm->set_url();
  75 + } else {
  76 + $comm = new page_wiki_handlecomments($wiki, $subwiki, $cm);
  77 + $comm->set_page($page);
  78 + if (!confirm_sesskey()) {
  79 + print_error(get_string('invalidsesskey', 'wiki'));
  80 + }
  81 + }
  82 +}
64 83
65 84 if ($action == 'delete') {
66 85 $comm->set_action($action, $commentid, 0);
2  mod/wiki/lang/en/wiki.php
@@ -42,6 +42,8 @@
42 42 * Creole - A common wiki markup language for which a small edit toolbar is available
43 43 * Nwiki - Mediawiki-like markup language used in the contributed Nwiki module';
44 44 $string['deletecomment'] = 'Deleting comment';
  45 +$string['deletecommentcheck'] = 'Delete comment';
  46 +$string['deletecommentcheckfull'] = 'Are you sure you want to delete the comment?';
45 47 $string['deleteupload'] = 'Delete';
46 48 $string['deletedbegins'] = 'Deleted begins';
47 49 $string['deletedends'] = 'Deleted ends';
93 mod/wiki/pagelib.php
@@ -761,6 +761,10 @@ private function add_comment_form() {
761 761 $pageid = $this->page->id;
762 762
763 763 if ($this->format == 'html') {
  764 + $com = new stdClass();
  765 + $com->action = 'add';
  766 + $com->commentoptions = array('trusttext' => true, 'maxfiles' => 0);
  767 + $this->form->set_data($com);
764 768 $this->form->display();
765 769 } else {
766 770 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) {
773 777 require_once($CFG->dirroot . '/mod/wiki/editors/wiki_editor.php');
774 778
775 779 if ($this->format == 'html') {
776   - $commentoptions = array('trusttext' => true, 'maxfiles' => 0);
777 780 $com->action = 'edit';
778 781 $com->entrycomment_editor['text'] = $com->content;
  782 + $com->commentoptions = array('trusttext' => true, 'maxfiles' => 0);
779 783
780   - $this->form->set_data($com, $commentoptions);
  784 + $this->form->set_data($com);
781 785 $this->form->display();
782 786 } else {
783   - $action = 'edit';
784   - $commentid = $com->id;
785   - $pageid = $this->page->id;
786   - $destination = $CFG->wwwroot . '/mod/wiki/instancecomments.php?pageid=' . $pageid . '&id=' . $commentid . '&action=' . $action;
787   - wiki_print_editor_wiki($this->page->id, $com->content, $this->format, -1, null, false, array(), 'editcomments', $commentid);
  787 + wiki_print_editor_wiki($this->page->id, $com->content, $this->format, -1, null, false, array(), 'editcomments', $com->id);
788 788 }
789 789
790 790 }
@@ -1859,24 +1859,95 @@ protected function setup_tabs() {
1859 1859 * If true, restores the old version and redirects the user to the 'view' tab.
1860 1860 */
1861 1861 private function print_restoreversion() {
1862   - global $CFG, $OUTPUT;
  1862 + global $OUTPUT;
1863 1863
1864 1864 $version = wiki_get_version($this->version->id);
1865 1865
  1866 + $optionsyes = array('confirm'=>1, 'pageid'=>$this->page->id, 'versionid'=>$version->id, 'sesskey'=>sesskey());
  1867 + $restoreurl = new moodle_url('/mod/wiki/restoreversion.php', $optionsyes);
  1868 + $return = new moodle_url('/mod/wiki/viewversion.php', array('pageid'=>$this->page->id, 'versionid'=>$version->id));
  1869 +
1866 1870 echo $OUTPUT->heading(get_string('restoreconfirm', 'wiki', $version->version), 2);
1867 1871 print_container_start(false, 'wiki_restoreform');
1868   - 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">';
  1872 + echo '<form class="wiki_restore_yes" action="' . $restoreurl . '" method="post" id="restoreversion">';
1869 1873 echo '<div><input type="submit" name="confirm" value="' . get_string('yes') . '" /></div>';
1870 1874 echo '</form>';
1871   - echo '<form class="wiki_restore_no" action="' . $CFG->wwwroot . '/mod/wiki/viewversion.php?pageid=' . $this->page->id . '&amp;versionid=' . $version->id . '" method="post">';
  1875 + echo '<form class="wiki_restore_no" action="' . $return . '" method="post">';
1872 1876 echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>';
1873 1877 echo '</form>';
1874 1878 print_container_end();
1875 1879 }
1876 1880 }
1877   -
1878 1881 /**
  1882 + * Class that models the behavior of wiki's delete comment confirmation page
1879 1883 *
  1884 + */
  1885 +class page_wiki_deletecomment extends page_wiki {
  1886 + private $commentid;
  1887 +
  1888 + function print_header() {
  1889 + parent::print_header();
  1890 + $this->print_pagetitle();
  1891 + }
  1892 +
  1893 + function print_content() {
  1894 + $this->printconfirmdelete();
  1895 + }
  1896 +
  1897 + function set_url() {
  1898 + global $PAGE;
  1899 + $PAGE->set_url('/mod/wiki/instancecomments.php', array('pageid' => $this->page->id, 'commentid' => $this->commentid));
  1900 + }
  1901 +
  1902 + public function set_action($action, $commentid, $content) {
  1903 + $this->action = $action;
  1904 + $this->commentid = $commentid;
  1905 + $this->content = $content;
  1906 + }
  1907 +
  1908 + protected function create_navbar() {
  1909 + global $PAGE;
  1910 +
  1911 + parent::create_navbar();
  1912 + $PAGE->navbar->add(get_string('deletecommentcheck', 'wiki'));
  1913 + }
  1914 +
  1915 + protected function setup_tabs() {
  1916 + parent::setup_tabs(array('linkedwhenactive' => 'comments', 'activetab' => 'comments'));
  1917 + }
  1918 +
  1919 + /**
  1920 + * Prints the comment deletion confirmation form
  1921 + *
  1922 + * @param page $page The page whose version will be restored
  1923 + * @param int $versionid The version to be restored
  1924 + * @param bool $confirm If false, shows a yes/no confirmation page.
  1925 + * If true, restores the old version and redirects the user to the 'view' tab.
  1926 + */
  1927 + private function printconfirmdelete() {
  1928 + global $OUTPUT;
  1929 +
  1930 + $strdeletecheck = get_string('deletecommentcheck', 'wiki');
  1931 + $strdeletecheckfull = get_string('deletecommentcheckfull', 'wiki');
  1932 +
  1933 + //ask confirmation
  1934 + $optionsyes = array('confirm'=>1, 'pageid'=>$this->page->id, 'action'=>'delete', 'commentid'=>$this->commentid, 'sesskey'=>sesskey());
  1935 + $deleteurl = new moodle_url('/mod/wiki/instancecomments.php', $optionsyes);
  1936 + $return = new moodle_url('/mod/wiki/comments.php', array('pageid'=>$this->page->id));
  1937 +
  1938 + echo $OUTPUT->heading($strdeletecheckfull);
  1939 + print_container_start(false, 'wiki_deletecommentform');
  1940 + echo '<form class="wiki_deletecomment_yes" action="' . $deleteurl . '" method="post" id="deletecomment">';
  1941 + echo '<div><input type="submit" name="confirmdeletecomment" value="' . get_string('yes') . '" /></div>';
  1942 + echo '</form>';
  1943 + echo '<form class="wiki_deletecomment_no" action="' . $return . '" method="post">';
  1944 + echo '<div><input type="submit" name="norestore" value="' . get_string('no') . '" /></div>';
  1945 + echo '</form>';
  1946 + print_container_end();
  1947 + }
  1948 +}
  1949 +
  1950 +/**
1880 1951 * Class that models the behavior of wiki's
1881 1952 * save page
1882 1953 *
6 mod/wiki/restoreversion.php
@@ -38,7 +38,7 @@
38 38
39 39 $pageid = required_param('pageid', PARAM_INT);
40 40 $versionid = required_param('versionid', PARAM_INT);
41   -$confirm = optional_param('confirm', '', PARAM_ALPHA);
  41 +$confirm = optional_param('confirm', 0, PARAM_BOOL);
42 42
43 43 if (!$page = wiki_get_page($pageid)) {
44 44 print_error('incorrectpageid', 'wiki');
@@ -63,7 +63,9 @@
63 63 add_to_log($course->id, "restore", "restore", "view.php?id=$cm->id", "$wiki->id");
64 64
65 65 if ($confirm) {
66   -
  66 + if (!confirm_sesskey()) {
  67 + print_error(get_string('invalidsesskey', 'wiki'));
  68 + }
67 69 $wikipage = new page_wiki_confirmrestore($wiki, $subwiki, $cm);
68 70 $wikipage->set_page($page);
69 71 $wikipage->set_versionid($versionid);
6 mod/wiki/styles.css
@@ -145,15 +145,15 @@
145 145 border: thin black solid;
146 146 }
147 147
148   -.wiki_restore_yes {
  148 +.wiki_restore_yes, .wiki_deletecomment_yes {
149 149 float: left;
150 150 }
151 151
152   -.wiki_restore_no {
  152 +.wiki_restore_no, .wiki_deletecomment_no {
153 153 float: right;
154 154 }
155 155
156   -.wiki_restoreform {
  156 +.wiki_restoreform, .wiki_deletecommentform {
157 157 width: 10%;
158 158 margin: auto;
159 159 }

0 comments on commit 9106716

Please sign in to comment.
Something went wrong with that request. Please try again.