Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.550
diff -u -p -r1.550 theme.inc
--- includes/theme.inc	8 Nov 2009 12:43:41 -0000	1.550
+++ includes/theme.inc	10 Nov 2009 22:29:29 -0000
@@ -1161,6 +1161,7 @@ function theme_get_setting($setting_name
       'toggle_comment_user_verification' =>  1,
       'toggle_main_menu'                 =>  1,
       'toggle_secondary_menu'            =>  1,
+      'toggle_contextual_links'          =>  1,
     );
 
     // Get the default values for the custom settings from the .info file.
Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.220
diff -u -p -r1.220 system.admin.inc
--- modules/system/system.admin.inc	8 Nov 2009 13:23:41 -0000	1.220
+++ modules/system/system.admin.inc	10 Nov 2009 22:29:30 -0000
@@ -440,6 +440,7 @@ function system_theme_settings($form, &$
     'favicon'                   => t('Shortcut icon'),
     'main_menu'                 => t('Main menu'),
     'secondary_menu'            => t('Secondary menu'),
+    'contextual_links'          => t('Contextual links'),
   );
 
   // Some features are not always available
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.838
diff -u -p -r1.838 system.module
--- modules/system/system.module	8 Nov 2009 10:29:23 -0000	1.838
+++ modules/system/system.module	10 Nov 2009 22:29:31 -0000
@@ -196,6 +196,26 @@ function system_theme() {
  * Implement hook_permission().
  */
 function system_permission() {
+  // Determine if there are any themes that do not support contextual links,
+  // so that we can add a proper permission description for 'access contextual
+  // links'.
+  $themes = list_themes();
+  $themes_without_contextual_links = array();
+  foreach ($themes as $theme) {
+    if (drupal_theme_access($theme) && !theme_get_setting('toggle_contextual_links', $theme->name)) {
+      $themes_without_contextual_links[] = $theme->info['name'];
+    }
+  }
+  if (empty($themes_without_contextual_links)) {
+    $contextual_links_description = t('Use contextual links to perform actions related to elements on a page.');
+  }
+  elseif (count($themes_without_contextual_links) == 1) {
+    $contextual_links_description = t('Use contextual links to perform actions related to elements on a page. (Note: The %theme theme is not configured to display contextual links, so this permission will not have an effect when that theme is being used.)', array('%theme' => reset($themes_without_contextual_links)));
+  }
+  else {
+    $contextual_links_description = t('Use contextual links to perform actions related to elements on a page. (Note: The following themes are not configured to display contextual links, so this permission will not have an effect when those themes are being used: %themes)', array('%themes' => implode(', ', $themes_without_contextual_links)));
+  }
+
   return array(
     'administer site configuration' => array(
       'title' => t('Administer site configuration'),
@@ -219,7 +239,7 @@ function system_permission() {
     ),
     'access contextual links' => array(
       'title' => t('Access contextual links'),
-      'description' => t('Use contextual links to perform actions related to elements on a page.'),
+      'description' => $contextual_links_description,
     ),
     'access site in maintenance mode' => array(
       'title' => t('Access site in maintenance mode'),
@@ -2217,6 +2237,7 @@ function _system_rebuild_theme_data() {
         'slogan',
         'main_menu',
         'secondary_menu',
+        'contextual_links',
       ),
       'screenshot' => 'screenshot.png',
       'php' => DRUPAL_MINIMUM_PHP,
@@ -3542,8 +3563,9 @@ function system_preprocess(&$variables, 
   // Initialize the $contextual_links template variable.
   $variables['contextual_links'] = array();
 
-  // Nothing to do here if the user is not permitted to access contextual links.
-  if (!user_access('access contextual links')) {
+  // Nothing to do here if the user is not permitted to access contextual links
+  // or the theme is configured not to render them.
+  if (!user_access('access contextual links') || !theme_get_setting('toggle_contextual_links')) {
     return;
   }
 
