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/>.
19 * This file contains all necessary code to define and process an edit form
22 * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once($CFG->libdir
.'/formslib.php');
29 class mod_wiki_create_form
extends moodleform
{
31 protected function definition() {
32 $mform = $this->_form
;
34 $formats = $this->_customdata
['formats'];
35 $defaultformat = $this->_customdata
['defaultformat'];
36 $forceformat = $this->_customdata
['forceformat'];
38 $mform->addElement('header', 'general', get_string('newpagehdr', 'wiki'));
40 $textoptions = array();
41 if (!empty($this->_customdata
['disable_pagetitle'])) {
42 $textoptions = array('readonly'=>'readonly');
44 $mform->addElement('text', 'pagetitle', get_string('newpagetitle', 'wiki'), $textoptions);
45 $mform->setType('pagetitle', PARAM_TEXT
);
46 $mform->addRule('pagetitle', get_string('required'), 'required', null, 'client');
49 $mform->addElement('hidden', 'pageformat', $defaultformat);
51 $mform->addElement('static', 'format', get_string('format', 'wiki'));
52 $mform->addHelpButton('format', 'format', 'wiki');
53 foreach ($formats as $format) {
54 if ($format == $defaultformat) {
55 $attr = array('checked'=>'checked');
56 }else if (!empty($forceformat)){
57 $attr = array('disabled'=>'disabled');
61 $mform->addElement('radio', 'pageformat', '', get_string('format'.$format, 'wiki'), $format, $attr);
64 $mform->setType('pageformat', PARAM_ALPHANUMEXT
);
65 $mform->addRule('pageformat', get_string('required'), 'required', null, 'client');
67 if (!empty($this->_customdata
['groups']->availablegroups
)) {
68 foreach ($this->_customdata
['groups']->availablegroups
as $groupdata) {
69 $groupinfo[$groupdata->id
] = $groupdata->name
;
71 if (count($groupinfo) > 1) {
72 $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
73 $mform->setDefault('groupinfo', $this->_customdata
['groups']->currentgroup
);
74 $mform->setType('groupinfo', PARAM_INT
);
76 $groupid = key($groupinfo);
77 $groupname = $groupinfo[$groupid];
78 $mform->addElement('static', 'groupdesciption', get_string('group'), $groupname);
79 $mform->addElement('hidden', 'groupinfo', $groupid);
80 $mform->setType('groupinfo', PARAM_INT
);
85 $mform->addElement('hidden', 'action', 'create');
86 $mform->setType('action', PARAM_ALPHA
);
88 $this->add_action_buttons(false, get_string('createpage', 'wiki'));