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(dirname(__FILE__
) . '/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 // The title of the new page, can be empty
31 $title = optional_param('title', get_string('newpage', 'wiki'), PARAM_TEXT
);
32 $wid = optional_param('wid', 0, PARAM_INT
);
33 $swid = optional_param('swid', 0, PARAM_INT
);
34 $group = optional_param('group', 0, PARAM_INT
);
35 $uid = optional_param('uid', 0, PARAM_INT
);
37 // 'create' action must be submitted by moodle form
38 // so sesskey must be checked
39 if ($action == 'create') {
40 if (!confirm_sesskey()) {
41 print_error('invalidsesskey');
46 $subwiki = wiki_get_subwiki($swid);
48 if (!$wiki = wiki_get_wiki($subwiki->wikiid
)) {
49 print_error('invalidwikiid', 'wiki');
53 $subwiki = wiki_get_subwiki_by_group($wid, $group, $uid);
55 if (!$wiki = wiki_get_wiki($wid)) {
56 print_error('invalidwikiid', 'wiki');
61 if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id
)) {
62 print_error('invalidcoursemoduleid', 'wiki');
65 $groups = new stdClass();
66 if (groups_get_activity_groupmode($cm)) {
67 $modulecontext = context_module
::instance($cm->id
);
68 $canaccessgroups = has_capability('moodle/site:accessallgroups', $modulecontext);
69 if ($canaccessgroups) {
70 $groups->availablegroups
= groups_get_all_groups($cm->course
);
71 $allpart = new stdClass();
73 $allpart->name
= get_string('allparticipants');
74 array_unshift($groups->availablegroups
, $allpart);
76 $groups->availablegroups
= groups_get_all_groups($cm->course
, $USER->id
);
79 $groups->currentgroup
= $group;
81 $groups->currentgroup
= groups_get_activity_group($cm);
85 $course = $DB->get_record('course', array('id' => $cm->course
), '*', MUST_EXIST
);
87 require_login($course, true, $cm);
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();