mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
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:
parent
9d88a01ba6
commit
3b5e2acbd1
2 changed files with 11 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue