From eab43a4b2f5b276eb5287edf91ca8f5612c9c8f6 Mon Sep 17 00:00:00 2001
Date: Tue, 25 May 2010 12:57:50 -0500
Subject: [PATCH] RT# 66011. Wiki page selects the correct wiki to display on page.

---
 mod/wiki/lib.php |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php
index 011b507..6096563 100644
--- a/mod/wiki/lib.php
+++ b/mod/wiki/lib.php
@@ -397,11 +397,13 @@ function wiki_get_default_entry(&$wiki, &$course, $userid=0, $groupid=0) {
     global $USER;
     /// If there is a groupmode, get the user's group id.
     $groupmode = groups_get_activity_groupmode($wiki);
-    // if groups mode is in use and no group supplied, use the first one found
     if ($groupmode && !$groupid) {
-        if(($mygroupids=mygroupid($course->id)) && count($mygroupids)>0) {
-            // Use first group. They ought to be able to change later
-            $groupid=$mygroupids[0];
+        // Get a group of wiki that user has access to in the course with groupingid.
+        $groups = groups_get_all_groups($course->id, $USER->id, $wiki->groupingid);
+        if($groups && count($groups)>0) {
+            // Select the first element in the array. Set the groupid to the id of the first element.
+            $group = current($groups);
+            $groupid = $group->id;
         } else {
             // Whatever groups are in the course, pick one
             $coursegroups = groups_get_all_groups($course->id);
-- 
1.5.5.6

