3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 require_once('../../config.php');
19 require_once(__DIR__
. '/create_form.php');
20 require_once($CFG->dirroot
. '/mod/wiki/lib.php');
21 require_once($CFG->dirroot
. '/mod/wiki/locallib.php');
22 require_once($CFG->dirroot
. '/mod/wiki/pagelib.php');
24 // this page accepts two actions: new and create
25 // 'new' action will display a form contains page title and page format
27 // 'create' action will create a new page in db, and redirect to
29 $action = optional_param('action', 'new', PARAM_TEXT
);
30 $wid = optional_param('wid', 0, PARAM_INT
);
31 $swid = optional_param('swid', 0, PARAM_INT
);
32 $group = optional_param('group', 0, PARAM_INT
);
33 $uid = optional_param('uid', 0, PARAM_INT
);
35 // 'create' action must be submitted by moodle form
36 // so sesskey must be checked
37 if ($action == 'create') {
38 if (!confirm_sesskey()) {
39 throw new \
moodle_exception('invalidsesskey');
44 $subwiki = wiki_get_subwiki($swid);
46 if (!$wiki = wiki_get_wiki($subwiki->wikiid
)) {
47 throw new \
moodle_exception('incorrectwikiid', 'wiki');
51 $subwiki = wiki_get_subwiki_by_group($wid, $group, $uid);
53 if (!$wiki = wiki_get_wiki($wid)) {
54 throw new \
moodle_exception('incorrectwikiid', 'wiki');
59 if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id
)) {
60 throw new \
moodle_exception('invalidcoursemodule');
63 $groups = new stdClass();
64 if (groups_get_activity_groupmode($cm)) {
65 $modulecontext = context_module
::instance($cm->id
);
66 $canaccessgroups = has_capability('moodle/site:accessallgroups', $modulecontext);
67 if ($canaccessgroups) {
68 $groups->availablegroups
= groups_get_all_groups($cm->course
);
69 $allpart = new stdClass();
71 $allpart->name
= get_string('allparticipants');
72 array_unshift($groups->availablegroups
, $allpart);
74 $groups->availablegroups
= groups_get_all_groups($cm->course
, $USER->id
);
77 $groups->currentgroup
= $group;
79 $groups->currentgroup
= groups_get_activity_group($cm);
83 $course = $DB->get_record('course', array('id' => $cm->course
), '*', MUST_EXIST
);
85 require_login($course, true, $cm);
87 // The title of the new page, cannot be empty.
88 $title = optional_param('title', get_string('newpage', 'wiki'), PARAM_TEXT
);
89 $wikipage = new page_wiki_create($wiki, $subwiki, $cm);
92 $wikipage->set_gid($subwiki->groupid
);
93 $wikipage->set_uid($subwiki->userid
);
94 $wikipage->set_swid($swid);
96 $wikipage->set_wid($wid);
97 $wikipage->set_gid($group);
98 $wikipage->set_uid($uid);
101 $wikipage->set_availablegroups($groups);
102 $wikipage->set_title($title);
104 // set page action, and initialise moodle form
105 $wikipage->set_action($action);
109 $newpageid = $wikipage->create_page($title);
110 redirect($CFG->wwwroot
. '/mod/wiki/edit.php?pageid='.$newpageid);
113 // Go straight to editing if we know the page title and we're in force format mode.
114 if ((int)$wiki->forceformat
== 1 && $title != get_string('newpage', 'wiki')) {
115 $newpageid = $wikipage->create_page($title);
116 redirect($CFG->wwwroot
. '/mod/wiki/edit.php?pageid='.$newpageid);
118 $wikipage->print_header();
119 // Create a new page.
120 $wikipage->print_content($title);
122 $wikipage->print_footer();