protected static function determine_group_and_user($cm, $wiki, $groupid = -1, $userid = 0) {
        global $USER;

        $currentgroup = groups_get_activity_group($cm);
        if ($currentgroup === false) {
            // Activity doesn't use groups.
            $groupid = 0;
        } else if ($groupid == -1) {
            // Use current group.
            $groupid = !empty($currentgroup) ? $currentgroup : 0;
        }

        // Determine user.
        if ($wiki->wikimode == 'collaborative') {
            // Collaborative wikis don't use userid in subwikis.
            $userid = 0;
        } else if (empty($userid)) {
            // Use current user.
            $userid = $USER->id;
        }

        return array($groupid, $userid);
    }