WordPress.org

Make WordPress Core

Changeset 29006


Ignore:
Timestamp:
07/05/14 05:13:05 (3 years ago)
Author:
nacin
Message:

Bring the language chooser to setup-config.php.

see #28577.

Location:
trunk/src/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/upgrade.php

    r28774 r29006  
    21592159} 
    21602160endif; 
     2161 
     2162function wp_install_language_form( $body ) { 
     2163    echo "<fieldset>\n"; 
     2164    echo "<legend class='screen-reader-text'>Select a default language</legend>\n"; 
     2165    echo '<input type="radio" checked="checked" class="screen-reader-input" name="language" id="language_default" value="">'; 
     2166    echo '<label for="language_default">English (United States)</label>'; 
     2167    echo "\n"; 
     2168 
     2169    if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) { 
     2170        if ( isset( $body['languages'][WPLANG] ) ) { 
     2171            $language = $body['languages'][WPLANG]; 
     2172            echo '<input type="radio" name="language" checked="checked" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_wplang" value="' . esc_attr( $language['language'] ) . '">'; 
     2173            echo '<label for="language_wplang">' . esc_html( $language['native_name'] ) . "</label>\n"; 
     2174        } 
     2175    } 
     2176 
     2177    foreach ( $body['languages'] as $language ) { 
     2178        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'] ) . '">'; 
     2179        echo '<label for="language_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n"; 
     2180    } 
     2181    echo "</fieldset>\n"; 
     2182    echo '<p class="step"><input type="submit" class="button button-primary button-hero" value="&raquo;" /></p>'; 
     2183} 
     2184 
     2185/** 
     2186 * @todo rename, move 
     2187 */ 
     2188function wp_get_available_translations() { 
     2189    $url = 'http://api.wordpress.org/translations/core/1.0/'; 
     2190    if ( wp_http_supports( array( 'ssl' ) ) ) { 
     2191        $url = set_url_scheme( $url, 'https' ); 
     2192    } 
     2193 
     2194    $options = array( 
     2195        'timeout' => 3, 
     2196        'body' => array( 'version' => $GLOBALS['wp_version'] ), 
     2197    ); 
     2198 
     2199    $response = wp_remote_post( $url, $options ); 
     2200    $body = wp_remote_retrieve_body( $response ); 
     2201    if ( $body && $body = json_decode( $body, true ) ) { 
     2202        $languages = array(); 
     2203        // Key the language array with the language code 
     2204        foreach ( $body['languages'] as $language ) { 
     2205            $languages[$language['language']] = $language; 
     2206        } 
     2207        $body['languages'] = $languages; 
     2208        return $body; 
     2209    } 
     2210    return false; 
     2211} 
     2212 
     2213function wp_install_download_language_pack( $language ) { 
     2214    // Check if the language is already installed. 
     2215    $available_languages = get_available_languages(); 
     2216    if ( in_array( $language->language, $available_languages ) ) { 
     2217        return $language->language; 
     2218    } 
     2219 
     2220    // Confirm the language is one we can download. 
     2221    $body = wp_get_available_translations(); 
     2222    $loading_language = false; 
     2223    if ( $body ) { 
     2224        foreach ( $body['languages'] as $language ) { 
     2225            if ( $language['language'] === $_REQUEST['language'] ) { 
     2226                $loading_language = $_REQUEST['language']; 
     2227                break; 
     2228            } 
     2229        } 
     2230    } 
     2231 
     2232    if ( ! $loading_language ) { 
     2233        return false; 
     2234    } 
     2235    $language = (object) $language; 
     2236 
     2237    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 
     2238    $skin = new Automatic_Upgrader_Skin; 
     2239    $upgrader = new Language_Pack_Upgrader( $skin ); 
     2240    $options = array( 'clear_update_cache' => false ); 
     2241    $language->type = 'core'; 
     2242    /** 
     2243     * @todo failures (such as non-direct FS) 
     2244     */ 
     2245    $upgrader->upgrade( $language, array( 'clear_update_cache' => false ) ); 
     2246    return $language->language; 
     2247} 
     2248 
     2249function wp_install_load_language( $request ) { 
     2250    $loading_language = ''; 
     2251    if ( ! empty( $request ) ) { 
     2252        $available_languages = get_available_languages(); 
     2253        if ( in_array( $request, $available_languages ) ) { 
     2254            $loading_language = $request; 
     2255        } 
     2256    } 
     2257 
     2258    if ( $loading_language ) { 
     2259        load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" ); 
     2260        load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" ); 
     2261        return $loading_language; 
     2262    } 
     2263 
     2264    return false; 
     2265} 
  • trunk/src/wp-admin/install.php

    r28984 r29006  
    4545 
    4646/** 
    47  * @todo rename, move 
    48  */ 
    49 function wp_get_available_translations() { 
    50     $url = 'http://api.wordpress.org/translations/core/1.0/'; 
    51     if ( wp_http_supports( array( 'ssl' ) ) ) { 
    52         $url = set_url_scheme( $url, 'https' ); 
    53     } 
    54  
    55     $options = array( 
    56         'timeout' => 3, 
    57         'body' => array( 'version' => $GLOBALS['wp_version'] ), 
    58     ); 
    59  
    60     $response = wp_remote_post( $url, $options ); 
    61     $body = wp_remote_retrieve_body( $response ); 
    62     if ( $body && $body = json_decode( $body, true ) ) { 
    63         $languages = array(); 
    64         // Key the language array with the language code 
    65         foreach ( $body['languages'] as $language ) { 
    66             $languages[$language['language']] = $language; 
    67         } 
    68         $body['languages'] = $languages; 
    69         return $body; 
    70     } 
    71     return false; 
    72 } 
    73  
    74 /** 
    7547 * Display install header. 
    7648 * 
     
    172144    </table> 
    173145    <p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Install WordPress' ); ?>" class="button button-large" /></p> 
    174     <input type="hidden" name="language" value="<?php echo isset( $_POST['language'] ) ? esc_attr( $_POST['language'] ) : ''; ?>" /> 
     146    <input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" /> 
    175147</form> 
    176148<?php 
     
    207179switch($step) { 
    208180    case 0: // Step 0 
    209         $body = wp_get_available_translations(); 
    210         if ( $body ) { 
     181 
     182        if ( empty( $_GET['language'] ) && ( $body = wp_get_available_translations() ) ) { 
    211183            display_header( 'language-chooser' ); 
    212             echo '<form id="setup" method="post" action="install.php?step=1">'; 
    213             echo "<fieldset>\n"; 
    214             echo "<legend class='screen-reader-text'>Select a default language</legend>\n"; 
    215             echo '<input type="radio" checked="checked" class="screen-reader-input" name="language" id="language_default" value="">'; 
    216             echo '<label for="language_default">English (United States)</label>'; 
    217             echo "\n"; 
    218  
    219             if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) { 
    220                 if ( isset( $body['languages'][WPLANG] ) ) { 
    221                     $language = $body['languages'][WPLANG]; 
    222                     echo '<input type="radio" name="language" checked="checked" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_wplang" value="' . esc_attr( $language['language'] ) . '">'; 
    223                     echo '<label for="language_wplang">' . esc_html( $language['native_name'] ) . "</label>\n"; 
    224                 } 
    225             } 
    226  
    227             foreach ( $body['languages'] as $language ) { 
    228                 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'] ) . '">'; 
    229                 echo '<label for="language_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n"; 
    230             } 
    231             echo "</fieldset>\n"; 
    232             echo '<p class="step"><input type="submit" class="button button-primary button-hero" value="&raquo;" /></p>'; 
     184            echo '<form id="setup" method="post" action="?step=1">'; 
     185            wp_install_language_form( $body ); 
    233186            echo '</form>'; 
    234187            break; 
    235188        } 
     189 
    236190        // Deliberately fall through if we can't reach the translations API. 
    237191 
    238192    case 1: // Step 1, direct link or from language chooser. 
    239         if ( ! empty( $_POST['language'] ) ) { 
    240             $body = wp_get_available_translations(); 
    241             $loading_language = false; 
    242             if ( $body ) { 
    243                 foreach ( $body['languages'] as $language ) { 
    244                     if ( $language['language'] === $_POST['language'] ) { 
    245                         $loading_language = $_POST['language']; 
    246                         break; 
    247                     } 
    248                 } 
    249             } 
    250             if ( ! empty( $loading_language ) ) { 
    251                 require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 
    252                 $skin = new Automatic_Upgrader_Skin; 
    253                 $upgrader = new Language_Pack_Upgrader( $skin ); 
    254                 $options = array( 'clear_update_cache' => false ); 
    255                 $language['type'] = 'core'; 
    256                 $language = (object) $language; 
    257                 /** 
    258                  * @todo failures (such as non-direct FS) 
    259                  */ 
    260                 $upgrader->upgrade( $language, array( 'clear_update_cache' => false ) ); 
    261                 load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" ); 
    262                 load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" ); 
     193        if ( ! empty( $_REQUEST['language'] ) ) { 
     194            $loaded_language = wp_install_download_language_pack( $_REQUEST['language'] ); 
     195            if ( $loaded_language ) { 
     196                wp_install_load_language( $loaded_language ); 
    263197            } 
    264198        } 
     
    276210        break; 
    277211    case 2: 
    278         $loading_language = ''; 
    279         if ( ! empty( $_POST['language'] ) ) { 
    280             $available_languages = get_available_languages(); 
    281             if ( in_array( $_POST['language'], $available_languages ) ) { 
    282                 $loading_language = $_POST['language']; 
    283                 load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" ); 
    284                 load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" ); 
    285             } 
    286         } 
     212        $loaded_language = wp_install_load_language( $_REQUEST['language'] ); 
    287213 
    288214        if ( ! empty( $wpdb->error ) ) 
     
    322248        if ( $error === false ) { 
    323249            $wpdb->show_errors(); 
    324             $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loading_language ); 
     250            $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language ); 
    325251?> 
    326252 
  • trunk/src/wp-admin/setup-config.php

    r29005 r29006  
    2727 * Set this to error_reporting( -1 ) for debugging 
    2828 */ 
    29 error_reporting(-1); 
     29error_reporting(0); 
    3030 
    3131define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' ); 
    3232 
    3333require( ABSPATH . 'wp-settings.php' ); 
     34 
     35require( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
    3436 
    3537// Support wp-config-sample.php one level up, for the develop repo. 
     
    4951    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>' ); 
    5052 
    51 $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0; 
     53$step = isset( $_GET['step'] ) ? (int) $_GET['step'] : -1; 
    5254 
    5355/** 
     
    5759 * @since 2.3.0 
    5860 */ 
    59 function setup_config_display_header() { 
     61function setup_config_display_header( $body_classes = array() ) { 
    6062    global $wp_version; 
     63    $body_classes = (array) $body_classes; 
     64    $body_classes[] = 'wp-core-ui'; 
     65    if ( is_rtl() ) { 
     66        $body_classes[] = 'rtl'; 
     67    } 
    6168 
    6269    header( 'Content-Type: text/html; charset=utf-8' ); 
     
    7279 
    7380</head> 
    74 <body class="wp-core-ui<?php if ( is_rtl() ) echo ' rtl'; ?>"> 
     81<body class="<?php echo implode( ' ', $body_classes ); ?>"> 
    7582<h1 id="logo"><a href="<?php esc_attr_e( 'https://wordpress.org/' ); ?>" tabindex="-1"><?php _e( 'WordPress' ); ?></a></h1> 
    7683<?php 
     
    7885 
    7986switch($step) { 
     87    case -1: 
     88 
     89        if ( empty( $_GET['language'] ) && ( $body = wp_get_available_translations() ) ) { 
     90            setup_config_display_header( 'language-chooser' ); 
     91            echo '<form id="setup" method="post" action="?step=0">'; 
     92            wp_install_language_form( $body ); 
     93            echo '</form>'; 
     94            break; 
     95        } 
     96 
     97        // Deliberately fall through if we can't reach the translations API. 
     98 
    8099    case 0: 
     100        if ( ! empty( $_REQUEST['language'] ) ) { 
     101            $loaded_language = wp_install_download_language_pack( $_REQUEST['language'] ); 
     102            if ( $loaded_language ) { 
     103                wp_install_load_language( $loaded_language ); 
     104            } 
     105        } 
     106 
    81107        setup_config_display_header(); 
     108        $step_1 = 'setup-config.php?step=1'; 
     109        if ( isset( $_REQUEST['noapi'] ) ) { 
     110            $step_1 .= '&amp;noapi'; 
     111        } 
     112        if ( ! empty( $loaded_language ) ) { 
     113            $step_1 .= '&amp;language=' . $loaded_language; 
     114        } 
    82115?> 
    83116 
     
    97130<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> 
    98131 
    99 <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> 
     132<p class="step"><a href="<?php echo $step_1; ?>" class="button button-large"><?php _e( 'Let&#8217;s go!' ); ?></a></p> 
    100133<?php 
    101134    break; 
    102135 
    103136    case 1: 
     137        $loaded_language = wp_install_load_language( $_REQUEST['language'] ); 
    104138        setup_config_display_header(); 
    105139    ?> 
     
    134168    </table> 
    135169    <?php if ( isset( $_GET['noapi'] ) ) { ?><input name="noapi" type="hidden" value="1" /><?php } ?> 
     170    <input type="hidden" name="language" value="<?php echo esc_attr( $loaded_language ); ?>" /> 
    136171    <p class="step"><input name="submit" type="submit" value="<?php echo htmlspecialchars( __( 'Submit' ), ENT_QUOTES ); ?>" class="button button-large" /></p> 
    137172</form> 
     
    140175 
    141176    case 2: 
     177    $loaded_language = wp_install_load_language( $_REQUEST['language'] ); 
    142178    $dbname = trim( wp_unslash( $_POST[ 'dbname' ] ) ); 
    143179    $uname = trim( wp_unslash( $_POST[ 'uname' ] ) ); 
     
    146182    $prefix = trim( wp_unslash( $_POST[ 'prefix' ] ) ); 
    147183 
    148     $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>'; 
     184    $step_1 = 'setup-config.php?step=1'; 
     185    $install = 'install.php'; 
     186    if ( isset( $_REQUEST['noapi'] ) ) { 
     187        $step_1 .= '&amp;noapi'; 
     188    } 
     189    if ( $loaded_language ) { 
     190        $step_1 .= '&amp;language=' . $loaded_language; 
     191        $install .= '?language=' . $loaded_language; 
     192    } 
     193    $tryagain_link = '</p><p class="step"><a href="' . $step_1 . '" onclick="javascript:history.go(-1);return false;" class="button button-large">' . __( 'Try again' ) . '</a>'; 
    149194 
    150195    if ( empty( $prefix ) ) 
     
    240285?></textarea> 
    241286<p><?php _e( 'After you&#8217;ve done that, click &#8220;Run the install.&#8221;' ); ?></p> 
    242 <p class="step"><a href="install.php" class="button button-large"><?php _e( 'Run the install' ); ?></a></p> 
     287<p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the install' ); ?></a></p> 
    243288<script> 
    244289(function(){ 
     
    267312<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> 
    268313 
    269 <p class="step"><a href="install.php" class="button button-large"><?php _e( 'Run the install' ); ?></a></p> 
     314<p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the install' ); ?></a></p> 
    270315<?php 
    271316    endif; 
Note: See TracChangeset for help on using the changeset viewer.