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 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
23 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 if (!defined('MOODLE_INTERNAL')) {
31 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
34 require_once($CFG->dirroot
. '/mod/wiki/editors/wikieditor.php');
36 class mod_wiki_edit_form
extends moodleform
{
38 protected function definition() {
41 $mform = $this->_form
;
42 // BEWARE HACK: In order for things to work we need to override the form id and set it to mform1.
43 // The first form to be instantiated never gets displayed so this should be safe.
44 $mform->updateAttributes(array('id' => 'mform1'));
46 $version = $this->_customdata
['version'];
47 $format = $this->_customdata
['format'];
49 if (empty($this->_customdata
['contextid'])) {
51 // This is being done ONLY to aid those who may have created there own wiki pages. It should be removed sometime
52 // after the release of 2.3 (not creating an issue because this whole thing should be reviewed)
53 debugging('You must always provide mod_wiki_edit_form with a contextid in its custom data', DEBUG_DEVELOPER
);
55 $contextid = $PAGE->context
->id
;
57 $contextid = $this->_customdata
['contextid'];
60 if (isset($this->_customdata
['pagetitle'])) {
61 // Page title must be formatted properly here as this is output and not an element.
62 $pagetitle = get_string('editingpage', 'wiki', format_string($this->_customdata
['pagetitle'], true, array('context' => context
::instance_by_id($contextid, MUST_EXIST
))));
64 $pagetitle = get_string('editing', 'wiki');
68 $mform->addElement('header', 'general', $pagetitle);
70 $fieldname = get_string('format' . $format, 'wiki');
71 if ($format != 'html') {
73 $extensions = file_get_typegroup('extension', 'web_image');
74 $fs = get_file_storage();
75 $tree = $fs->get_area_tree($contextid, 'mod_wiki', $this->_customdata
['filearea'], $this->_customdata
['fileitemid']);
77 foreach ($tree['files'] as $file) {
78 $filename = $file->get_filename();
79 foreach ($extensions as $ext) {
80 if (preg_match('#'.$ext.'$#i', $filename)) {
85 $mform->addElement('wikieditor', 'newcontent', $fieldname, array('cols' => 100, 'rows' => 20, 'wiki_format' => $format, 'files'=>$files));
86 $mform->addHelpButton('newcontent', 'format'.$format, 'wiki');
87 $mform->setType('newcontent', PARAM_RAW
); // processed by trust text or cleaned before the display
89 $mform->addElement('editor', 'newcontent_editor', $fieldname, null, page_wiki_edit
::$attachmentoptions);
90 $mform->addHelpButton('newcontent_editor', 'formathtml', 'wiki');
91 $mform->setType('newcontent_editor', PARAM_RAW
); // processed by trust text or cleaned before the display
96 $mform->addElement('hidden', 'version', $version);
97 $mform->setType('version', PARAM_FLOAT
);
100 $mform->addElement('hidden', 'contentformat', $format);
101 $mform->setType('contentformat', PARAM_ALPHANUMEXT
);
103 if (!empty($CFG->usetags
)) {
104 $mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
105 $mform->addElement('tags', 'tags', get_string('tags'));
106 $mform->setType('tags', PARAM_TEXT
);
109 $buttongroup = array();
110 $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('save', 'wiki'), array('id' => 'save'));
111 $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('preview'), array('id' => 'preview'));
112 $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('cancel'), array('id' => 'cancel'));
114 $mform->addGroup($buttongroup, 'buttonar', '', array(' '), false);
115 $mform->closeHeaderBefore('buttonar');