st('Your web server does not appear to support any common database types. Check with your hosting provider to see if they offer any databases that Drupal supports.', array('@drupal-databases' => 'http://drupal.org/node/270#database')), ); } else { $form['basic_options'] = array( '#type' => 'fieldset', '#title' => st('Basic options'), '#description' => '
'. st('To set up your @drupal database, enter the following information.', array('@drupal' => drupal_install_profile_name())) .'
', ); if (count($db_types) > 1) { $form['basic_options']['db_type'] = array( '#type' => 'radios', '#title' => st('Database type'), '#required' => TRUE, '#options' => $db_types, '#default_value' => ($db_type ? $db_type : current($db_types)), '#description' => st('The type of database your @drupal data will be stored in.', array('@drupal' => drupal_install_profile_name())), ); $db_path_description = st('The name of the database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('@drupal' => drupal_install_profile_name())); } else { if (count($db_types) == 1) { $db_types = array_values($db_types); $form['basic_options']['db_type'] = array( '#type' => 'hidden', '#value' => $db_types[0], ); $db_path_description = st('The name of the %db_type database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('%db_type' => $db_types[0], '@drupal' => drupal_install_profile_name())); } } // Database name $form['basic_options']['db_path'] = array( '#type' => 'textfield', '#title' => st('Database name'), '#default_value' => $db_path, '#size' => 45, '#maxlength' => 45, '#required' => TRUE, '#description' => $db_path_description ); // Database username $form['basic_options']['db_user'] = array( '#type' => 'textfield', '#title' => st('Database username'), '#default_value' => $db_user, '#size' => 45, '#maxlength' => 45, '#required' => TRUE, ); // Database username $form['basic_options']['db_pass'] = array( '#type' => 'password', '#title' => st('Database password'), '#default_value' => $db_pass, '#size' => 45, '#maxlength' => 45, ); $form['advanced_options'] = array( '#type' => 'fieldset', '#title' => st('Advanced options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => st("These options are only necessary for some sites. If you're not sure what you should enter here, leave the default settings or check with your hosting provider.") ); // Database host $form['advanced_options']['db_host'] = array( '#type' => 'textfield', '#title' => st('Database host'), '#default_value' => $db_host, '#size' => 45, '#maxlength' => 45, '#required' => TRUE, '#description' => st('If your database is located on a different server, change this.'), ); // Database port $form['advanced_options']['db_port'] = array( '#type' => 'textfield', '#title' => st('Database port'), '#default_value' => $db_port, '#size' => 45, '#maxlength' => 45, '#description' => st('If your database server is listening to a non-standard port, enter its number.'), ); // Table prefix $prefix = ($profile == 'default') ? 'drupal_' : $profile .'_'; $form['advanced_options']['db_prefix'] = array( '#type' => 'textfield', '#title' => st('Table prefix'), '#default_value' => $db_prefix, '#size' => 45, '#maxlength' => 45, '#description' => st('If more than one application will be sharing this database, enter a table prefix such as %prefix for your @drupal site here.', array('@drupal' => drupal_install_profile_name(), '%prefix' => $prefix)), ); // Create database $db_create = $_POST['db_create']; $form['create_database'] = array( '#type' => 'fieldset', '#title' => st('Create database'), '#collapsible' => TRUE, '#collapsed' => !$db_create, '#description' => st("If database is not exists, you can create it. This is useful when you develop sites on your desktop."), ); // Database master username $form['create_database']['db_create'] = array( '#type' => 'checkbox', '#title' => st('Create new database'), '#default_value' => $db_create, '#description' => st("Check if you want to create new database"), ); // Database master username $form['create_database']['db_master_user'] = array( '#type' => 'textfield', '#title' => st('Database master username'), '#default_value' => 'root', '#size' => 45, '#maxlength' => 45, '#description' => st("Enter database master username, usually 'root'"), ); // Database master password $form['create_database']['db_master_pass'] = array( '#type' => 'password', '#title' => st('Database master password'), '#size' => 45, '#maxlength' => 45, ); $form['save'] = array( '#type' => 'submit', '#value' => st('Save and continue'), ); $form['errors'] = array(); $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file); $form['_db_url'] = array('#type' => 'value'); $form['#action'] = "install.php?profile=$profile". ($install_locale ? "&locale=$install_locale" : ''); $form['#redirect'] = FALSE; } return $form; } /** * Form API validate for install_settings form. */ function install_settings_form_validate($form, &$form_state) { global $db_url; if(_install_settings_form_create_database_validate($form_state['values']['db_create'], $form_state['values']['db_type'], $form_state['values']['db_master_user'], $form_state['values']['db_master_pass'], $form_state['values']['db_user'], $form_state['values']['db_pass'], $form_state['values']['db_host'], $form_state['values']['db_port'], $form_state['values']['db_path'])) _install_settings_form_validate($form_state['values']['db_prefix'], $form_state['values']['db_type'], $form_state['values']['db_user'], $form_state['values']['db_pass'], $form_state['values']['db_host'], $form_state['values']['db_port'], $form_state['values']['db_path'], $form_state['values']['settings_file'], $form_state, $form); } /** * Create database before future validation */ function _install_settings_form_create_database_validate($db_create, $db_type, $db_master_user, $db_master_pass, $db_user, $db_pass, $db_host, $db_port, $db_path) { global $db_url; if ($db_create) { if (!$db_master_user) { form_set_error('db_master_user', st('Master username is required')); return; } $function = '_install_create_db_' . $db_type; if (function_exists($function)) return $function($db_master_user, $db_master_pass, $db_user, $db_pass, $db_host, $db_port, $db_path); else form_set_error('', 'Create database feature is not suported for this database type yet.'); } return true; } function _install_create_db_mysql($db_master_user, $db_master_pass, $db_user, $db_pass, $db_host, $db_port, $db_path) { // Verify database connection $connect_host = ($db_host ? $db_host : 'localhost') . ($db_port ? ":$db_port" : ''); $conn = @mysql_connect($connect_host, $db_master_user, $db_master_pass); if (!$conn) { form_set_error('', st('Failed to connect to your MySQL database server by master. MySQL reports the following message: ') . mysql_error()); return false; } // Get version of database $result = @mysql_query("SHOW variables WHERE Variable_name='version'"); if (!$result) { form_set_error('', st('Failed get version of database. MySQL reports the following message: ' . mysql_error())); mysql_close($conn); return false; } $row = mysql_fetch_array($result); $version = $row['Value']; if (!$version) { form_set_error('', st('Failed to get version of database')); mysql_close($conn); return false; } // Create databse if (strcmp($version, "4.1") >= 0) $utf8_suffix = " DEFAULT CHARACTER SET 'utf8' DEFAULT COLLATE 'utf8_general_ci'"; $result = @mysql_query(sprintf("CREATE DATABASE IF NOT EXISTS `%s`" . $utf8_suffix, mysql_escape_string($db_path))); if (!$result) { form_set_error('', st('Failed to create database. MySQL reports the following message: ' . mysql_error())); mysql_close($conn); return false; } // Grant permissions $result = @mysql_query(sprintf("GRANT ALL ON `%s`.* TO `%s`@'%%' IDENTIFIED BY '%s'", mysql_escape_string($db_path), mysql_escape_string($db_user), mysql_escape_string($db_pass))); if (!$result) { form_set_error('', st('Failed to grant permissions. MySQL reports the following message: ' . mysql_error())); mysql_close($conn); return false; } mysql_close($conn); return true; } function _install_create_db_mysqli($db_master_user, $db_master_pass, $db_user, $db_pass, $db_host, $db_port, $db_path) { // Verify database connection $connect_host = ($db_host ? $db_host : 'localhost') . ($db_port ? ":$db_port" : ''); $conn = @mysqli_connect($connect_host, $db_master_user, $db_master_pass); if (!$conn) { form_set_error('', st('Failed to connect to your MySQL database server by master. MySQL reports the following message: ') . mysqli_connect_error()); return false; } // Get version of database $result = @mysqli_query($conn, "SHOW variables WHERE Variable_name='version'"); if (!$result) { form_set_error('', st('Failed get version of database. MySQL reports the following message: ' . mysqli_error($conn))); mysqli_close($conn); return false; } $row = mysqli_fetch_array($result); $version = $row['Value']; if (!$version) { form_set_error('', st('Failed to get version of database')); mysqli_close($conn); return false; } // Create databse if (strcmp($version, "4.1") >= 0) $utf8_suffix = " DEFAULT CHARACTER SET 'utf8' DEFAULT COLLATE 'utf8_general_ci'"; $result = @mysqli_query($conn, sprintf("CREATE DATABASE IF NOT EXISTS `%s`" . $utf8_suffix, mysqli_escape_string($db_path))); if (!$result) { form_set_error('', st('Failed to create database. MySQL reports the following message: ' . mysqli_error($conn))); mysqli_close($conn); return false; } // Grant permissions $result = @mysqli_query($conn, sprintf("GRANT ALL ON `%s`.* TO `%s`@'%%' IDENTIFIED BY '%s'", mysqli_escape_string($db_path), mysqli_escape_string($db_user), mysqli_escape_string($db_pass))); if (!$result){ form_set_error('', st('Failed to grant permissions. MySQL reports the following message: ' . mysqli_error($conn))); mysqli_close($conn); return false; } mysqli_close($conn); return true; } function _install_create_db_pgsql($db_master_user, $db_master_pass, $db_user, $db_pass, $db_host, $db_port, $db_path) { $conn_string = ''; //Make connection string if (!empty($db_master_user)) { $conn_string .= ' user='. $db_master_user; } if (!empty($db_master_pass)) { $conn_string .= ' password='. $db_master_pass; } if (!empty($db_host)) { $conn_string .= ' host='. $db_host; } if (!empty($db_path)) { $conn_string .= ' dbname=postgres'; } if (!empty($db_port)) { $conn_string .= ' port='. $db_port; } // Connect to the database. $conn = @pg_connect($conn_string); if (!$conn) { drupal_set_message(st('Failed to connect to your PostgreSQL database server. PostgreSQL reports the following message: %error.'. st('With the addition of an appropriate translation package, this installer is capable of proceeding in another language of your choice. To install and use Drupal in a language other than English:') .'
'; $output .= ''. st('Alternatively, to install and use Drupal in English, or to defer the selection of an alternative language until after installation, select the first link below.') .'
'; $output .= ''. st('How should the installation continue?') .'
'; $output .= ''; } else { $output = ''; } print theme('install_page', $output); exit; } // One language, but not the default profile, assume // the user knows what he is doing. return FALSE; } else { // Allow profile to pre-select the language, skipping the selection. $function = $profilename .'_profile_details'; if (function_exists($function)) { $details = $function(); if (isset($details['language'])) { foreach ($locales as $locale) { if ($details['language'] == $locale->name) { return $locale->name; } } } } foreach ($locales as $locale) { if ($_POST['locale'] == $locale->name) { return $locale->name; } } install_task_list('locale-select'); drupal_set_title(st('Choose language')); print theme('install_page', drupal_get_form('install_select_locale_form', $locales)); exit; } } /** * Form API array definition for language selection. */ function install_select_locale_form(&$form_state, $locales) { include_once './includes/locale.inc'; $languages = _locale_get_predefined_list(); foreach ($locales as $locale) { // Try to use verbose locale name $name = $locale->name; if (isset($languages[$name])) { $name = $languages[$name][0] . (isset($languages[$name][1]) ? ' '. st('(@language)', array('@language' => $languages[$name][1])) : ''); } $form['locale'][$locale->name] = array( '#type' => 'radio', '#return_value' => $locale->name, '#default_value' => ($locale->name == 'en' ? TRUE : FALSE), '#title' => $name . ($locale->name == 'en' ? ' '. st('(built-in)') : ''), '#parents' => array('locale') ); } $form['submit'] = array( '#type' => 'submit', '#value' => st('Select language'), ); return $form; } /** * Show an error page when there are no profiles available. */ function install_no_profile_error() { install_task_list('profile-select'); drupal_set_title(st('No profiles available')); print theme('install_page', ''. st('We were unable to find any installer profiles. Installer profiles tell us what modules to enable and what schema to install in the database. A profile is necessary to continue with the installation process.') .'
'); exit; } /** * Show an error page when Drupal has already been installed. */ function install_already_done_error() { global $base_url; drupal_set_title(st('Drupal already installed')); print theme('install_page', st(''. st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) .'
'; $output .= ''. (isset($messages['error']) ? st('Please review the messages above before continuing on to your new site.', array('@url' => url(''))) : st('You may now visit your new site.', array('@url' => url('')))) .'
'; $task = 'done'; } // The end of the install process. Remember profile used. if ($task == 'done') { // Rebuild menu to get content type links registered by the profile, // and possibly any other menu items created through the tasks. menu_rebuild(); // Register actions declared by any modules. actions_synchronize(); variable_set('install_profile', $profile); } // Set task for user, and remember the task in the database. install_task_list($task); variable_set('install_task', $task); // Output page, if some output was required. Otherwise it is possible // that we are printing a JSON page and theme output should not be there. if (isset($output)) { print theme('maintenance_page', $output); } } /** * Batch callback for batch installation of modules. */ function _install_module_batch($module, $module_name, &$context) { _drupal_install_module($module); // We enable the installed module right away, so that the module will be // loaded by drupal_bootstrap in subsequent batch requests, and other // modules possibly depending on it can safely perform their installation // steps. module_enable(array($module)); $context['results'][] = $module; $context['message'] = 'Installed '. $module_name .' module.'; } /** * Finished callback for the modules install batch. * * Advance installer task to language import. */ function _install_profile_batch_finished($success, $results) { variable_set('install_task', 'locale-initial-import'); } /** * Finished callback for the first locale import batch. * * Advance installer task to the configure screen. */ function _install_locale_initial_batch_finished($success, $results) { variable_set('install_task', 'configure'); } /** * Finished callback for the second locale import batch. * * Advance installer task to the finished screen. */ function _install_locale_remaining_batch_finished($success, $results) { variable_set('install_task', 'finished'); } /** * The list of reserved tasks to run in the installer. */ function install_reserved_tasks() { return array('configure', 'profile-install', 'profile-install-batch', 'locale-initial-import', 'locale-initial-batch', 'profile-finished', 'locale-remaining-batch', 'finished', 'done'); } /** * Check installation requirements and report any errors. */ function install_check_requirements($profile, $verify) { $requirements = drupal_check_profile($profile); $severity = drupal_requirements_severity($requirements); // If there are issues, report them. if ($severity == REQUIREMENT_ERROR) { foreach ($requirements as $requirement) { if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) { $message = $requirement['description']; if (isset($requirement['value']) && $requirement['value']) { $message .= ' ('. st('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) .')'; } drupal_set_message($message, 'error'); } } } // If Drupal is not set up already, we also need to create a settings file. if (!$verify) { $writable = FALSE; $conf_path = './'. conf_path(); $settings_file = $conf_path .'/settings.php'; $file = $conf_path; // Verify that the directory exists. if (drupal_verify_install_file($conf_path, FILE_EXIST, 'dir')) { // Check to see if a settings.php already exists. if (drupal_verify_install_file($settings_file, FILE_EXIST)) { // If it does, make sure it is writable. $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE); $file = $settings_file; } else { // If not, make sure the directory is. $writable = drupal_verify_install_file($conf_path, FILE_READABLE|FILE_WRITABLE, 'dir'); } } if (!$writable) { drupal_set_message(st('The @drupal installer requires write permissions to %file during the installation process. If you are unsure how to grant file permissions, please consult the on-line handbook.', array('@drupal' => drupal_install_profile_name(), '%file' => $file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'error'); } } } /** * Add the installation task list to the current page. */ function install_task_list($active = NULL) { // Default list of tasks. $tasks = array( 'profile-select' => st('Choose profile'), 'locale-select' => st('Choose language'), 'requirements' => st('Verify requirements'), 'database' => st('Set up database'), 'profile-install-batch' => st('Install profile'), 'locale-initial-batch' => st('Set up translations'), 'configure' => st('Configure site'), ); $profiles = install_find_profiles(); $profile = isset($_GET['profile']) && isset($profiles[$_GET['profile']]) ? $_GET['profile'] : '.'; $locales = install_find_locales($profile); // If we have only one profile, remove 'Choose profile' // and rename 'Install profile'. if (count($profiles) == 1) { unset($tasks['profile-select']); $tasks['profile-install-batch'] = st('Install site'); } // Add tasks defined by the profile. if ($profile) { $function = $profile .'_profile_task_list'; if (function_exists($function)) { $result = $function(); if (is_array($result)) { $tasks += $result; } } } if (count($locales) < 2 || empty($_GET['locale']) || $_GET['locale'] == 'en') { // If not required, remove translation import from the task list. unset($tasks['locale-initial-batch']); } else { // If required, add remaining translations import task. $tasks += array('locale-remaining-batch' => st('Finish translations')); } // Add finished step as the last task. $tasks += array( 'finished' => st('Finished') ); // Let the theming function know that 'finished' and 'done' // include everything, so every step is completed. if (in_array($active, array('finished', 'done'))) { $active = NULL; } drupal_set_content('left', theme_task_list($tasks, $active)); } /** * Form API array definition for site configuration. */ function install_configure_form(&$form_state, $url) { $form['intro'] = array( '#value' => st('To configure your website, please provide the following information.'), '#weight' => -10, ); $form['site_information'] = array( '#type' => 'fieldset', '#title' => st('Site information'), '#collapsible' => FALSE, ); $form['site_information']['site_name'] = array( '#type' => 'textfield', '#title' => st('Site name'), '#required' => TRUE, '#weight' => -20, ); $form['site_information']['site_mail'] = array( '#type' => 'textfield', '#title' => st('Site e-mail address'), '#default_value' => ini_get('sendmail_from'), '#description' => st("The From address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)"), '#required' => TRUE, '#weight' => -15, ); $form['admin_account'] = array( '#type' => 'fieldset', '#title' => st('Administrator account'), '#collapsible' => FALSE, ); $form['admin_account']['account']['#tree'] = TRUE; $form['admin_account']['markup'] = array( '#value' => ''. st('The administrator account has complete access to the site; it will automatically be granted all permissions and can perform any administrative activity. This will be the only account that can perform certain activities, so keep its credentials safe.') .'
', '#weight' => -10, ); $form['admin_account']['account']['name'] = array('#type' => 'textfield', '#title' => st('Username'), '#maxlength' => USERNAME_MAX_LENGTH, '#description' => st('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), '#required' => TRUE, '#weight' => -10, ); $form['admin_account']['account']['mail'] = array('#type' => 'textfield', '#title' => st('E-mail address'), '#maxlength' => EMAIL_MAX_LENGTH, '#description' => st('All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), '#required' => TRUE, '#weight' => -5, ); $form['admin_account']['account']['pass'] = array( '#type' => 'password_confirm', '#required' => TRUE, '#size' => 25, '#weight' => 0, ); $form['server_settings'] = array( '#type' => 'fieldset', '#title' => st('Server settings'), '#collapsible' => FALSE, ); $form['server_settings']['date_default_timezone'] = array( '#type' => 'select', '#title' => st('Default time zone'), '#default_value' => 0, '#options' => _system_zonelist(), '#description' => st('By default, dates in this site will be displayed in the chosen time zone.'), '#weight' => 5, ); $form['server_settings']['clean_url'] = array( '#type' => 'radios', '#title' => st('Clean URLs'), '#default_value' => 0, '#options' => array(0 => st('Disabled'), 1 => st('Enabled')), '#description' => st('This option makes Drupal emit "clean" URLs (i.e. without?q= in the URL).'),
'#disabled' => TRUE,
'#prefix' => '