Index: install.php
===================================================================
RCS file: /cvs/drupal/drupal/install.php,v
retrieving revision 1.34
diff -u -p -r1.34 install.php
--- install.php	10 Jan 2007 10:15:07 -0000	1.34
+++ install.php	16 Jan 2007 23:17:42 -0000
@@ -555,6 +555,17 @@ function install_complete($profile) {
     // No more steps
     $output .= '<p>' . (drupal_set_message() ? st('Please review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) . '</p>';
   }
+
+  // Automatically enable clean URLs if possible.
+  drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module');
+  drupal_add_js('
+  // Global Killswitch
+  if (Drupal.jsEnabled) {
+    $(document).ready(function() {
+      Drupal.cleanURLsCheck("install", "' . base_path() . 'admin/settings/clean-urls/install_test");
+    });
+  }', 'inline');
+
   // Output page.
   print theme('maintenance_page', $output);
 }
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.441
diff -u -p -r1.441 system.module
--- modules/system/system.module	15 Jan 2007 12:03:50 -0000	1.441
+++ modules/system/system.module	16 Jan 2007 23:17:43 -0000
@@ -268,6 +268,11 @@ function system_menu($may_cache) {
       'description' => t('Enable or disable clean URLs for your site.'),
       'callback' => 'drupal_get_form',
       'callback arguments' => array('system_clean_url_settings'));
+    $items[] = array(
+      'path' => 'admin/settings/clean-urls/install_test',
+      'callback' => 'system_clean_urls_install_check',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK);
 
 
     // Logs:
@@ -610,6 +615,45 @@ function system_clean_url_settings() {
   return system_settings_form($form);
 }
 
+/**
+ * Automatically enable clean URLs during installation if possible.
+ *
+ * This function is called via Ajax from install.php.
+ */
+function system_clean_urls_install_check() {
+  // Check that only the anonymous user exists.
+  $result = db_query('SELECT COUNT(*) AS count FROM {users} WHERE uid > 0');
+  $obj = db_fetch_object($result);
+  if ($obj->count > 0) {
+   watchdog('cleanurls test', 'Clean URLs installation test attempted but users exist. Aborting.');
+    exit;
+  }
+
+  // Check that no nodes exist.
+  $result = db_query('SELECT COUNT(*) FROM {node}');
+  $obj = db_fetch_object($result);
+  if ($obj->count > 0) {
+    watchdog('cleanurls test', 'Clean URLs installation test attempted but nodes exist. Aborting.');
+    exit;
+  }
+  
+  // Make sure that the clean URLs variable wasn't already set.
+  if (!is_null(variable_get('clean_url', NULL))) {
+    watchdog('cleanurls test', 'Clean URLs installation test attempted but variable already set. Aborting.');
+    exit;
+  }
+
+  // Make sure that this was a true clean URL test.
+  if (strpos(request_uri(), '?q=') !== FALSE) {
+    watchdog('cleanurls test', 'Clean URLs installation test attempted but incorrect url was used. Aborting.');
+    exit;
+  }
+
+  // This is a new website and clean URLs test worked, so save the setting.
+  variable_set('clean_url', 1);
+  watchdog('cleanurls test', 'Clean URLs installation test attempted and succeeded. Clean URLs were automatically enabled.');
+}
+
 function system_error_reporting_settings() {
 
   $form['site_403'] = array(
