MDL-51088 completion: Do not require hover to confirm xpath
[moodle.git] / mod / wiki / create.php
blobcbd4a1cddec43dd77e4f2fbf8bd36ff30e2d87a1
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
9 //
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
26 // selections
27 // 'create' action will create a new page in db, and redirect to
28 // page editing page.
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');
45 if (!empty($swid)) {
46 $subwiki = wiki_get_subwiki($swid);
48 if (!$wiki = wiki_get_wiki($subwiki->wikiid)) {
49 print_error('invalidwikiid', 'wiki');
52 } else {
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();
72 $allpart->id = '0';
73 $allpart->name = get_string('allparticipants');
74 array_unshift($groups->availablegroups, $allpart);
75 } else {
76 $groups->availablegroups = groups_get_all_groups($cm->course, $USER->id);
78 if (!empty($group)) {
79 $groups->currentgroup = $group;
80 } else {
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);
91 if (!empty($swid)) {
92 $wikipage->set_gid($subwiki->groupid);
93 $wikipage->set_uid($subwiki->userid);
94 $wikipage->set_swid($swid);
95 } else {
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);
107 switch ($action) {
108 case 'create':
109 $newpageid = $wikipage->create_page($title);
110 redirect($CFG->wwwroot . '/mod/wiki/edit.php?pageid='.$newpageid);
111 break;
112 case 'new':
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);
117 } else {
118 $wikipage->print_header();
119 // Create a new page.
120 $wikipage->print_content($title);
122 $wikipage->print_footer();
123 break;