### Eclipse Workspace Patch 1.0
#P moodle19b
Index: mod/forum/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/forum/lib.php,v
retrieving revision 1.609.2.63
diff -u -r1.609.2.63 lib.php
--- mod/forum/lib.php	10 Jul 2008 09:48:46 -0000	1.609.2.63
+++ mod/forum/lib.php	24 Jul 2008 06:08:39 -0000
@@ -6690,4 +6690,11 @@
                   '0' => get_string('openmode0', 'forum') );
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function forum_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames', 'moodle/site:trustcontent');
+}
+
 ?>
Index: mod/scorm/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/lib.php,v
retrieving revision 1.87.2.7
diff -u -r1.87.2.7 lib.php
--- mod/scorm/lib.php	2 Apr 2008 06:10:05 -0000	1.87.2.7
+++ mod/scorm/lib.php	24 Jul 2008 06:08:47 -0000
@@ -627,4 +627,11 @@
     return $status;
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function scorm_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups');
+}
+
 ?>
Index: mod/resource/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/resource/lib.php,v
retrieving revision 1.70.2.11
diff -u -r1.70.2.11 lib.php
--- mod/resource/lib.php	17 Jun 2008 01:47:58 -0000	1.70.2.11
+++ mod/resource/lib.php	24 Jul 2008 06:08:47 -0000
@@ -674,4 +674,12 @@
 function resource_reset_userdata($data) {
     return array();
 }
+
+/**
+ * Returns all other caps used in module
+ */
+function resource_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups');
+}
+
 ?>
Index: mod/glossary/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/glossary/lib.php,v
retrieving revision 1.193.2.14
diff -u -r1.193.2.14 lib.php
--- mod/glossary/lib.php	10 Jul 2008 09:48:46 -0000	1.193.2.14
+++ mod/glossary/lib.php	24 Jul 2008 06:08:41 -0000
@@ -2330,4 +2330,11 @@
     return $status;
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function glossary_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames', 'moodle/site:trustcontent');
+}
+
 ?>
Index: enrol/authorize/db/access.php
===================================================================
RCS file: /cvsroot/moodle/moodle/enrol/authorize/db/access.php,v
retrieving revision 1.6
diff -u -r1.6 access.php
--- enrol/authorize/db/access.php	5 Mar 2007 11:27:19 -0000	1.6
+++ enrol/authorize/db/access.php	24 Jul 2008 06:08:19 -0000
@@ -14,7 +14,7 @@
     'enrol/authorize:uploadcsv' => array(
         'riskbitmask' => RISK_XSS,
         'captype' => 'write',
-        'contextlevel' => CONTEXT_USER,
+        'contextlevel' => CONTEXT_SYSTEM,
         'legacy' => array(
             'admin' => CAP_ALLOW
         )
Index: mod/quiz/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/lib.php,v
retrieving revision 1.282.2.15
diff -u -r1.282.2.15 lib.php
--- mod/quiz/lib.php	22 Jun 2008 13:01:39 -0000	1.282.2.15
+++ mod/quiz/lib.php	24 Jul 2008 06:08:46 -0000
@@ -1174,4 +1174,24 @@
     }
     return '';
 }
+
+/**
+ * Returns all other caps used in module
+ */
+function quiz_get_extra_capabilities() {
+    return array(
+        'moodle/site:accessallgroups',
+        'moodle/question:add',
+        'moodle/question:editmine',
+        'moodle/question:editall',
+        'moodle/question:viewmine',
+        'moodle/question:viewall',
+        'moodle/question:usemine',
+        'moodle/question:useall',
+        'moodle/question:movemine',
+        'moodle/question:moveall',
+        'moodle/question:managecategory',
+    );
+}
+
 ?>
Index: blocks/rss_client/block_rss_client.php
===================================================================
RCS file: /cvsroot/moodle/moodle/blocks/rss_client/block_rss_client.php,v
retrieving revision 1.77.2.7
diff -u -r1.77.2.7 block_rss_client.php
--- blocks/rss_client/block_rss_client.php	23 Mar 2008 16:23:48 -0000	1.77.2.7
+++ blocks/rss_client/block_rss_client.php	24 Jul 2008 06:08:19 -0000
@@ -19,7 +19,7 @@
 
     function init() {
         $this->title = get_string('feedstitle', 'block_rss_client');
-        $this->version = 2007101509;
+        $this->version = 2007101511;
         $this->cron = 300; /// Set min time between cron executions to 300 secs (5 mins)
     }
 
Index: mod/chat/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/chat/lib.php,v
retrieving revision 1.99.2.11
diff -u -r1.99.2.11 lib.php
--- mod/chat/lib.php	14 Feb 2008 16:11:58 -0000	1.99.2.11
+++ mod/chat/lib.php	24 Jul 2008 06:08:29 -0000
@@ -792,4 +792,11 @@
     return $status;
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function chat_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
+}
+
 ?>
Index: mod/hotpot/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/hotpot/lib.php,v
retrieving revision 1.79.2.14
diff -u -r1.79.2.14 lib.php
--- mod/hotpot/lib.php	12 Jul 2008 22:55:39 -0000	1.79.2.14
+++ mod/hotpot/lib.php	24 Jul 2008 06:08:44 -0000
@@ -2603,4 +2603,11 @@
     }
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function hotpot_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups');
+}
+
 ?>
Index: enrol/authorize/version.php
===================================================================
RCS file: /cvsroot/moodle/moodle/enrol/authorize/version.php,v
retrieving revision 1.29
diff -u -r1.29 version.php
--- enrol/authorize/version.php	10 Oct 2007 16:09:27 -0000	1.29
+++ enrol/authorize/version.php	24 Jul 2008 06:08:19 -0000
@@ -1,6 +1,6 @@
 <?php // $Id: version.php,v 1.29 2007/10/10 16:09:27 skodak Exp $
 
-$plugin->version  = 2006112901;
+$plugin->version  = 2006112902;
 $plugin->requires = 2007101000;
 
 ?>
Index: mod/data/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/lib.php,v
retrieving revision 1.137.2.36
diff -u -r1.137.2.36 lib.php
--- mod/data/lib.php	16 Jun 2008 13:46:43 -0000	1.137.2.36
+++ mod/data/lib.php	24 Jul 2008 06:08:33 -0000
@@ -2087,4 +2087,12 @@
     }
     return $status;
 }
+
+/**
+ * Returns all other caps used in module
+ */
+function data_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
+}
+
 ?>
Index: mod/assignment/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/lib.php,v
retrieving revision 1.277.2.42
diff -u -r1.277.2.42 lib.php
--- mod/assignment/lib.php	27 Apr 2008 22:40:21 -0000	1.277.2.42
+++ mod/assignment/lib.php	24 Jul 2008 06:08:29 -0000
@@ -3056,4 +3056,11 @@
     return array('reset_assignment_submissions'=>1);
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function assignment_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
+}
+
 ?>
Index: mod/workshop/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/workshop/Attic/lib.php,v
retrieving revision 1.98.2.2
diff -u -r1.98.2.2 lib.php
--- mod/workshop/lib.php	27 Mar 2008 08:35:34 -0000	1.98.2.2
+++ mod/workshop/lib.php	24 Jul 2008 06:08:51 -0000
@@ -1854,4 +1854,11 @@
     return array('agree','assess','comment','grade','newattachment','removeattachments','resubmit','submit');
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function workshop_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
+}
+
 ?>
Index: version.php
===================================================================
RCS file: /cvsroot/moodle/moodle/version.php,v
retrieving revision 1.563.2.183
diff -u -r1.563.2.183 version.php
--- version.php	24 Jul 2008 01:40:01 -0000	1.563.2.183
+++ version.php	24 Jul 2008 06:08:18 -0000
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2007101520.01;  // YYYYMMDD      = date of the 1.9 branch (don't change)
+    $version = 2007101520.02;  // YYYYMMDD      = date of the 1.9 branch (don't change)
                             //         X     = release number 1.9.[0,1,2,3...]
                             //          Y.YY = micro-increments between releases
 
Index: mod/exercise/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/exercise/Attic/lib.php,v
retrieving revision 1.48.2.3
diff -u -r1.48.2.3 lib.php
--- mod/exercise/lib.php	10 Jul 2008 09:48:45 -0000	1.48.2.3
+++ mod/exercise/lib.php	24 Jul 2008 06:08:33 -0000
@@ -746,4 +746,11 @@
     return array('assess','delete','grade','open','set up','submit');
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function exercise_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups');
+}
+
 ?>
Index: blocks/rss_client/db/access.php
===================================================================
RCS file: /cvsroot/moodle/moodle/blocks/rss_client/db/access.php,v
retrieving revision 1.7
diff -u -r1.7 access.php
--- blocks/rss_client/db/access.php	5 Mar 2007 11:27:06 -0000	1.7
+++ blocks/rss_client/db/access.php	24 Jul 2008 06:08:19 -0000
@@ -36,7 +36,7 @@
     'block/rss_client:createprivatefeeds' => array(
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_BLOCK,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -49,7 +49,7 @@
         'riskbitmask' => RISK_SPAM,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_BLOCK,
         'legacy' => array(
             'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
@@ -59,7 +59,7 @@
     'block/rss_client:manageownfeeds' => array(
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_BLOCK,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -72,7 +72,7 @@
         'riskbitmask' => RISK_SPAM,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_BLOCK,
         'legacy' => array(
             'admin' => CAP_ALLOW
         )
Index: lib/accesslib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v
retrieving revision 1.421.2.68
diff -u -r1.421.2.68 accesslib.php
--- lib/accesslib.php	23 Jul 2008 16:09:15 -0000	1.421.2.68
+++ lib/accesslib.php	24 Jul 2008 06:08:24 -0000
@@ -3399,45 +3399,85 @@
 
     global $CFG;
 
-    $sort = 'ORDER BY contextlevel,component,id';   // To group them sensibly for display
+    $sort = 'ORDER BY contextlevel,component,name';   // To group them sensibly for display
 
     switch ($context->contextlevel) {
 
         case CONTEXT_SYSTEM: // all
-            $SQL = "select * from {$CFG->prefix}capabilities";
+            $SQL = "SELECT *
+                      FROM {$CFG->prefix}capabilities";
         break;
 
         case CONTEXT_USER:
+            $extra = "";
+            if ($extracaps = array('moodle/grade:viewall')) {
+                foreach ($extracaps as $key=>$value) {
+                    $extracaps[$key]= "'$value'";
+                }
+                $extra = implode(',', $extracaps);
+            }
             $SQL = "SELECT *
-                    FROM {$CFG->prefix}capabilities
-                    WHERE contextlevel = ".CONTEXT_USER;
+                      FROM {$CFG->prefix}capabilities
+                     WHERE contextlevel = ".CONTEXT_USER."
+                           OR name IN ($extra)";
         break;
 
         case CONTEXT_COURSECAT: // all
-            $SQL = "select * from {$CFG->prefix}capabilities";
+            $SQL = "SELECT *
+                      FROM {$CFG->prefix}capabilities
+                     WHERE contextlevel IN (".CONTEXT_COURSECAT.",".CONTEXT_COURSE.",".CONTEXT_MODULE.",".CONTEXT_BLOCK.")";
         break;
 
         case CONTEXT_COURSE: // all
-            $SQL = "select * from {$CFG->prefix}capabilities";
-        break;
-
-        case CONTEXT_GROUP: // group caps
+            $SQL = "SELECT *
+                      FROM {$CFG->prefix}capabilities
+                     WHERE contextlevel IN (".CONTEXT_COURSE.",".CONTEXT_MODULE.",".CONTEXT_BLOCK.")";
         break;
 
         case CONTEXT_MODULE: // mod caps
             $cm = get_record('course_modules', 'id', $context->instanceid);
             $module = get_record('modules', 'id', $cm->module);
 
-            $SQL = "select * from {$CFG->prefix}capabilities where contextlevel = ".CONTEXT_MODULE."
-                    and component = 'mod/$module->name'";
+            $extra = "";
+            $modfile = "$CFG->dirroot/mod/$module->name/lib.php";
+            if (file_exists($modfile)) {
+                include_once($modfile);
+                $modfunction = $module->name.'_get_extra_capabilities';
+                if (function_exists($modfunction)) {
+                    if ($extracaps = $modfunction()) {
+                        foreach ($extracaps as $key=>$value) {
+                            $extracaps[$key]= "'$value'";
+                        }
+                        $extra = implode(',', $extracaps);
+                        $extra = "OR name IN ($extra)";
+                    }
+                }
+            }
+
+            $SQL = "SELECT *
+                      FROM {$CFG->prefix}capabilities
+                     WHERE contextlevel = ".CONTEXT_MODULE."
+                           AND component = 'mod/$module->name'
+                           $extra";
         break;
 
         case CONTEXT_BLOCK: // block caps
             $cb = get_record('block_instance', 'id', $context->instanceid);
             $block = get_record('block', 'id', $cb->blockid);
 
-            $SQL = "select * from {$CFG->prefix}capabilities where (contextlevel = ".CONTEXT_BLOCK." AND component = 'moodle')
-                    OR (component = 'block/$block->name')";
+            $extra = "";
+            if ($block = block_instance($block->name)) {
+                if ($extracaps = $block->get_extra_capabilities()) {
+                    $extra = implode(',', $extracaps);
+                    $extra = "OR name IN ($extra)";
+                }
+            }
+
+            $SQL = "SELECT *
+                      FROM {$CFG->prefix}capabilities
+                     WHERE (contextlevel = ".CONTEXT_BLOCK."
+                           AND component = 'block/$block->name')
+                           $extra";
         break;
 
         default:
@@ -3448,54 +3488,10 @@
         $records = array();
     }
 
-/// the rest of code is a bit hacky, think twice before modifying it :-(
-
-    // special sorting of core system capabiltites and enrollments
-    if (in_array($context->contextlevel, array(CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE))) {
-        $first = array();
-        foreach ($records as $key=>$record) {
-            if (preg_match('|^moodle/|', $record->name) and $record->contextlevel == CONTEXT_SYSTEM) {
-                $first[$key] = $record;
-                unset($records[$key]);
-            } else if (count($first)){
-                break;
-            }
-        }
-        if (count($first)) {
-           $records = $first + $records; // merge the two arrays keeping the keys
-        }
-    } else {
-        $contextindependentcaps = fetch_context_independent_capabilities();
-        $records = array_merge($contextindependentcaps, $records);
-    }
-
     return $records;
 
 }
 
-
-/**
- * Gets the context-independent capabilities that should be overrridable in
- * any context.
- * @return array of capability records from the capabilities table.
- */
-function fetch_context_independent_capabilities() {
-
-    //only CONTEXT_SYSTEM capabilities here or it will break the hack in fetch_context_capabilities()
-    $contextindependentcaps = array(
-        'moodle/site:accessallgroups'
-        );
-
-    $records = array();
-
-    foreach ($contextindependentcaps as $capname) {
-        $record = get_record('capabilities', 'name', $capname);
-        array_push($records, $record);
-    }
-    return $records;
-}
-
-
 /**
  * This function pulls out all the resolved capabilities (overrides and
  * defaults) of a role used in capability overrides in contexts at a given
Index: mod/wiki/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/wiki/lib.php,v
retrieving revision 1.53.2.1
diff -u -r1.53.2.1 lib.php
--- mod/wiki/lib.php	24 Jan 2008 20:29:39 -0000	1.53.2.1
+++ mod/wiki/lib.php	24 Jul 2008 06:08:49 -0000
@@ -1739,5 +1739,11 @@
     }
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function wiki_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
+}
 
 ?>
Index: blocks/moodleblock.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/blocks/moodleblock.class.php,v
retrieving revision 1.92.2.7
diff -u -r1.92.2.7 moodleblock.class.php
--- blocks/moodleblock.class.php	1 Apr 2008 05:30:18 -0000	1.92.2.7
+++ blocks/moodleblock.class.php	24 Jul 2008 06:08:18 -0000
@@ -787,6 +787,9 @@
         return true;
     }
 
+    function get_extra_capabilities() {
+        return array();
+    }
 }
 
 /**
Index: lib/db/access.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/access.php,v
retrieving revision 1.75.2.8
diff -u -r1.75.2.8 access.php
--- lib/db/access.php	23 Jul 2008 16:09:14 -0000	1.75.2.8
+++ lib/db/access.php	24 Jul 2008 06:08:25 -0000
@@ -35,7 +35,7 @@
 
     'moodle/site:doanything' => array(
 
-        'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG,
+        'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG | RISK_DATALOSS,
 
         'captype' => 'admin',
         'contextlevel' => CONTEXT_SYSTEM
@@ -91,7 +91,7 @@
 
     'moodle/legacy:admin' => array(
 
-        'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG,
+        'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG | RISK_DATALOSS,
 
         'captype' => 'legacy',
         'contextlevel' => CONTEXT_SYSTEM
@@ -100,7 +100,7 @@
 
     'moodle/site:config' => array(
 
-        'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG,
+        'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS | RISK_CONFIG | RISK_DATALOSS,
 
         'captype' => 'write',
         'contextlevel' => CONTEXT_SYSTEM,
@@ -149,7 +149,7 @@
         'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
@@ -161,7 +161,7 @@
         'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
@@ -173,7 +173,7 @@
         'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
@@ -185,7 +185,7 @@
         'riskbitmask' => RISK_SPAM | RISK_XSS,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_BLOCK,
         'legacy' => array(
             'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
@@ -195,7 +195,7 @@
     'moodle/site:accessallgroups' => array(
 
         'captype' => 'read',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -206,7 +206,7 @@
     'moodle/site:viewfullnames' => array(
 
         'captype' => 'read',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -219,7 +219,7 @@
         'riskbitmask' => RISK_PERSONAL,
 
         'captype' => 'read',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -232,7 +232,7 @@
         'riskbitmask' => RISK_XSS,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
@@ -309,7 +309,7 @@
     'moodle/user:viewdetails' => array(
 
         'captype' => 'read',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'guest' => CAP_ALLOW,
             'student' => CAP_ALLOW,
@@ -324,7 +324,7 @@
         'riskbitmask' => RISK_PERSONAL,
 
         'captype' => 'read',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -348,7 +348,7 @@
         'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
@@ -360,7 +360,7 @@
         'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'admin' => CAP_ALLOW
         )
@@ -371,7 +371,7 @@
         'riskbitmask' => RISK_SPAM,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'editingteacher' => CAP_ALLOW
         )
@@ -391,7 +391,7 @@
     'moodle/role:unassignself' => array(
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'student' => (empty($CFG->allowunenrol)) ? CAP_INHERIT : CAP_ALLOW,
             'teacher' => CAP_ALLOW,
@@ -404,7 +404,7 @@
     'moodle/role:viewhiddenassigns' => array(
 
         'captype' => 'read',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -417,7 +417,7 @@
         'riskbitmask' => RISK_XSS | RISK_PERSONAL,
 
         'captype' => 'read',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'editingteacher' => CAP_ALLOW,
             'admin' => CAP_ALLOW
@@ -685,7 +685,7 @@
     'moodle/blog:view' => array(
 
         'captype' => 'read',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'guest' => CAP_ALLOW,
             'user' => CAP_ALLOW,
@@ -713,7 +713,7 @@
         'riskbitmask' => RISK_SPAM,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -726,7 +726,7 @@
         'riskbitmask' => RISK_SPAM,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'user' => CAP_ALLOW,
             'admin' => CAP_ALLOW
@@ -738,7 +738,7 @@
         'riskbitmask' => RISK_SPAM,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -751,7 +751,7 @@
         'riskbitmask' => RISK_SPAM,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -831,6 +831,17 @@
         )
     ),
 
+    'moodle/user:reviewcaps' => array(
+
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+
     'moodle/question:managecategory' => array(
 
         'captype' => 'write',
@@ -1134,7 +1145,7 @@
 
     'moodle/notes:view' => array(
         'captype' => 'read',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
@@ -1146,7 +1157,7 @@
         'riskbitmask' => RISK_SPAM,
 
         'captype' => 'write',
-        'contextlevel' => CONTEXT_SYSTEM,
+        'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
             'teacher' => CAP_ALLOW,
             'editingteacher' => CAP_ALLOW,
Index: mod/lesson/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/lesson/lib.php,v
retrieving revision 1.41.2.3
diff -u -r1.41.2.3 lib.php
--- mod/lesson/lib.php	24 Jan 2008 20:29:33 -0000	1.41.2.3
+++ mod/lesson/lib.php	24 Jul 2008 06:08:45 -0000
@@ -656,4 +656,11 @@
     return $status;
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function lesson_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups');
+}
+
 ?>
Index: mod/choice/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/choice/lib.php,v
retrieving revision 1.59.2.21
diff -u -r1.59.2.21 lib.php
--- mod/choice/lib.php	27 May 2008 10:16:01 -0000	1.59.2.21
+++ mod/choice/lib.php	24 Jul 2008 06:08:30 -0000
@@ -733,6 +733,13 @@
     }
 
     return $allresponses;
+}
 
+/**
+ * Returns all other caps used in module
+ */
+function chice_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups');
 }
+
 ?>
Index: mod/survey/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/survey/lib.php,v
retrieving revision 1.63.2.5
diff -u -r1.63.2.5 lib.php
--- mod/survey/lib.php	21 May 2008 04:01:09 -0000	1.63.2.5
+++ mod/survey/lib.php	24 Jul 2008 06:08:47 -0000
@@ -575,4 +575,11 @@
     return $status;
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function survey_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups');
+}
+
 ?>
Index: mod/journal/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/journal/Attic/lib.php,v
retrieving revision 1.82.2.1
diff -u -r1.82.2.1 lib.php
--- mod/journal/lib.php	24 Jan 2008 20:29:39 -0000	1.82.2.1
+++ mod/journal/lib.php	24 Jul 2008 06:08:44 -0000
@@ -547,4 +547,11 @@
     return array('add entry','update entry','update feedback');
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function journal_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups');
+}
+
 ?>
Index: mod/label/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/label/lib.php,v
retrieving revision 1.12.4.9
diff -u -r1.12.4.9 lib.php
--- mod/label/lib.php	8 Jul 2008 09:38:27 -0000	1.12.4.9
+++ mod/label/lib.php	24 Jul 2008 06:08:44 -0000
@@ -123,4 +123,11 @@
     return array();
 }
 
+/**
+ * Returns all other caps used in module
+ */
+function lable_get_extra_capabilities() {
+    return array('moodle/site:accessallgroups');
+}
+
 ?>
