Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

   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   * Manage files in wiki
  19   *
  20   * @package   mod_wiki
  21   * @copyright 2011 Dongsheng Cai <dongsheng@moodle.com>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require(__DIR__.'/../../config.php');
  26  require_once ('lib.php');
  27  require_once ('locallib.php');
  28  require_once("$CFG->dirroot/mod/wiki/filesedit_form.php");
  29  require_once("$CFG->dirroot/repository/lib.php");
  30  
  31  $subwikiid = required_param('subwiki', PARAM_INT);
  32  // not being used for file management, we use it to generate navbar link
  33  $pageid    = optional_param('pageid', 0, PARAM_INT);
  34  $returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
  35  
  36  if (!$subwiki = wiki_get_subwiki($subwikiid)) {
  37      print_error('incorrectsubwikiid', 'wiki');
  38  }
  39  
  40  // Checking wiki instance of that subwiki
  41  if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
  42      print_error('incorrectwikiid', 'wiki');
  43  }
  44  
  45  // Checking course module instance
  46  if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
  47      print_error('invalidcoursemodule');
  48  }
  49  
  50  // Checking course instance
  51  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  52  
  53  $context = context_module::instance($cm->id);
  54  
  55  require_login($course, true, $cm);
  56  
  57  if (!wiki_user_can_view($subwiki, $wiki)) {
  58      print_error('cannotviewpage', 'wiki');
  59  }
  60  require_capability('mod/wiki:managefiles', $context);
  61  
  62  if (empty($returnurl)) {
  63      $referer = get_local_referer(false);
  64      if (!empty($referer)) {
  65          $returnurl = $referer;
  66      } else {
  67          $returnurl = new moodle_url('/mod/wiki/files.php', array('subwiki' => $subwiki->id, 'pageid' => $pageid));
  68      }
  69  }
  70  
  71  $title = get_string('editfiles', 'wiki');
  72  
  73  $struser = get_string('user');
  74  $url = new moodle_url('/mod/wiki/filesedit.php', array('subwiki'=>$subwiki->id, 'pageid'=>$pageid));
  75  $PAGE->set_url($url);
  76  $PAGE->set_context($context);
  77  $PAGE->set_title($title);
  78  $PAGE->set_heading($course->fullname);
  79  $PAGE->navbar->add(format_string(get_string('wikifiles', 'wiki')), $CFG->wwwroot . '/mod/wiki/files.php?pageid=' . $pageid);
  80  $PAGE->navbar->add(format_string($title));
  81  $PAGE->set_secondary_active_tab('modulepage');
  82  $PAGE->activityheader->set_attrs([
  83      'hidecompletion' => true
  84  ]);
  85  $PAGE->add_body_class('limitedwidth');
  86  
  87  $data = new stdClass();
  88  $data->returnurl = $returnurl;
  89  $data->subwikiid = $subwiki->id;
  90  $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
  91  $types = FILE_INTERNAL | FILE_REFERENCE | FILE_CONTROLLED_LINK;
  92  $options = array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => -1, 'accepted_types' => '*', 'return_types' => $types);
  93  file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_wiki', 'attachments', $subwiki->id);
  94  
  95  $mform = new mod_wiki_filesedit_form(null, array('data'=>$data, 'options'=>$options));
  96  
  97  if ($mform->is_cancelled()) {
  98      redirect($returnurl);
  99  } else if ($formdata = $mform->get_data()) {
 100      $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_wiki', 'attachments', $subwiki->id);
 101      redirect($returnurl);
 102  }
 103  
 104  echo $OUTPUT->header();
 105  echo $OUTPUT->box_start('generalbox');
 106  $mform->display();
 107  echo $OUTPUT->box_end();
 108  echo $OUTPUT->footer();