Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * @TODO: Doc this file
  20   *
  21   * @package mod_wiki
  22   * @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
  23   * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
  24   *
  25   * @author Jordi Piguillem
  26   * @author Marc Alier
  27   * @author David Jimenez
  28   * @author Josep Arus
  29   * @author Daniel Serrano
  30   * @author Kenneth Riba
  31   *
  32   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  
  35  require_once('../../config.php');
  36  require_once($CFG->dirroot . "/mod/wiki/pagelib.php");
  37  require_once($CFG->dirroot . "/mod/wiki/locallib.php");
  38  require_once($CFG->dirroot . '/mod/wiki/comments_form.php');
  39  
  40  $pageid = required_param('pageid', PARAM_TEXT);
  41  $action = optional_param('action', '', PARAM_ALPHANUMEXT);
  42  $id = optional_param('id', 0, PARAM_INT);
  43  $commentid = optional_param('commentid', 0, PARAM_INT);
  44  $newcontent = optional_param_array('newcontent', '', PARAM_CLEANHTML);
  45  $confirm = optional_param('confirm', 0, PARAM_BOOL);
  46  
  47  if ($newcontent) {
  48      $newcontent = $newcontent['text'];
  49  }
  50  
  51  if (!$page = wiki_get_page($pageid)) {
  52      throw new \moodle_exception('incorrectpageid', 'wiki');
  53  }
  54  
  55  if (!$subwiki = wiki_get_subwiki($page->subwikiid)) {
  56      throw new \moodle_exception('incorrectsubwikiid', 'wiki');
  57  }
  58  if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
  59      throw new \moodle_exception('invalidcoursemodule');
  60  }
  61  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  62  if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
  63      throw new \moodle_exception('incorrectwikiid', 'wiki');
  64  }
  65  require_login($course, true, $cm);
  66  
  67  if ($action == 'add' || $action == 'edit') {
  68      //just check sesskey
  69      if (!confirm_sesskey()) {
  70          throw new \moodle_exception(get_string('invalidsesskey', 'wiki'));
  71      }
  72      $comm = new page_wiki_handlecomments($wiki, $subwiki, $cm, 'modulepage');
  73      $comm->set_page($page);
  74  } else {
  75      if(!$confirm) {
  76          $comm = new page_wiki_deletecomment($wiki, $subwiki, $cm, 'modulepage');
  77          $comm->set_page($page);
  78          $comm->set_url();
  79      } else {
  80          $comm = new page_wiki_handlecomments($wiki, $subwiki, $cm, 'modulepage');
  81          $comm->set_page($page);
  82          if (!confirm_sesskey()) {
  83              throw new \moodle_exception(get_string('invalidsesskey', 'wiki'));
  84          }
  85      }
  86  }
  87  
  88  if ($action == 'delete') {
  89      $comm->set_action($action, $commentid, 0);
  90  } else {
  91      if (empty($newcontent)) {
  92          $form = new mod_wiki_comments_form();
  93          if ($form->is_cancelled()) {
  94              redirect(new moodle_url('/mod/wiki/comments.php', ['pageid' => (int)$pageid]));
  95          }
  96          $newcomment = $form->get_data();
  97          $content = $newcomment->entrycomment_editor['text'];
  98      } else {
  99          $content = $newcontent;
 100      }
 101  
 102      if ($action == 'edit') {
 103          $comm->set_action($action, $id, $content);
 104      } else {
 105          $action = 'add';
 106          $comm->set_action($action, 0, $content);
 107      }
 108  }
 109  
 110  $comm->print_header();
 111  $comm->print_content();
 112  $comm->print_footer();