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  // 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  
  82  $data = new stdClass();
  83  $data->returnurl = $returnurl;
  84  $data->subwikiid = $subwiki->id;
  85  $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
  86  $types = FILE_INTERNAL | FILE_REFERENCE | FILE_CONTROLLED_LINK;
  87  $options = array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => -1, 'accepted_types' => '*', 'return_types' => $types);
  88  file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_wiki', 'attachments', $subwiki->id);
  89  
  90  $mform = new mod_wiki_filesedit_form(null, array('data'=>$data, 'options'=>$options));
  91  
  92  if ($mform->is_cancelled()) {
  93      redirect($returnurl);
  94  } else if ($formdata = $mform->get_data()) {
  95      $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_wiki', 'attachments', $subwiki->id);
  96      redirect($returnurl);
  97  }
  98  
  99  echo $OUTPUT->header();
 100  echo $OUTPUT->heading(format_string($wiki->name));
 101  echo $OUTPUT->box(format_module_intro('wiki', $wiki, $PAGE->cm->id), 'generalbox', 'intro');
 102  echo $OUTPUT->box_start('generalbox');
 103  $mform->display();
 104  echo $OUTPUT->box_end();
 105  echo $OUTPUT->footer();