|
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 00018 require_once('../../config.php'); 00019 require_once(dirname(__FILE__) . '/create_form.php'); 00020 require_once($CFG->dirroot . '/mod/wiki/lib.php'); 00021 require_once($CFG->dirroot . '/mod/wiki/locallib.php'); 00022 require_once($CFG->dirroot . '/mod/wiki/pagelib.php'); 00023 00024 // this page accepts two actions: new and create 00025 // 'new' action will display a form contains page title and page format 00026 // selections 00027 // 'create' action will create a new page in db, and redirect to 00028 // page editing page. 00029 $action = optional_param('action', 'new', PARAM_TEXT); 00030 // The title of the new page, can be empty 00031 $title = optional_param('title', '', PARAM_TEXT); 00032 $wid = optional_param('wid', 0, PARAM_INT); 00033 $swid = optional_param('swid', 0, PARAM_INT); 00034 $gid = optional_param('gid', 0, PARAM_INT); 00035 $uid = optional_param('uid', 0, PARAM_INT); 00036 00037 // 'create' action must be submitted by moodle form 00038 // so sesskey must be checked 00039 if ($action == 'create') { 00040 if (!confirm_sesskey()) { 00041 print_error('invalidsesskey'); 00042 } 00043 } 00044 00045 if (!empty($swid)) { 00046 $subwiki = wiki_get_subwiki($swid); 00047 00048 if (!$wiki = wiki_get_wiki($subwiki->wikiid)) { 00049 print_error('invalidwikiid', 'wiki'); 00050 } 00051 00052 } else { 00053 $subwiki = wiki_get_subwiki_by_group($wid, $gid, $uid); 00054 00055 if (!$wiki = wiki_get_wiki($wid)) { 00056 print_error('invalidwikiid', 'wiki'); 00057 } 00058 00059 } 00060 00061 if (!$cm = get_coursemodule_from_instance('wiki', $wiki->id)) { 00062 print_error('invalidcoursemoduleid', 'wiki'); 00063 } 00064 00065 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); 00066 00067 require_login($course->id, true, $cm); 00068 00069 add_to_log($course->id, 'createpage', 'createpage', 'view.php?id=' . $cm->id, $wiki->id); 00070 00071 $wikipage = new page_wiki_create($wiki, $subwiki, $cm); 00072 00073 if (!empty($swid)) { 00074 $wikipage->set_gid($subwiki->groupid); 00075 $wikipage->set_uid($subwiki->userid); 00076 $wikipage->set_swid($swid); 00077 } else { 00078 $wikipage->set_wid($wid); 00079 $wikipage->set_gid($gid); 00080 $wikipage->set_uid($uid); 00081 } 00082 00083 if (!empty($title)) { 00084 $wikipage->set_title($title); 00085 } else { 00086 $wikipage->set_title(get_string('newpage', 'wiki')); 00087 } 00088 00089 // set page action, and initialise moodle form 00090 $wikipage->set_action($action); 00091 00092 switch ($action) { 00093 case 'create': 00094 $wikipage->create_page($title); 00095 break; 00096 case 'new': 00097 if ((int)$wiki->forceformat == 1 && !empty($title)) { 00098 $wikipage->create_page($title); 00099 } else { 00100 // create link from moodle navigation block without pagetitle 00101 $wikipage->print_header(); 00102 // new page without page title 00103 $wikipage->print_content($title); 00104 } 00105 $wikipage->print_footer(); 00106 break; 00107 }