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.
/mod/wiki/ -> admin.php (source)

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   * Delete wiki pages or versions
  20   *
  21   * This will show options for deleting wiki pages or purging page versions
  22   * If user have wiki:managewiki ability then only this page will show delete
  23   * options
  24   *
  25   * @package mod_wiki
  26   * @copyright 2011 Rajesh Taneja
  27   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  
  30  require_once('../../config.php');
  31  require_once($CFG->dirroot . '/mod/wiki/lib.php');
  32  require_once($CFG->dirroot . '/mod/wiki/locallib.php');
  33  require_once($CFG->dirroot . '/mod/wiki/pagelib.php');
  34  
  35  $pageid = required_param('pageid', PARAM_INT); // Page ID
  36  $delete = optional_param('delete', 0, PARAM_INT); // ID of the page to be deleted.
  37  $option = optional_param('option', 1, PARAM_INT); // Option ID
  38  $listall = optional_param('listall', 0, PARAM_INT); // list all pages
  39  $toversion = optional_param('toversion', 0, PARAM_INT); // max version to be deleted
  40  $fromversion = optional_param('fromversion', 0, PARAM_INT); // min version to be deleted
  41  
  42  if (!$page = wiki_get_page($pageid)) {
  43      print_error('incorrectpageid', 'wiki');
  44  }
  45  if (!$subwiki = wiki_get_subwiki($page->subwikiid)) {
  46      print_error('incorrectsubwikiid', 'wiki');
  47  }
  48  if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
  49      print_error('invalidcoursemodule');
  50  }
  51  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  52  if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
  53      print_error('incorrectwikiid', 'wiki');
  54  }
  55  
  56  require_login($course, true, $cm);
  57  
  58  if (!wiki_user_can_view($subwiki, $wiki)) {
  59      print_error('cannotviewpage', 'wiki');
  60  }
  61  
  62  $context = context_module::instance($cm->id);
  63  require_capability('mod/wiki:managewiki', $context);
  64  
  65  //Delete page if a page ID to delete was supplied
  66  if (!empty($delete) && confirm_sesskey()) {
  67      if ($pageid != $delete) {
  68          // Validate that we are deleting from the same subwiki.
  69          $deletepage = wiki_get_page($delete);
  70          if (!$deletepage || $deletepage->subwikiid != $page->subwikiid) {
  71              print_error('incorrectsubwikiid', 'wiki');
  72          }
  73      }
  74      wiki_delete_pages($context, $delete, $page->subwikiid);
  75      //when current wiki page is deleted, then redirect user to create that page, as
  76      //current pageid is invalid after deletion.
  77      if ($pageid == $delete) {
  78          $params = array('swid' => $page->subwikiid, 'title' => $page->title);
  79          $url = new moodle_url('/mod/wiki/create.php', $params);
  80          redirect($url);
  81      }
  82  }
  83  
  84  //delete version if toversion and fromversion are set.
  85  if (!empty($toversion) && !empty($fromversion) && confirm_sesskey()) {
  86      //make sure all versions should not be deleted...
  87      $versioncount = wiki_count_wiki_page_versions($pageid);
  88      $versioncount -= 1; //ignore version 0
  89      $totalversionstodelete = $toversion - $fromversion;
  90      $totalversionstodelete += 1; //added 1 as toversion should be included
  91  
  92      if (($totalversionstodelete >= $versioncount) || ($versioncount <= 1)) {
  93          print_error('incorrectdeleteversions', 'wiki');
  94      } else {
  95          $versions = array();
  96          for ($i = $fromversion; $i <= $toversion; $i++) {
  97              //Add all version to deletion list which exist
  98              if (wiki_get_wiki_page_version($pageid, $i)) {
  99                  array_push($versions, $i);
 100              }
 101          }
 102          $purgeversions[$pageid] = $versions;
 103          wiki_delete_page_versions($purgeversions, $context);
 104      }
 105  }
 106  
 107  //show actual page
 108  $wikipage = new page_wiki_admin($wiki, $subwiki, $cm);
 109  
 110  $wikipage->set_page($page);
 111  $wikipage->print_header();
 112  $wikipage->set_view($option, empty($listall)?true:false);
 113  $wikipage->print_content();
 114  
 115  $wikipage->print_footer();