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

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

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Wiki files management
  19   *
  20   * @package mod_wiki
  21   * @copyright 2011 Dongsheng Cai <dongsheng@moodle.com>
  22   *
  23   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once('../../config.php');
  27  require_once($CFG->dirroot . '/mod/wiki/lib.php');
  28  require_once($CFG->dirroot . '/mod/wiki/locallib.php');
  29  
  30  $pageid       = required_param('pageid', PARAM_INT); // Page ID
  31  $wid          = optional_param('wid', 0, PARAM_INT); // Wiki ID
  32  $currentgroup = optional_param('group', 0, PARAM_INT); // Group ID
  33  $userid       = optional_param('uid', 0, PARAM_INT); // User ID
  34  $groupanduser = optional_param('groupanduser', null, PARAM_TEXT);
  35  
  36  if (!$page = wiki_get_page($pageid)) {
  37      throw new \moodle_exception('incorrectpageid', 'wiki');
  38  }
  39  
  40  if ($groupanduser) {
  41      list($currentgroup, $userid) = explode('-', $groupanduser);
  42      $currentgroup = clean_param($currentgroup, PARAM_INT);
  43      $userid       = clean_param($userid, PARAM_INT);
  44  }
  45  
  46  if ($wid) {
  47      // in group mode
  48      if (!$wiki = wiki_get_wiki($wid)) {
  49          throw new \moodle_exception('incorrectwikiid', 'wiki');
  50      }
  51      if (!$subwiki = wiki_get_subwiki_by_group($wiki->id, $currentgroup, $userid)) {
  52          // create subwiki if doesn't exist
  53          $subwikiid = wiki_add_subwiki($wiki->id, $currentgroup, $userid);
  54          $subwiki = wiki_get_subwiki($subwikiid);
  55      }
  56  } else {
  57      // no group
  58      if (!$subwiki = wiki_get_subwiki($page->subwikiid)) {
  59          throw new \moodle_exception('incorrectsubwikiid', 'wiki');
  60      }
  61  
  62      // Checking wiki instance of that subwiki
  63      if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
  64          throw new \moodle_exception('incorrectwikiid', 'wiki');
  65      }
  66  }
  67  
  68  // Checking course module instance
  69  if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
  70      throw new \moodle_exception('invalidcoursemodule');
  71  }
  72  
  73  // Checking course instance
  74  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  75  
  76  $context = context_module::instance($cm->id);
  77  
  78  $url = new moodle_url('/mod/wiki/files.php', ['pageid' => $pageid]);
  79  $PAGE->set_url($url);
  80  require_course_login($course, true, $cm);
  81  
  82  if (!wiki_user_can_view($subwiki, $wiki)) {
  83      throw new \moodle_exception('cannotviewfiles', 'wiki');
  84  }
  85  
  86  $PAGE->set_title(get_string('wikifiles', 'wiki'));
  87  $PAGE->set_heading($course->fullname);
  88  $PAGE->add_body_class('limitedwidth');
  89  $PAGE->navbar->add(format_string(get_string('wikifiles', 'wiki')));
  90  $PAGE->set_secondary_active_tab('modulepage');
  91  
  92  echo $OUTPUT->header();
  93  
  94  $renderer = $PAGE->get_renderer('mod_wiki');
  95  
  96  $actionbar = new \mod_wiki\output\action_bar($pageid, $PAGE->url);
  97  echo $renderer->render_action_bar($actionbar);
  98  
  99  echo $OUTPUT->box_start('generalbox');
 100  echo $renderer->wiki_print_subwiki_selector($PAGE->activityrecord, $subwiki, $page, 'files');
 101  echo $renderer->wiki_files_tree($context, $subwiki);
 102  echo $OUTPUT->box_end();
 103  
 104  if (has_capability('mod/wiki:managefiles', $context)) {
 105      echo $OUTPUT->single_button(new moodle_url('/mod/wiki/filesedit.php', array('subwiki'=>$subwiki->id, 'pageid'=>$pageid)), get_string('editfiles', 'wiki'), 'get');
 106  }
 107  echo $OUTPUT->footer();