=== modified file 'includes/bootstrap.inc'
--- includes/bootstrap.inc	2009-12-02 19:26:21 +0000
+++ includes/bootstrap.inc	2009-12-05 13:11:34 +0000
@@ -707,13 +707,26 @@ function drupal_get_filename($type, $nam
  * file.
  */
 function variable_initialize($conf = array()) {
-  // NOTE: caching the variables improves performance by 20% when serving cached pages.
-  if ($cached = cache_get('variables', 'cache_bootstrap')) {
-    $variables = $cached->data;
+  $variables = array();
+  try {
+    // NOTE: caching the variables improves performance by 20% when serving cached pages.
+    if ($cached = cache_get('variables', 'cache_bootstrap')) {
+      $variables = $cached->data;
+    }
+    else {
+      $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
+      cache_set('variables', $variables, 'cache_bootstrap');
+    }
   }
-  else {
-    $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
-    cache_set('variables', $variables, 'cache_bootstrap');
+  catch (Exception $e) {
+    // Do nothing.
+  }
+  $variables = array();
+  if (!isset($variables['install_time'])) {
+    drupal_maintenance_theme();
+    drupal_language_initialize();
+    print theme('maintenance_page', array('content' => t('boo.')));
+    exit;
   }
 
   foreach ($conf as $name => $value) {

=== modified file 'includes/theme.inc'
--- includes/theme.inc	2009-12-02 14:56:32 +0000
+++ includes/theme.inc	2009-12-05 13:12:48 +0000
@@ -2250,7 +2250,7 @@ function template_preprocess(&$variables
   $variables['is_admin']            = FALSE;
   $variables['is_front']            = FALSE;
   $variables['logged_in']           = FALSE;
-  if ($variables['db_is_active'] = db_is_active()  && !defined('MAINTENANCE_MODE')) {
+  if ($variables['db_is_active'] = db_is_active()  && !defined('MAINTENANCE_MODE') && function_exists('user_access')) {
     // Check for administrators.
     if (user_access('access administration pages')) {
       $variables['is_admin'] = TRUE;

=== modified file 'includes/theme.maintenance.inc'
--- includes/theme.maintenance.inc	2009-12-01 15:57:40 +0000
+++ includes/theme.maintenance.inc	2009-12-05 13:10:17 +0000
@@ -36,7 +36,7 @@ function _drupal_maintenance_theme() {
     $custom_theme = 'seven';
   }
   else {
-    if (!db_is_active()) {
+    if (!db_is_active() || drupal_bootstrap() != DRUPAL_BOOTSTRAP_FULL) {
       // Because we are operating in a crippled environment, we need to
       // bootstrap just enough to allow hook invocations to work.
       $module_list['system']['filename'] = 'modules/system/system.module';

=== modified file 'modules/system/system.module'
--- modules/system/system.module	2009-12-04 16:49:45 +0000
+++ modules/system/system.module	2009-12-05 13:12:24 +0000
@@ -3591,7 +3591,7 @@ function system_preprocess(&$variables, 
   $variables['contextual_links'] = array();
 
   // Nothing to do here if the user is not permitted to access contextual links.
-  if (!user_access('access contextual links')) {
+  if (!function_exists('user_access') || !user_access('access contextual links')) {
     return;
   }
 

