From 3b5e2acbd1eb43d1f2db017acd862f35ec8b5a92 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Mon, 3 May 2010 05:49:36 +0000 Subject: [PATCH] MDL-22112, create wiki's first page automatically without ask user questions, and add capability check to wiki_create_page function --- mod/wiki/locallib.php | 3 ++- mod/wiki/view.php | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mod/wiki/locallib.php b/mod/wiki/locallib.php index ebb53d472bc..0fa4ad268b5 100644 --- a/mod/wiki/locallib.php +++ b/mod/wiki/locallib.php @@ -323,7 +323,8 @@ function wiki_refresh_page_links($page, $links) { * @param int $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 = wiki_get_page_by_title($swid, $title)) { return $page->id; diff --git a/mod/wiki/view.php b/mod/wiki/view.php index 0960c402c72..a4a13fafc71 100644 --- a/mod/wiki/view.php +++ b/mod/wiki/view.php @@ -77,6 +77,7 @@ if ($id) { // Getting current group id $currentgroup = groups_get_activity_group($cm); + $currentgroup = !empty($currentgroup)?$currentgroup:0; // Getting current user id if ($wiki->wikimode == 'individual'){ if (empty($userid)){ @@ -93,23 +94,21 @@ if ($id) { if (!empty($page)){ $pageid = $page->id; } 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; $title = $wiki->firstpagetitle; $default = $wiki->defaultformat; - $params = array(); - $params['action'] = 'new'; - $params['title'] = $title; if (empty($subwiki)) { - $params['gid'] = $currentgroup; - $params['wid'] = $wiki->id; - $params['uid'] = $userid; + if (!$swid = wiki_add_subwiki($wiki->id, $currentgroup, $userid)) { + print_error('invalidwikiid'); + } } else { - $params['swid'] = $subwiki->id; + $swid = $subwiki->id; } - $url = new moodle_url('/mod/wiki/create.php', $params); - redirect($url->out(false)); + $id = wiki_create_page($swid, $title, $default, $USER->id); + redirect($CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $id); } /*