commit c78f6ea8c0d50ccba46599d4b945a8a2887fed8b Author: Erik Stielstra Date: Thu Dec 20 12:44:13 2012 +0100 #45 diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 49fdc29..b58ca7d 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -193,7 +193,7 @@ function install_state_defaults() { // $_SERVER array via drupal_override_server_variables(). Used by // non-interactive installations only. 'server' => array(), - // The server URL where the interface translations files can be downloaded. + // The server URL where the interface translation files can be downloaded. // Tokens in the pattern will be replaced by appropriate values for the // required translation file. 'server_pattern' => 'http://ftp.drupal.org/files/translations/%core/%project/%project-%version.%language.po', @@ -1256,7 +1256,7 @@ function install_select_profile_form($form, &$form_state, $install_state) { * Finds all .po files that are useful to the installer. * * @return - * An associative array of file uris keyed by language code. Uris as + * An associative array of file URIs keyed by language code. URIs as * returned by file_scan_directory(). * * @see file_scan_directory() @@ -1271,7 +1271,7 @@ function install_find_translations() { $langcode = preg_replace('!^(.+\.)?([^\.]+)$!', '\2', $file->name); // Language codes cannot exceed 12 characters to fit into the {language} // table. - if ($langcode <= 12) { + if (strlen($langcode) <= 12) { $translations[$langcode] = $uri; } } @@ -1315,7 +1315,7 @@ function install_find_translation_files($langcode = NULL) { function install_select_language(&$install_state) { include_once DRUPAL_ROOT . '/core/includes/standard.inc'; - // Find all available translations files. + // Find all available translation files. $files = install_find_translations(); $install_state['translations'] += $files; @@ -1346,9 +1346,9 @@ function install_select_language(&$install_state) { $elements = drupal_get_form('install_select_language_form', count($files) > 1 ? $files : array()); return drupal_render($elements); } - // If we are performing a none interactive installation. If only one - // language (English) is available, assume the user knows what he is doing. - // Otherwise thow an error. + // If we are performing a non-interactive installation. If only one language + // (English) is available, assume the user knows what he is doing. Otherwise + // thow an error. else { if (count($files) == 1) { $install_state['parameters']['langcode'] = array_shift(array_keys($files)); @@ -1365,54 +1365,44 @@ function install_select_language(&$install_state) { * Form constructor for the language selection form. * * @param array $files - * (option) An associative array of file information objects keyed by file URIs as + * (optional) An associative array of file URIs keyed by language code as * returned by file_scan_directory(). Defaults to all standard languages. * * @see file_scan_directory() * @ingroup forms */ -function install_select_language_form($form, &$form_state, $files = array(), $message = '') { +function install_select_language_form($form, &$form_state, $files = array()) { include_once DRUPAL_ROOT . '/core/includes/standard.inc'; include_once DRUPAL_ROOT . '/core/modules/language/language.module'; include_once DRUPAL_ROOT . '/core/modules/language/language.negotiation.inc'; $standard_languages = standard_language_list(); $select_options = array(); - $languages = array(); + $browser_options = array(); + // Build a select list with language names in native language for the user + // to choose from. And build a list of available languages for the browser + // to select the language default from. if (count($files)) { + // Select lists based on available language files. foreach ($files as $langcode => $uri) { - if (isset($standard_languages[$langcode])) { - // Build a list of select list options based on files we found. - $select_options[$langcode] = $standard_languages[$langcode][1]; - } - else { - // If the language was not found in standard.inc, display its langcode. - $select_options[$langcode] = $langcode; - } - // Build a list of languages simulated for browser detection. - $languages[$langcode] = new Language(array( + $select_options[$langcode] = isset($standard_languages[$langcode]) ? $standard_languages[$langcode][1] : $langcode; + $browser_options[$langcode] = new Language(array( 'langcode' => $langcode, )); } } else { - foreach ($standard_languages as $langcode => $language_names) - // Build a select list with available languages. - $select_options[$langcode] = $language_names[1]; - // Build a list of languages required for browser detection. - $languages[$langcode] = new Language(array( - 'langcode' => $langcode, - )); - } - - if ($message) { - $form['message'] = array( - '#markup' => '

' . $message . '

', - ); + // Select lists based on all standard languages. + foreach ($standard_languages as $langcode => $language_names) { + $select_options[$langcode] = $language_names[1]; + $browser_options[$langcode] = new Language(array( + 'langcode' => $langcode, + )); + } } - $browser_langcode = language_from_browser($languages); + $browser_langcode = language_from_browser($browser_options); $form['langcode'] = array( '#type' => 'select', '#options' => $select_options, @@ -1437,15 +1427,12 @@ function install_select_language_form($form, &$form_state, $files = array(), $me /** * Download a translation file for the selected langaguage. * - * @param $install_state + * @param array $install_state * An array of information about the current installation state. * - * @return + * @return string * A themed status report, or an exception if there are requirement errors. - * If there are only requirement warnings, a themed status report is shown - * initially, but the user is allowed to bypass it by providing 'continue=1' - * in the URL. Otherwise, no output is returned, so that the next task can be - * run in the same page request. + * Upon successfull download the page is reloaded and no output is returned. */ function install_download_translation(&$install_state) { // Check whether all conditions are met to download. Download the translation @@ -1462,8 +1449,8 @@ function install_download_translation(&$install_state) { /** * Attempts to get a file using drupal_http_request and to store it locally. * - * @param string $url - * The URL of the file to grab. + * @param string $uri + * The URI of the file to grab. * @param string $destination * Stream wrapper URI specifying where the file should be placed. If a * directory path is provided, the file is saved into that directory under its @@ -1473,16 +1460,16 @@ function install_download_translation(&$install_state) { * @return boolean * TRUE on success, FALSE on failure. */ -function install_retrieve_file($url, $destination) { - $parsed_url = parse_url($url); +function install_retrieve_file($uri, $destination) { + $parsed_url = parse_url($uri); if (is_dir(drupal_realpath($destination))) { - // Prevent URIs with triple slashes when glueing parts together. + // Prevent URIs with triple slashes when gluing parts together. $path = str_replace('///', '//', "$destination/") . drupal_basename($parsed_url['path']); } else { $path = $destination; } - $result = drupal_http_request($url); + $result = drupal_http_request($uri); if ($result->code != 200) { return FALSE; } @@ -1495,15 +1482,15 @@ function install_retrieve_file($url, $destination) { /** * Checks if the localization server can be contacted. * - * @param string $url - * The URL to contact. + * @param string $uri + * The URI to contact. * * @return string - * URL of the server if the localization server was contacted successfully. + * URI of the server if the localization server was contacted successfully. * FALSE if not. */ -function install_check_localization_server($url) { - $result = drupal_http_request($url, array('method' => 'HEAD')); +function install_check_localization_server($uri) { + $result = drupal_http_request($uri, array('method' => 'HEAD')); return (!isset($result->error) && $result->code == 200); } @@ -1523,8 +1510,8 @@ function install_get_localization_release() { list($version, ) = explode('-', VERSION); list($major, $minor) = explode('.', $version); - // Calculate the major and minor release numbers to fall back to. - // e.g. 8.0-dev falls back to 7.0 and 8.2-dev falls back to 8.1. + // Calculate the major and minor release numbers to fall back to. + // E.g. 8.0-dev falls back to 7.0 and 8.2-dev falls back to 8.1. if ($minor == 0) { $major--; } @@ -1681,7 +1668,7 @@ function install_import_translations(&$install_state) { language_save($language); } - // If a non-english language was selected, remove English and import the + // If a non-English language was selected, remove English and import the // translations. if ($langcode != 'en') { language_delete('en'); @@ -1696,7 +1683,7 @@ function install_import_translations(&$install_state) { } /** - * Tells the translation import process that drupal core is installed. + * Tells the translation import process that Drupal core is installed. */ function _install_prepare_import() { global $install_state; @@ -1872,15 +1859,14 @@ function install_check_translations($install_state) { file_prepare_directory($translations_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); // Get values so the requirements errors can be specific. - if (drupal_verify_install_file($translations_directory, FILE_EXIST, 'dir')) { + if (drupal_verify_install_file($translations_directory, FILE_EXIST|FILE_WRITABLE, 'dir')) { $readable = is_readable($translations_directory); $writable = is_writable($translations_directory); $executable = is_executable($translations_directory); $translations_directory_exists = TRUE; } - // Build the URL where the translation file and translation server can be - // downloaded from. + // Build URLs for the translation file and the translation server. $release = install_get_localization_release(); $langcode = $install_state['parameters']['langcode']; $variables = array( @@ -1892,6 +1878,8 @@ function install_check_translations($install_state) { $translation_url = strtr($install_state['server_pattern'], $variables); $elements = parse_url($translation_url); $server_url = $elements['scheme'] . '://' . $elements['host']; + + // Build the language name for display. $languages = standard_language_list(); $language = isset($languages[$langcode]) ? $languages[$langcode][0] : $langcode; @@ -2156,6 +2144,8 @@ function install_check_requirements($install_state) { * initially, but the user is allowed to bypass it by providing 'continue=1' * in the URL. Otherwise, no output is returned, so that the next task can be * run in the same page request. + * + * @thows \Exception */ function install_display_requirements($install_state, $requirements) { // Check the severity of the requirements reported. @@ -2183,7 +2173,7 @@ function install_display_requirements($install_state, $requirements) { } } if (!empty($failures)) { - throw new Exception(implode("\n\n", $failures)); + throw new \Exception(implode("\n\n", $failures)); } } }