diff --git a/src/wp-admin/includes/upgrade.php b/src/wp-admin/includes/upgrade.php index 9e9441e084..6e4fd801fa 100644 --- a/src/wp-admin/includes/upgrade.php +++ b/src/wp-admin/includes/upgrade.php @@ -2158,3 +2158,108 @@ CREATE TABLE $wpdb->sitecategories ( dbDelta( $ms_queries ); } endif; + +function wp_install_language_form( $body ) { + echo "
\n"; + echo ''; +} + +/** + * @todo rename, move + */ +function wp_get_available_translations() { + $url = 'http://api.wordpress.org/translations/core/1.0/'; + if ( wp_http_supports( array( 'ssl' ) ) ) { + $url = set_url_scheme( $url, 'https' ); + } + + $options = array( + 'timeout' => 3, + 'body' => array( 'version' => $GLOBALS['wp_version'] ), + ); + + $response = wp_remote_post( $url, $options ); + $body = wp_remote_retrieve_body( $response ); + if ( $body && $body = json_decode( $body, true ) ) { + $languages = array(); + // Key the language array with the language code + foreach ( $body['languages'] as $language ) { + $languages[$language['language']] = $language; + } + $body['languages'] = $languages; + return $body; + } + return false; +} + +function wp_install_download_language_pack( $language ) { + // Check if the language is already installed. + $available_languages = get_available_languages(); + if ( in_array( $language->language, $available_languages ) ) { + return $language->language; + } + + // Confirm the language is one we can download. + $body = wp_get_available_translations(); + $loading_language = false; + if ( $body ) { + foreach ( $body['languages'] as $language ) { + if ( $language['language'] === $_REQUEST['language'] ) { + $loading_language = $_REQUEST['language']; + break; + } + } + } + + if ( ! $loading_language ) { + return false; + } + $language = (object) $language; + + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; + $skin = new Automatic_Upgrader_Skin; + $upgrader = new Language_Pack_Upgrader( $skin ); + $options = array( 'clear_update_cache' => false ); + $language->type = 'core'; + /** + * @todo failures (such as non-direct FS) + */ + $upgrader->upgrade( $language, array( 'clear_update_cache' => false ) ); + return $language->language; +} + +function wp_install_load_language( $request ) { + $loading_language = ''; + if ( ! empty( $request ) ) { + $available_languages = get_available_languages(); + if ( in_array( $request, $available_languages ) ) { + $loading_language = $request; + } + } + + if ( $loading_language ) { + load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" ); + load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" ); + return $loading_language; + } + + return false; +} diff --git a/src/wp-admin/install.php b/src/wp-admin/install.php index a78c7220b7..a2cc028495 100644 --- a/src/wp-admin/install.php +++ b/src/wp-admin/install.php @@ -43,34 +43,6 @@ require_once( ABSPATH . WPINC . '/wp-db.php' ); $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0; -/** - * @todo rename, move - */ -function wp_get_available_translations() { - $url = 'http://api.wordpress.org/translations/core/1.0/'; - if ( wp_http_supports( array( 'ssl' ) ) ) { - $url = set_url_scheme( $url, 'https' ); - } - - $options = array( - 'timeout' => 3, - 'body' => array( 'version' => $GLOBALS['wp_version'] ), - ); - - $response = wp_remote_post( $url, $options ); - $body = wp_remote_retrieve_body( $response ); - if ( $body && $body = json_decode( $body, true ) ) { - $languages = array(); - // Key the language array with the language code - foreach ( $body['languages'] as $language ) { - $languages[$language['language']] = $language; - } - $body['languages'] = $languages; - return $body; - } - return false; -} - /** * Display install header. * @@ -171,7 +143,7 @@ function display_setup_form( $error = null ) { - + base_prefix ) || '' === $wpdb->base_prefix ) { switch($step) { case 0: // Step 0 - $body = wp_get_available_translations(); - if ( $body ) { + + if ( empty( $_GET['language'] ) && ( $body = wp_get_available_translations() ) ) { display_header( 'language-chooser' ); - echo ''; break; } + // Deliberately fall through if we can't reach the translations API. case 1: // Step 1, direct link or from language chooser. - if ( ! empty( $_POST['language'] ) ) { - $body = wp_get_available_translations(); - $loading_language = false; - if ( $body ) { - foreach ( $body['languages'] as $language ) { - if ( $language['language'] === $_POST['language'] ) { - $loading_language = $_POST['language']; - break; - } - } - } - if ( ! empty( $loading_language ) ) { - require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; - $skin = new Automatic_Upgrader_Skin; - $upgrader = new Language_Pack_Upgrader( $skin ); - $options = array( 'clear_update_cache' => false ); - $language['type'] = 'core'; - $language = (object) $language; - /** - * @todo failures (such as non-direct FS) - */ - $upgrader->upgrade( $language, array( 'clear_update_cache' => false ) ); - load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" ); - load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" ); + if ( ! empty( $_REQUEST['language'] ) ) { + $loaded_language = wp_install_download_language_pack( $_REQUEST['language'] ); + if ( $loaded_language ) { + wp_install_load_language( $loaded_language ); } } @@ -275,15 +209,7 @@ switch($step) { display_setup_form(); break; case 2: - $loading_language = ''; - if ( ! empty( $_POST['language'] ) ) { - $available_languages = get_available_languages(); - if ( in_array( $_POST['language'], $available_languages ) ) { - $loading_language = $_POST['language']; - load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" ); - load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" ); - } - } + $loaded_language = wp_install_load_language( $_REQUEST['language'] ); if ( ! empty( $wpdb->error ) ) wp_die( $wpdb->error->get_error_message() ); @@ -321,7 +247,7 @@ switch($step) { if ( $error === false ) { $wpdb->show_errors(); - $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loading_language ); + $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language ); ?> diff --git a/src/wp-admin/setup-config.php b/src/wp-admin/setup-config.php index 5e938d57db..199078a22b 100644 --- a/src/wp-admin/setup-config.php +++ b/src/wp-admin/setup-config.php @@ -26,12 +26,14 @@ define('WP_SETUP_CONFIG', true); * * Set this to error_reporting( -1 ) for debugging */ -error_reporting(-1); +error_reporting(0); define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' ); require( ABSPATH . 'wp-settings.php' ); +require( ABSPATH . 'wp-admin/includes/upgrade.php' ); + // Support wp-config-sample.php one level up, for the develop repo. if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) $config_file = file( ABSPATH . 'wp-config-sample.php' ); @@ -48,7 +50,7 @@ if ( file_exists( ABSPATH . 'wp-config.php' ) ) if ( file_exists(ABSPATH . '../wp-config.php' ) && ! file_exists( ABSPATH . '../wp-settings.php' ) ) wp_die( '' . sprintf( __( "The file 'wp-config.php' already exists one level above your WordPress installation. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now."), 'install.php' ) . '
' ); -$step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0; +$step = isset( $_GET['step'] ) ? (int) $_GET['step'] : -1; /** * Display setup wp-config.php file header. @@ -56,8 +58,13 @@ $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0; * @ignore * @since 2.3.0 */ -function setup_config_display_header() { +function setup_config_display_header( $body_classes = array() ) { global $wp_version; + $body_classes = (array) $body_classes; + $body_classes[] = 'wp-core-ui'; + if ( is_rtl() ) { + $body_classes[] = 'rtl'; + } header( 'Content-Type: text/html; charset=utf-8' ); ?> @@ -71,14 +78,40 @@ function setup_config_display_header() { - +' . __( 'Try again' ) . ''; + $step_1 = 'setup-config.php?step=1'; + $install = 'install.php'; + if ( isset( $_REQUEST['noapi'] ) ) { + $step_1 .= '&noapi'; + } + if ( $loaded_language ) { + $step_1 .= '&language=' . $loaded_language; + $install .= '?language=' . $loaded_language; + } + $tryagain_link = '
' . __( 'Try again' ) . ''; if ( empty( $prefix ) ) wp_die( __( 'ERROR: "Table Prefix" must not be empty.' . $tryagain_link ) ); @@ -239,7 +284,7 @@ switch($step) { } ?>
- +