Bring the language chooser to setup-config.php.

see #28577.

Built from https://develop.svn.wordpress.org/trunk@29006


git-svn-id: http://core.svn.wordpress.org/trunk@28794 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-07-05 05:14:15 +00:00
parent cb49dd0109
commit 7a1351b411
3 changed files with 170 additions and 94 deletions

View File

@ -2158,3 +2158,108 @@ CREATE TABLE $wpdb->sitecategories (
dbDelta( $ms_queries );
}
endif;
function wp_install_language_form( $body ) {
echo "<fieldset>\n";
echo "<legend class='screen-reader-text'>Select a default language</legend>\n";
echo '<input type="radio" checked="checked" class="screen-reader-input" name="language" id="language_default" value="">';
echo '<label for="language_default">English (United States)</label>';
echo "\n";
if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) {
if ( isset( $body['languages'][WPLANG] ) ) {
$language = $body['languages'][WPLANG];
echo '<input type="radio" name="language" checked="checked" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_wplang" value="' . esc_attr( $language['language'] ) . '">';
echo '<label for="language_wplang">' . esc_html( $language['native_name'] ) . "</label>\n";
}
}
foreach ( $body['languages'] as $language ) {
echo '<input type="radio" name="language" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_'. esc_attr( $language['language'] ) .'" value="' . esc_attr( $language['language'] ) . '">';
echo '<label for="language_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n";
}
echo "</fieldset>\n";
echo '<p class="step"><input type="submit" class="button button-primary button-hero" value="&raquo;" /></p>';
}
/**
* @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;
}

View File

@ -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 ) {
</tr>
</table>
<p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Install WordPress' ); ?>" class="button button-large" /></p>
<input type="hidden" name="language" value="<?php echo isset( $_POST['language'] ) ? esc_attr( $_POST['language'] ) : ''; ?>" />
<input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" />
</form>
<?php
} // end display_setup_form()
@ -206,60 +178,22 @@ if ( ! is_string( $wpdb->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 '<form id="setup" method="post" action="install.php?step=1">';
echo "<fieldset>\n";
echo "<legend class='screen-reader-text'>Select a default language</legend>\n";
echo '<input type="radio" checked="checked" class="screen-reader-input" name="language" id="language_default" value="">';
echo '<label for="language_default">English (United States)</label>';
echo "\n";
if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) {
if ( isset( $body['languages'][WPLANG] ) ) {
$language = $body['languages'][WPLANG];
echo '<input type="radio" name="language" checked="checked" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_wplang" value="' . esc_attr( $language['language'] ) . '">';
echo '<label for="language_wplang">' . esc_html( $language['native_name'] ) . "</label>\n";
}
}
foreach ( $body['languages'] as $language ) {
echo '<input type="radio" name="language" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_'. esc_attr( $language['language'] ) .'" value="' . esc_attr( $language['language'] ) . '">';
echo '<label for="language_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n";
}
echo "</fieldset>\n";
echo '<p class="step"><input type="submit" class="button button-primary button-hero" value="&raquo;" /></p>';
echo '<form id="setup" method="post" action="?step=1">';
wp_install_language_form( $body );
echo '</form>';
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 );
?>
<h1><?php _e( 'Success!' ); ?></h1>

View File

@ -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( '<p>' . 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 <a href='install.php'>installing now</a>."), 'install.php' ) . '</p>' );
$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() {
<link rel="stylesheet" href="../<?php echo WPINC ?>/css/buttons.css?ver=<?php echo preg_replace( '/[^0-9a-z\.-]/i', '', $wp_version ); ?>" type="text/css" />
</head>
<body class="wp-core-ui<?php if ( is_rtl() ) echo ' rtl'; ?>">
<body class="<?php echo implode( ' ', $body_classes ); ?>">
<h1 id="logo"><a href="<?php esc_attr_e( 'https://wordpress.org/' ); ?>" tabindex="-1"><?php _e( 'WordPress' ); ?></a></h1>
<?php
} // end function setup_config_display_header();
switch($step) {
case -1:
if ( empty( $_GET['language'] ) && ( $body = wp_get_available_translations() ) ) {
setup_config_display_header( 'language-chooser' );
echo '<form id="setup" method="post" action="?step=0">';
wp_install_language_form( $body );
echo '</form>';
break;
}
// Deliberately fall through if we can't reach the translations API.
case 0:
if ( ! empty( $_REQUEST['language'] ) ) {
$loaded_language = wp_install_download_language_pack( $_REQUEST['language'] );
if ( $loaded_language ) {
wp_install_load_language( $loaded_language );
}
}
setup_config_display_header();
$step_1 = 'setup-config.php?step=1';
if ( isset( $_REQUEST['noapi'] ) ) {
$step_1 .= '&amp;noapi';
}
if ( ! empty( $loaded_language ) ) {
$step_1 .= '&amp;language=' . $loaded_language;
}
?>
<p><?php _e( 'Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.' ) ?></p>
@ -96,11 +129,12 @@ switch($step) {
</p>
<p><?php _e( "In all likelihood, these items were supplied to you by your Web Host. If you do not have this information, then you will need to contact them before you can continue. If you&#8217;re all ready&hellip;" ); ?></p>
<p class="step"><a href="setup-config.php?step=1<?php if ( isset( $_GET['noapi'] ) ) echo '&amp;noapi'; ?>" class="button button-large"><?php _e( 'Let&#8217;s go!' ); ?></a></p>
<p class="step"><a href="<?php echo $step_1; ?>" class="button button-large"><?php _e( 'Let&#8217;s go!' ); ?></a></p>
<?php
break;
case 1:
$loaded_language = wp_install_load_language( $_REQUEST['language'] );
setup_config_display_header();
?>
<form method="post" action="setup-config.php?step=2">
@ -133,19 +167,30 @@ switch($step) {
</tr>
</table>
<?php if ( isset( $_GET['noapi'] ) ) { ?><input name="noapi" type="hidden" value="1" /><?php } ?>
<input type="hidden" name="language" value="<?php echo esc_attr( $loaded_language ); ?>" />
<p class="step"><input name="submit" type="submit" value="<?php echo htmlspecialchars( __( 'Submit' ), ENT_QUOTES ); ?>" class="button button-large" /></p>
</form>
<?php
break;
case 2:
$loaded_language = wp_install_load_language( $_REQUEST['language'] );
$dbname = trim( wp_unslash( $_POST[ 'dbname' ] ) );
$uname = trim( wp_unslash( $_POST[ 'uname' ] ) );
$pwd = trim( wp_unslash( $_POST[ 'pwd' ] ) );
$dbhost = trim( wp_unslash( $_POST[ 'dbhost' ] ) );
$prefix = trim( wp_unslash( $_POST[ 'prefix' ] ) );
$tryagain_link = '</p><p class="step"><a href="setup-config.php?step=1" onclick="javascript:history.go(-1);return false;" class="button button-large">' . __( 'Try again' ) . '</a>';
$step_1 = 'setup-config.php?step=1';
$install = 'install.php';
if ( isset( $_REQUEST['noapi'] ) ) {
$step_1 .= '&amp;noapi';
}
if ( $loaded_language ) {
$step_1 .= '&amp;language=' . $loaded_language;
$install .= '?language=' . $loaded_language;
}
$tryagain_link = '</p><p class="step"><a href="' . $step_1 . '" onclick="javascript:history.go(-1);return false;" class="button button-large">' . __( 'Try again' ) . '</a>';
if ( empty( $prefix ) )
wp_die( __( '<strong>ERROR</strong>: "Table Prefix" must not be empty.' . $tryagain_link ) );
@ -239,7 +284,7 @@ switch($step) {
}
?></textarea>
<p><?php _e( 'After you&#8217;ve done that, click &#8220;Run the install.&#8221;' ); ?></p>
<p class="step"><a href="install.php" class="button button-large"><?php _e( 'Run the install' ); ?></a></p>
<p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the install' ); ?></a></p>
<script>
(function(){
var el=document.getElementById('wp-config');
@ -266,7 +311,7 @@ el.select();
?>
<p><?php _e( "All right, sparky! You&#8217;ve made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to&hellip;" ); ?></p>
<p class="step"><a href="install.php" class="button button-large"><?php _e( 'Run the install' ); ?></a></p>
<p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the install' ); ?></a></p>
<?php
endif;
break;