Merge branch 'wip-MDL-31948-master' of git://github.com/phalacee/moodle
[moodle.git] / mod / wiki / files.php
blob377ed741afb090d76d14167fbaf2c7b9214de078
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.
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/>.
17 /**
18 * Wiki files management
20 * @package mod-wiki-2.0
21 * @copyrigth 2011 Dongsheng Cai <dongsheng@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../../config.php');
27 require_once($CFG->dirroot . '/mod/wiki/lib.php');
28 require_once($CFG->dirroot . '/mod/wiki/locallib.php');
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);
36 if (!$page = wiki_get_page($pageid)) {
37 print_error('incorrectpageid', 'wiki');
40 if ($groupanduser) {
41 list($currentgroup, $userid) = explode('-', $groupanduser);
42 $currentgroup = clean_param($currentgroup, PARAM_INT);
43 $userid = clean_param($userid, PARAM_INT);
46 if ($wid) {
47 // in group mode
48 if (!$wiki = wiki_get_wiki($wid)) {
49 print_error('incorrectwikiid', 'wiki');
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);
56 } else {
57 // no group
58 if (!$subwiki = wiki_get_subwiki($page->subwikiid)) {
59 print_error('incorrectsubwikiid', 'wiki');
62 // Checking wiki instance of that subwiki
63 if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
64 print_error('incorrectwikiid', 'wiki');
68 // Checking course module instance
69 if (!$cm = get_coursemodule_from_instance("wiki", $subwiki->wikiid)) {
70 print_error('invalidcoursemodule');
73 // Checking course instance
74 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
76 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
79 $PAGE->set_url('/mod/wiki/files.php', array('pageid'=>$pageid));
80 require_login($course, true, $cm);
81 $PAGE->set_context($context);
82 $PAGE->set_title(get_string('wikifiles', 'wiki'));
83 $PAGE->set_heading(get_string('wikifiles', 'wiki'));
84 $PAGE->navbar->add(format_string(get_string('wikifiles', 'wiki')));
85 echo $OUTPUT->header();
87 $renderer = $PAGE->get_renderer('mod_wiki');
89 $tabitems = array('view' => 'view', 'edit' => 'edit', 'comments' => 'comments', 'history' => 'history', 'map' => 'map', 'files' => 'files');
91 $options = array('activetab'=>'files');
92 echo $renderer->tabs($page, $tabitems, $options);
95 echo $OUTPUT->box_start('generalbox');
96 if (has_capability('mod/wiki:viewpage', $context)) {
97 echo $renderer->wiki_print_subwiki_selector($PAGE->activityrecord, $subwiki, $page, 'files');
98 echo $renderer->wiki_files_tree($context, $subwiki);
99 } else {
100 echo $OUTPUT->notification(get_string('cannotviewfiles', 'wiki'));
102 echo $OUTPUT->box_end();
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');
107 echo $OUTPUT->footer();