MDL-22112, create wiki's first page automatically without ask user questions, and add capability check to wiki_create_page function

This commit is contained in:
Dongsheng Cai 2010-05-03 05:49:36 +00:00
parent 9d88a01ba6
commit 3b5e2acbd1
2 changed files with 11 additions and 11 deletions

View file

@ -323,7 +323,8 @@ function wiki_refresh_page_links($page, $links) {
* @param int $userid * @param int $userid
*/ */
function wiki_create_page($swid, $title, $format, $userid) { function wiki_create_page($swid, $title, $format, $userid) {
global $DB; global $DB, $PAGE;
require_capability('mod/wiki:editpage', $PAGE->context);
// if page exists // if page exists
if ($page = wiki_get_page_by_title($swid, $title)) { if ($page = wiki_get_page_by_title($swid, $title)) {
return $page->id; return $page->id;

View file

@ -77,6 +77,7 @@ if ($id) {
// Getting current group id // Getting current group id
$currentgroup = groups_get_activity_group($cm); $currentgroup = groups_get_activity_group($cm);
$currentgroup = !empty($currentgroup)?$currentgroup:0;
// Getting current user id // Getting current user id
if ($wiki->wikimode == 'individual'){ if ($wiki->wikimode == 'individual'){
if (empty($userid)){ if (empty($userid)){
@ -93,23 +94,21 @@ if ($id) {
if (!empty($page)){ if (!empty($page)){
$pageid = $page->id; $pageid = $page->id;
} else { } else {
// the first page doesn't exist, so redirect to create page // the first page doesn't exist, create first page automatically
// Then redirct to editing page
$page = null; $page = null;
$title = $wiki->firstpagetitle; $title = $wiki->firstpagetitle;
$default = $wiki->defaultformat; $default = $wiki->defaultformat;
$params = array();
$params['action'] = 'new';
$params['title'] = $title;
if (empty($subwiki)) { if (empty($subwiki)) {
$params['gid'] = $currentgroup; if (!$swid = wiki_add_subwiki($wiki->id, $currentgroup, $userid)) {
$params['wid'] = $wiki->id; print_error('invalidwikiid');
$params['uid'] = $userid; }
} else { } else {
$params['swid'] = $subwiki->id; $swid = $subwiki->id;
} }
$url = new moodle_url('/mod/wiki/create.php', $params); $id = wiki_create_page($swid, $title, $default, $USER->id);
redirect($url->out(false)); redirect($CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $id);
} }
/* /*