|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00034 require_once('../../config.php'); 00035 00036 require_once($CFG->dirroot . '/mod/wiki/lib.php'); 00037 require_once($CFG->dirroot . '/mod/wiki/locallib.php'); 00038 require_once($CFG->dirroot . '/mod/wiki/pagelib.php'); 00039 00040 $pageid = required_param('pageid', PARAM_INT); 00041 $contentformat = optional_param('contentformat', '', PARAM_ALPHA); 00042 $option = optional_param('editoption', '', PARAM_TEXT); 00043 $section = optional_param('section', "", PARAM_TEXT); 00044 $version = optional_param('version', -1, PARAM_INT); 00045 $attachments = optional_param('attachments', 0, PARAM_INT); 00046 $deleteuploads = optional_param('deleteuploads', 0, PARAM_RAW); 00047 00048 $newcontent = ''; 00049 if (!empty($newcontent) && is_array($newcontent)) { 00050 $newcontent = $newcontent['text']; 00051 } 00052 00053 if (!$page = wiki_get_page($pageid)) { 00054 print_error('incorrectpageid', 'wiki'); 00055 } 00056 00057 if (!$subwiki = wiki_get_subwiki($page->subwikiid)) { 00058 print_error('incorrectsubwikiid', 'wiki'); 00059 } 00060 00061 if (!$wiki = wiki_get_wiki($subwiki->wikiid)) { 00062 print_error('incorrectwikiid', 'wiki'); 00063 } 00064 00065 if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id)) { 00066 print_error('invalidcoursemodule'); 00067 } 00068 00069 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); 00070 00071 if (!empty($section) && !$sectioncontent = wiki_get_section_page($page, $section)) { 00072 print_error('invalidsection', 'wiki'); 00073 } 00074 00075 require_login($course, true, $cm); 00076 00077 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00078 require_capability('mod/wiki:editpage', $context); 00079 00080 add_to_log($course->id, 'wiki', 'edit', "edit.php?id=$cm->id", "$wiki->id"); 00081 00082 if ($option == get_string('save', 'wiki')) { 00083 if (!confirm_sesskey()) { 00084 print_error(get_string('invalidsesskey', 'wiki')); 00085 } 00086 $wikipage = new page_wiki_save($wiki, $subwiki, $cm); 00087 $wikipage->set_page($page); 00088 $wikipage->set_newcontent($newcontent); 00089 $wikipage->set_upload(true); 00090 } else { 00091 if ($option == get_string('preview')) { 00092 if (!confirm_sesskey()) { 00093 print_error(get_string('invalidsesskey', 'wiki')); 00094 } 00095 $wikipage = new page_wiki_preview($wiki, $subwiki, $cm); 00096 $wikipage->set_page($page); 00097 } else { 00098 if ($option == get_string('cancel')) { 00099 //delete lock 00100 wiki_delete_locks($page->id, $USER->id, $section); 00101 00102 redirect($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $pageid); 00103 } else { 00104 $wikipage = new page_wiki_edit($wiki, $subwiki, $cm); 00105 $wikipage->set_page($page); 00106 $wikipage->set_upload($option == get_string('upload', 'wiki')); 00107 } 00108 } 00109 00110 if (has_capability('mod/wiki:overridelock', $context)) { 00111 $wikipage->set_overridelock(true); 00112 } 00113 } 00114 00115 if ($version >= 0) { 00116 $wikipage->set_versionnumber($version); 00117 } 00118 00119 if (!empty($section)) { 00120 $wikipage->set_section($sectioncontent, $section); 00121 } 00122 00123 if (!empty($attachments)) { 00124 $wikipage->set_attachments($attachments); 00125 } 00126 00127 if (!empty($deleteuploads)) { 00128 $wikipage->set_deleteuploads($deleteuploads); 00129 } 00130 00131 if (!empty($contentformat)) { 00132 $wikipage->set_format($contentformat); 00133 } 00134 00135 $wikipage->print_header(); 00136 00137 $wikipage->print_content(); 00138 00139 $wikipage->print_footer();