From f2ce3d0239663ed3a96dc68b91b01399131ff0ab Mon Sep 17 00:00:00 2001 From: Jonathon Fowler Date: Thu, 2 Aug 2012 16:39:21 +1000 Subject: [PATCH] MDL-34695 wiki: ensure the correct individual subwiki is used/created for a user --- mod/wiki/files.php | 5 +++++ mod/wiki/pagelib.php | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mod/wiki/files.php b/mod/wiki/files.php index 377ed741afb..fe92ac5fb5d 100644 --- a/mod/wiki/files.php +++ b/mod/wiki/files.php @@ -49,6 +49,11 @@ if ($wid) { print_error('incorrectwikiid', 'wiki'); } if (!$subwiki = wiki_get_subwiki_by_group($wiki->id, $currentgroup, $userid)) { + // trap anomalous parameters that would lead to a shared subwiki being created for an individual user + if ($wiki->wikimode == 'individual' && $userid == 0) { + throw new coding_exception('Tried creating a shared subwiki in \'individual\' mode. This shouldn\'t happen.'); + } + // create subwiki if doesn't exist $subwikiid = wiki_add_subwiki($wiki->id, $currentgroup, $userid); $subwiki = wiki_get_subwiki($subwikiid); diff --git a/mod/wiki/pagelib.php b/mod/wiki/pagelib.php index 54e710f59a7..703946d64df 100644 --- a/mod/wiki/pagelib.php +++ b/mod/wiki/pagelib.php @@ -947,8 +947,13 @@ class page_wiki_create extends page_wiki { $groupid = '0'; } if (empty($this->subwiki)) { + // trap anomalous parameters that would lead to a shared subwiki being created for an individual user + if ($PAGE->activityrecord->wikimode == 'individual' && $this->uid == 0) { + throw new coding_exception('Tried creating a shared subwiki in \'individual\' mode. This shouldn\'t happen.'); + } + // If subwiki is not set then try find one and set else create one. - if (!$this->subwiki = wiki_get_subwiki_by_group($this->wid, $groupid)) { + if (!$this->subwiki = wiki_get_subwiki_by_group($this->wid, $groupid, $this->uid)) { $swid = wiki_add_subwiki($PAGE->activityrecord->id, $groupid, $this->uid); $this->subwiki = wiki_get_subwiki($swid); }