--- ../drupal/install.php	2007-04-13 10:56:57.000000000 +0200
+++ install.php	2007-05-06 17:45:23.000000000 +0200
@@ -24,6 +24,17 @@ function install_main() {
   // Ensure correct page headers are sent (e.g. caching)
   drupal_page_header();
 
+  // Finalizing steps can do redirects and redirect to install.php?install_finalized=1
+  // to ensure installation is not triggered again.
+  if (isset($_GET['install_finalized'])) {
+    $install_locale = check_plain($_GET['locale']);
+    $profile = check_plain($_GET['profile']);
+    include_once "profiles/$profile/$profile.profile";
+    install_complete();
+    exit;
+  }
+
+
   // Check existing settings.php.
   $verify = install_verify_settings();
 
@@ -95,8 +106,11 @@ function install_main() {
     drupal_set_message(st('All necessary changes to %file have been made. It has been set to read-only for security.', array('%file' => $settings_file)));
   }
 
+  // Finalize installation. Anything, including redirects can happen here.
+  // Make sure that if you use redirect, you set $_GET['install_finalized'] to true.
+  $profile_message = install_finalize($profile);
   // Show end page.
-  install_complete($profile);
+  install_complete($profile_message);
 }
 
 /**
@@ -484,7 +498,7 @@ function install_select_locale($profilen
 
 function install_select_locale_form($locales) {
   include_once './includes/locale.inc';
-  $languages = _locale_get_iso639_list();
+  $languages = _locale_get_predefined_list();
   foreach ($locales as $locale) {
     // Try to use verbose locale name
     $name = $locale->name;
@@ -544,11 +558,10 @@ function install_missing_modules_error($
 }
 
 /**
- * Page displayed when the installation is complete. Called from install.php.
+ * Finalize installation, call profile final function if it exists.
  */
-function install_complete($profile) {
-  global $base_url;
-  $output = '';
+function install_finalize($profile) {
+  global $install_locale;
   // Store install profile for later use.
   variable_set('install_profile', $profile);
 
@@ -557,23 +570,36 @@ function install_complete($profile) {
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
   $_SESSION['messages'] = $messages;
 
-  // Build final page.
-  drupal_maintenance_theme();
-  install_task_list();
-  drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())));
-  $output .= '<p>'. st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) .'</p>';
-
   // Show profile finalization info.
   $function = $profile .'_profile_final';
   if (function_exists($function)) {
     // More steps required
     $profile_message = $function();
   }
+  return $profile_message;
+}
+/**
+ * Page displayed when the installation is complete. Called from install.php.
+ */
+function install_complete($profile_message = NULL) {
+  global $base_url;
+  $output = '';
+
+  // Bootstrap newly installed Drupal.
+  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
+  // Rebuild all menus. Nothing should change now.
   menu_rebuild();
+  
+  // Build final page.
+  drupal_maintenance_theme();
+  install_task_list();
+  drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())));
+  $output .= '<p>'. st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) .'</p>';
+
   // If the profile returned a welcome message, use that instead of default.
-  if (isset($profile_message)) {
-    $output .= $profile_message;
+  if (isset($_SESSION['profile_message']) || isset($profile_message)) {
+    $output .= isset($_SESSION['profile_message']) ? $_SESSION['profile_message'] : $profile_message;
   }
   else {
     // No more steps
