Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.169
diff -u -p -r1.169 bootstrap.inc
--- includes/bootstrap.inc	30 May 2007 08:08:57 -0000	1.169
+++ includes/bootstrap.inc	8 Jun 2007 02:33:59 -0000
@@ -1090,3 +1090,72 @@ function ip_address() {
   $remote_ip = check_plain($remote_ip);
   return $remote_ip;
 }
+
+/**
+ * Outputs error messages when site is offline.
+ *
+ * Note that a custom_offline_error_handler($id, $error) function may also be
+ * defined in settings.php, which may make modifications to any of these
+ * messages.
+ *
+ * @param $id
+ *   A unique identifier for the error message. Possible values are:
+ *   - db-connect: Unable to connect to database server.
+ *   - db-php: PHP support for the database type was not found.
+ *   - db-select: Could not select database.
+ *   - db-type: Database type not supported.
+ *   - unknown: An unknown error.
+ */
+function drupal_offline_error_handler($id) {
+  global $db_url, $db_type, $active_db;
+  $error = array();
+  $db_error = $db_type .'_error';
+  include_once './includes/common.inc';
+  include_once './includes/theme.inc';
+
+  // Generate default error messages.
+  switch ($id) {
+    case 'db-connect':
+      $error['title'] = 'Unable to connect to database server';
+      $error['error'] = '<p>If you still have to install Drupal, proceed to the <a href="'. base_path() .'install.php">installation page</a>.</p>
+<p>If you have already finished installed Drupal, this either means that the username and password information in your <code>settings.php</code> file is incorrect or that we can\'t connect to the '. $db_type .' database server. This could mean your hosting provider\'s database server is down.</p>
+<p>The database error was: '. theme('placeholder', call_user_func($db_error)) .'.</p>
+<p>Currently, the username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.</p>
+<ul>
+  <li>Are you sure you have the correct username and password?</li>
+  <li>Are you sure that you have typed the correct hostname?</li>
+  <li>Are you sure that the database server is running?</li>
+</ul>
+<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>';
+      break;
+    case 'db-php':
+      $error['title'] = "PHP $db_type support not enabled";
+      $error['error'] = '<p>We were unable to use the '. $db_type .' database because the '. $db_type .' extension for PHP is not installed. Check your <code>PHP.ini</code> to see how you can enable it.</p>
+<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>';
+      break;
+    case 'db-type':
+      $error['title'] = 'Unsupported database type';
+      $error['error'] = '<p>The database type '. theme('placeholder', $db_type) .' is unsupported. Please use either <var>mysql</var> for MySQL 4.0.x+ databases, <var>mysqli</var> for MySQL 4.1.x+ databases, or <var>pgsql</var> for PostgreSQL databases. The database information is in your <code>settings.php</code> file.</p>
+<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>';
+      break;
+    case 'db-select':
+      $error['title'] = 'Unable to select database';
+      $error['error'] = '<p>We were able to connect to the database server (which means your username and password are okay) but not able to select the database.</p><p>The database error was: '. theme('placeholder', call_user_func($db_type .'_error', $connection)) .'.</p><p>Currently, the database is '. theme('placeholder', substr($url['path'], 1)) .'. The username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.</p><ul>  <li>Are you sure you have the correct database name?</li>  <li>Are you sure the database exists?</li>  <li>Are you sure the username has permission to access the database?</li></ul><p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>';
+      break;
+    default:
+      $id = 'unknown';
+      $error['title'] = 'Unknown';
+      $error['error'] = '<p>An unknown error has occurred.</p>';
+  }
+
+  // Allow customization of error message.
+  if (function_exists('custom_offline_error_handler')) {
+    $error = custom_offline_error_handler($id, $error); 
+  }
+
+  // Output error.
+  drupal_maintenance_theme();
+  drupal_set_header('HTTP/1.1 503 Service Unavailable');
+  drupal_set_title($error['title']);
+  print theme('maintenance_page', $error['error']);
+}
Index: includes/database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.inc,v
retrieving revision 1.70
diff -u -p -r1.70 database.inc
--- includes/database.inc	30 May 2007 09:11:21 -0000	1.70
+++ includes/database.inc	8 Jun 2007 02:34:00 -0000
@@ -139,10 +139,7 @@ function db_set_active($name = 'default'
       include_once $handler;
     }
     else {
-      drupal_maintenance_theme();
-      drupal_set_title('Unsupported database type');
-      print theme('maintenance_page', '<p>The database type '. theme('placeholder', $db_type) .' is unsupported. Please use either <var>mysql</var> for MySQL 3.x &amp; 4.0.x databases, <var>mysqli</var> for MySQL 4.1.x+ databases, or <var>pgsql</var> for PostgreSQL databases. The database information is in your <code>settings.php</code> file.</p>
-<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+      drupal_offline_error_handler('db-type');
       exit;
     }
 
Index: includes/database.mysql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.mysql.inc,v
retrieving revision 1.74
diff -u -p -r1.74 database.mysql.inc
--- includes/database.mysql.inc	5 Jun 2007 12:13:20 -0000	1.74
+++ includes/database.mysql.inc	8 Jun 2007 02:34:00 -0000
@@ -53,10 +53,7 @@ function db_connect($url) {
 
   // Check if MySQL support is present in PHP
   if (!function_exists('mysql_connect')) {
-    drupal_maintenance_theme();
-    drupal_set_title('PHP MySQL support not enabled');
-    print theme('maintenance_page', '<p>We were unable to use the MySQL database because the MySQL extension for PHP is not installed. Check your <code>PHP.ini</code> to see how you can enable it.</p>
-<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+    drupal_offline_error_handler('db-php');
     exit;
   }
 
@@ -86,34 +83,12 @@ function db_connect($url) {
   $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);
   if (!$connection) {
     // Show error screen otherwise
-    drupal_maintenance_theme();
-    drupal_set_header('HTTP/1.1 503 Service Unavailable');
-    drupal_set_title('Unable to connect to database server');
-    print theme('maintenance_page', '<p>If you still have to install Drupal, proceed to the <a href="'. base_path() .'install.php">installation page</a>.</p>
-<p>If you have already finished installed Drupal, this either means that the username and password information in your <code>settings.php</code> file is incorrect or that we can\'t connect to the MySQL database server. This could mean your hosting provider\'s database server is down.</p>
-<p>The MySQL error was: '. theme('placeholder', mysql_error()) .'.</p>
-<p>Currently, the username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.</p>
-<ul>
-  <li>Are you sure you have the correct username and password?</li>
-  <li>Are you sure that you have typed the correct hostname?</li>
-  <li>Are you sure that the database server is running?</li>
-</ul>
-<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+    drupal_offline_error_handler('db-connect');
     exit;
   }
 
   if (!mysql_select_db(substr($url['path'], 1))) {
-    drupal_maintenance_theme();
-    drupal_set_title('Unable to select database');
-    print theme('maintenance_page', '<p>We were able to connect to the MySQL database server (which means your username and password are okay) but not able to select the database.</p>
-<p>The MySQL error was: '. theme('placeholder', mysql_error($connection)) .'.</p>
-<p>Currently, the database is '. theme('placeholder', substr($url['path'], 1)) .'. The username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.</p>
-<ul>
-  <li>Are you sure you have the correct database name?</li>
-  <li>Are you sure the database exists?</li>
-  <li>Are you sure the username has permission to access the database?</li>
-</ul>
-<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+    drupal_offline_error_handler('db-select');
     exit;
   }
 
Index: includes/database.mysqli.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.mysqli.inc,v
retrieving revision 1.38
diff -u -p -r1.38 database.mysqli.inc
--- includes/database.mysqli.inc	5 Jun 2007 12:13:20 -0000	1.38
+++ includes/database.mysqli.inc	8 Jun 2007 02:34:02 -0000
@@ -58,10 +58,7 @@ function db_version() {
 function db_connect($url) {
   // Check if MySQLi support is present in PHP
   if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
-    drupal_maintenance_theme();
-    drupal_set_title('PHP MySQLi support not enabled');
-    print theme('maintenance_page', '<p>We were unable to use the MySQLi database because the MySQLi extension for PHP is not installed. Check your <code>PHP.ini</code> to see how you can enable it.</p>
-<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+    drupal_offline_error_handler('db-php');
     exit;
   }
 
@@ -84,34 +81,11 @@ function db_connect($url) {
 
   // Find all database connection errors and error 1045 for access denied for user account
   if (mysqli_connect_errno() >= 2000 || mysqli_connect_errno() == 1045) {
-    drupal_maintenance_theme();
-    drupal_set_header('HTTP/1.1 503 Service Unavailable');
-    drupal_set_title('Unable to connect to database server');
-    print theme('maintenance_page', '<p>If you still have to install Drupal, proceed to the <a href="'. base_path() .'install.php">installation page</a>.</p>
-<p>If you have already finished installed Drupal, this either means that the username and password information in your <code>settings.php</code> file is incorrect or that we can\'t connect to the MySQL database server. This could mean your hosting provider\'s database server is down.</p>
-<p>The MySQL error was: '. theme('placeholder', mysqli_error($connection)) .'.</p>
-<p>Currently, the username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.</p>
-<ul>
-  <li>Are you sure you have the correct username and password?</li>
-  <li>Are you sure that you have typed the correct hostname?</li>
-  <li>Are you sure that the database server is running?</li>
-  <li>Are you sure that the mysqli libraries are compiled in your PHP installation? Try using the mysql library instead by editing your <code>settings.php</code> configuration file in Drupal.</li>
-</ul>
-<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+    drupal_offline_error_handler('db-connect');
     exit;
   }
   else if (mysqli_connect_errno() > 0) {
-    drupal_maintenance_theme();
-    drupal_set_title('Unable to select database');
-    print theme('maintenance_page', '<p>We were able to connect to the MySQL database server (which means your username and password are okay) but not able to select the database.</p>
-<p>The MySQL error was: '. theme('placeholder', mysqli_error($connection)) .'.</p>
-<p>Currently, the database is '. theme('placeholder', substr($url['path'], 1)) .'. The username is '. theme('placeholder', $url['user']) .' and the database server is '. theme('placeholder', $url['host']) .'.</p>
-<ul>
-  <li>Are you sure you have the correct database name?</li>
-  <li>Are you sure the database exists?</li>
-  <li>Are you sure the username has permission to access the database?</li>
-</ul>
-<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+    drupal_offline_error_handler('db-select');
     exit;
   }
 
Index: includes/database.pgsql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.pgsql.inc,v
retrieving revision 1.49
diff -u -p -r1.49 database.pgsql.inc
--- includes/database.pgsql.inc	5 Jun 2007 12:13:20 -0000	1.49
+++ includes/database.pgsql.inc	8 Jun 2007 02:34:02 -0000
@@ -47,10 +47,7 @@ function db_version() {
 function db_connect($url) {
    // Check if MySQL support is present in PHP
   if (!function_exists('pg_connect')) {
-    drupal_maintenance_theme();
-    drupal_set_title('PHP PostgreSQL support not enabled');
-    print theme('maintenance_page', '<p>We were unable to use the PostgreSQL database because the PostgreSQL extension for PHP is not installed. Check your <code>PHP.ini</code> to see how you can enable it.</p>
-<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+    drupal_offline_error_handler('db-php');
     exit;
   }
 
@@ -82,20 +79,7 @@ function db_connect($url) {
 
   $connection = @pg_connect($conn_string);
   if (!$connection) {
-    drupal_maintenance_theme();
-    drupal_set_header('HTTP/1.1 503 Service Unavailable');
-    drupal_set_title('Unable to connect to database');
-    print theme('maintenance_page', '<p>If you still have to install Drupal, proceed to the <a href="'. base_path() .'install.php">installation page</a>.</p>
-<p>If you have already finished installed Drupal, this either means that the username and password information in your <code>settings.php</code> file is incorrect or that we can\'t connect to the PostgreSQL database server. This could mean your hosting provider\'s database server is down.</p>
-<p>The PostgreSQL error was: '. theme('placeholder', decode_entities($php_errormsg)) .'</p>
-<p>Currently, the database is '. theme('placeholder', substr($url['path'], 1)) .', the username is '. theme('placeholder', $url['user']) .', and the database server is '. theme('placeholder', $url['host']) .'.</p>
-<ul>
-  <li>Are you sure you have the correct username and password?</li>
-  <li>Are you sure that you have typed the correct hostname?</li>
-  <li>Are you sure you have the correct database name?</li>
-  <li>Are you sure that the database server is running?</li>
-</ul>
-<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
+    drupal_offline_error_handler('db-connect');
     exit;
   }
 
