Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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      print_error('incorrectpageid', 'wiki');
  53  }
  54  
  55  if (!$subwiki = wiki_get_subwiki($page->subwikiid)) {
  56      print_error('incorrectsubwikiid', 'wiki');
  57  }
  58  if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
  59      print_error('invalidcoursemodule');
  60  }
  61  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  62  if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
  63      print_error('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          print_error(get_string('invalidsesskey', 'wiki'));
  71      }
  72      $comm = new page_wiki_handlecomments($wiki, $subwiki, $cm);
  73      $comm->set_page($page);
  74  } else {
  75      if(!$confirm) {
  76          $comm = new page_wiki_deletecomment($wiki, $subwiki, $cm);
  77          $comm->set_page($page);
  78          $comm->set_url();
  79      } else {
  80          $comm = new page_wiki_handlecomments($wiki, $subwiki, $cm);
  81          $comm->set_page($page);
  82          if (!confirm_sesskey()) {
  83              print_error(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          $newcomment = $form->get_data();
  94          $content = $newcomment->entrycomment_editor['text'];
  95      } else {
  96          $content = $newcontent;
  97      }
  98  
  99      if ($action == 'edit') {
 100          $comm->set_action($action, $id, $content);
 101      } else {
 102          $action = 'add';
 103          $comm->set_action($action, 0, $content);
 104      }
 105  }
 106  
 107  $comm->print_header();
 108  $comm->print_content();
 109  $comm->print_footer();