Make WordPress Core

Ticket #15677: 15677.15.patch

File 15677.15.patch, 29.9 KB (added by ocean90, 9 years ago)
  • src/wp-admin/includes/translation-install.php

     
     1<?php
     2/**
     3 * WordPress Translation Install Administration API
     4 *
     5 * @package WordPress
     6 * @subpackage Administration
     7 */
     8
     9
     10/**
     11 * Retrieve translations from WordPress Translation API.
     12 *
     13 * @since 4.0.0
     14 *
     15 * @param string       $type Type of translations. Accepts 'plugins', 'themes', 'core'.
     16 * @param array|object $args Translation API arguments. Optional.
     17 * @return object|WP_Error On success an object of translations, WP_Error on failure.
     18 */
     19function translations_api( $type, $args = null ) {
     20        include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
     21
     22        if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ) ) ) {
     23                return  new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) );
     24        }
     25
     26        /**
     27         * Allows a plugin to override the WordPress.org Translation Install API entirely.
     28         *
     29         * @since 4.0.0
     30         *
     31         * @param bool|array  $result The result object. Default false.
     32         * @param string      $type   The type of translations being requested.
     33         * @param object      $args   Translation API arguments.
     34         */
     35        $res = apply_filters( 'translations_api', false, $type, $args );
     36
     37        if ( false === $res ) {
     38                $url = $http_url = 'http://api.wordpress.org/translations/' . $type . '/1.0/';
     39                if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
     40                        $url = set_url_scheme( $url, 'https' );
     41                }
     42
     43                $options = array(
     44                        'timeout' => 3,
     45                        'body' => array(
     46                                'wp_version' => $wp_version,
     47                                'locale'     => get_locale(),
     48                                'version'    => $args['version'], // Version of plugin, theme or core
     49                        ),
     50                );
     51
     52                if ( 'core' !== $type ) {
     53                        $options['body']['slug'] = $args['slug']; // Plugin or theme slug
     54                }
     55
     56                $request = wp_remote_post( $url, $options );
     57
     58                if ( $ssl && is_wp_error( $request ) ) {
     59                        trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE );
     60
     61                        $request = wp_remote_post( $http_url, $options );
     62                }
     63
     64                if ( is_wp_error( $request ) ) {
     65                        $res = new WP_Error( 'translations_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() );
     66                } else {
     67                        $res = json_decode( wp_remote_retrieve_body( $request ), true );
     68                        if ( ! is_object( $res ) && ! is_array( $res ) ) {
     69                                $res = new WP_Error( 'translations_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) );
     70                        }
     71                }
     72        }
     73
     74        /**
     75         * Filter the Translation Install API response results.
     76         *
     77         * @since 4.0.0
     78         *
     79         * @param object|WP_Error $res  Response object or WP_Error.
     80         * @param string          $type The type of translations being requested.
     81         * @param object          $args Translation API arguments.
     82         */
     83        return apply_filters( 'translations_api_result', $res, $type, $args );
     84}
     85
     86/**
     87 * Get available translations from the WordPress.org API.
     88 *
     89 * @since 4.0.0
     90 *
     91 * @see translations_api()
     92 *
     93 * @return array Array of translations, each an array of data. If the API response results
     94 *               in an error, an empty array will be returned.
     95 */
     96function wp_get_available_translations() {
     97        if ( ! defined( 'WP_INSTALLING' ) && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) {
     98                return $translations;
     99        }
     100
     101        include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
     102
     103        $api = translations_api( 'core', array( 'version' => $wp_version ) );
     104
     105        if ( is_wp_error( $api ) || empty( $api['translations'] ) ) {
     106                return array();
     107        }
     108
     109        $translations = array();
     110        // Key the array with the language code for now.
     111        foreach ( $api['translations'] as $translation ) {
     112                $translations[ $translation['language'] ] = $translation;
     113        }
     114
     115        if ( ! defined( 'WP_INSTALLING' ) ) {
     116                set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS );
     117        }
     118
     119        return $translations;
     120}
     121
     122/**
     123 * Output the select form for the language selection on the installation screen.
     124 *
     125 * @since 4.0.0
     126 *
     127 * @param array $languages Array of available languages (populated via the Translation API).
     128 */
     129function wp_install_language_form( $languages ) {
     130        $installed_languages = get_available_languages();
     131
     132        echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n";
     133        echo "<select size='14' name='language' id='language'>\n";
     134        echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>';
     135        echo "\n";
     136
     137        if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) {
     138                if ( isset( $languages[ WPLANG ] ) ) {
     139                        $language = $languages[ WPLANG ];
     140                        echo '<option value="' . esc_attr( $language['language'] ) . '" lang="' . esc_attr( $language['iso'][1] ) . '">' . esc_html( $language['native_name'] ) . "</option>\n";
     141                        unset( $languages[ WPLANG ] );
     142                }
     143        }
     144
     145        foreach ( $languages as $language ) {
     146                printf( '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
     147                        esc_attr( $language['language'] ),
     148                        esc_attr( $language['iso'][1] ),
     149                        esc_attr( $language['strings']['continue'] ),
     150                        in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
     151                        esc_html( $language['native_name'] ) );
     152        }
     153        echo "</select>\n";
     154        echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';
     155}
     156
     157/**
     158 * Download a language pack.
     159 *
     160 * @since 4.0.0
     161 *
     162 * @see wp_get_available_translations()
     163 *
     164 * @param string $download Language code to download.
     165 * @return string|bool Returns the language code if successfully downloaded
     166 *                     (or already installed), or false on failure.
     167 */
     168function wp_download_language_pack( $download ) {
     169        // Check if the translation is already installed.
     170        if ( in_array( $download, get_available_languages() ) ) {
     171                return $download;
     172        }
     173
     174        if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
     175                return false;
     176        }
     177
     178        // Confirm the translation is one we can download.
     179        $translations = wp_get_available_translations();
     180        if ( ! $translations ) {
     181                return false;
     182        }
     183        foreach ( $translations as $translation ) {
     184                if ( $translation['language'] === $download ) {
     185                        $translation_to_load = true;
     186                        break;
     187                }
     188        }
     189
     190        if ( empty( $translation_to_load ) ) {
     191                return false;
     192        }
     193        $translation = (object) $translation;
     194
     195        require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     196        $skin = new Automatic_Upgrader_Skin;
     197        $upgrader = new Language_Pack_Upgrader( $skin );
     198        $translation->type = 'core';
     199        /**
     200         * @todo failures (such as non-direct FS)
     201         */
     202        $result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
     203        return $translation->language;
     204}
  • src/wp-admin/includes/upgrade.php

     
    437437        if ( $wp_current_db_version < 26691 )
    438438                upgrade_380();
    439439
     440        if ( $wp_current_db_version < 29600 )
     441                upgrade_400();
     442
    440443        maybe_disable_link_manager();
    441444
    442445        maybe_disable_automattic_widgets();
     
    13041307                deactivate_plugins( array( 'mp6/mp6.php' ), true );
    13051308        }
    13061309}
     1310
    13071311/**
     1312 * Execute changes made in WordPress 4.0.0.
     1313 *
     1314 * @since 4.0.0
     1315 */
     1316function upgrade_400() {
     1317        global $wp_current_db_version;
     1318        if ( $wp_current_db_version < 29600 ) {
     1319                if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) {
     1320                        if (
     1321                                defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) &&
     1322                                in_array( WPLANG, get_available_languages() ) )
     1323                        {
     1324                                update_option( 'WPLANG', WPLANG );
     1325                        } else {
     1326                                update_option( 'WPLANG', '' );
     1327                        }
     1328                }
     1329        }
     1330}
     1331
     1332/**
    13081333 * Execute network level changes
    13091334 *
    13101335 * @since 3.0.0
     
    14191444 */
    14201445function maybe_create_table($table_name, $create_ddl) {
    14211446        global $wpdb;
    1422        
     1447
    14231448        $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $table_name ) );
    14241449
    14251450        if ( $wpdb->get_var( $query ) == $table_name ) {
     
    21922217        dbDelta( $ms_queries );
    21932218}
    21942219endif;
    2195 
    2196 /**
    2197  * Output the input fields for the language selection form on the installation screen.
    2198  *
    2199  * @since 4.0.0
    2200  *
    2201  * @see wp_get_available_translations_from_api()
    2202  *
    2203  * @param array $languages Array of available languages (populated via the Translations API).
    2204  */
    2205 function wp_install_language_form( $languages ) {
    2206         $installed_languages = get_available_languages();
    2207 
    2208         echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n";
    2209         echo "<select size='14' name='language' id='language'>\n";
    2210         echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>';
    2211         echo "\n";
    2212 
    2213         if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) {
    2214                 if ( isset( $languages[ WPLANG ] ) ) {
    2215                         $language = $languages[ WPLANG ];
    2216                         echo '<option value="' . esc_attr( $language['language'] ) . '" lang="' . esc_attr( $language['iso'][1] ) . '">' . esc_html( $language['native_name'] ) . "</option>\n";
    2217                 }
    2218         }
    2219 
    2220         foreach ( $languages as $language ) {
    2221                 printf( '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
    2222                         esc_attr( $language['language'] ),
    2223                         esc_attr( $language['iso'][1] ),
    2224                         esc_attr( $language['strings']['continue'] ),
    2225                         in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
    2226                         esc_html( $language['native_name'] ) );
    2227         }
    2228         echo "</select>\n";
    2229         echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';
    2230 }
    2231 
    2232 /**
    2233  * Get available translations from the WordPress.org API.
    2234  *
    2235  * @since 4.0.0
    2236  *
    2237  * @see wp_remote_post()
    2238  *
    2239  * @return array Array of translations, each an array of data.
    2240  */
    2241 function wp_get_available_translations_from_api() {
    2242         $url = 'http://api.wordpress.org/translations/core/1.0/';
    2243         if ( wp_http_supports( array( 'ssl' ) ) ) {
    2244                 $url = set_url_scheme( $url, 'https' );
    2245         }
    2246 
    2247         $options = array(
    2248                 'timeout' => 3,
    2249                 'body' => array( 'version' => $GLOBALS['wp_version'] ),
    2250         );
    2251 
    2252         $response = wp_remote_post( $url, $options );
    2253         $body = wp_remote_retrieve_body( $response );
    2254         if ( $body && $body = json_decode( $body, true ) ) {
    2255                 $translations = array();
    2256                 // Key the array with the language code for now
    2257                 foreach ( $body['translations'] as $translation ) {
    2258                         $translations[ $translation['language'] ] = $translation;
    2259                 }
    2260                 return $translations;
    2261         }
    2262         return false;
    2263 }
    2264 
    2265 /**
    2266  * Download a language pack.
    2267  *
    2268  * @since 4.0.0
    2269  *
    2270  * @see wp_get_available_translations_from_api()
    2271  *
    2272  * @param string $download Language code to download.
    2273  * @return string|bool Returns the language code if successfully downloaded
    2274  *                     (or already installed), or false on failure.
    2275  */
    2276 function wp_install_download_language_pack( $download ) {
    2277         // Check if the translation is already installed.
    2278         if ( in_array( $download, get_available_languages() ) ) {
    2279                 return $download;
    2280         }
    2281 
    2282         // Confirm the translation is one we can download.
    2283         $translations = wp_get_available_translations_from_api();
    2284         if ( ! $translations ) {
    2285                 return false;
    2286         }
    2287         foreach ( $translations as $translation ) {
    2288                 if ( $translation['language'] === $download ) {
    2289                         $translation_to_load = true;
    2290                         break;
    2291                 }
    2292         }
    2293 
    2294         if ( empty( $translation_to_load ) ) {
    2295                 return false;
    2296         }
    2297         $translation = (object) $translation;
    2298 
    2299         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    2300         $skin = new Automatic_Upgrader_Skin;
    2301         $upgrader = new Language_Pack_Upgrader( $skin );
    2302         $translation->type = 'core';
    2303         /**
    2304          * @todo failures (such as non-direct FS)
    2305          */
    2306         $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
    2307         return $translation->language;
    2308 }
    2309 
    2310 /**
    2311  * Load a translation during the install process.
    2312  *
    2313  * @since 4.0.0
    2314  *
    2315  * @see load_textdomain()
    2316  *
    2317  * @param string $translation Translation to load.
    2318  * @return string|bool Returns the language code if successfully loaded,
    2319  *                     or false on failure.
    2320  */
    2321 function wp_install_load_language( $translation ) {
    2322         if ( ! empty( $translation ) ) {
    2323                 if ( in_array( $translation, get_available_languages() ) ) {
    2324                         $translation_to_load = $translation;
    2325                 }
    2326         }
    2327 
    2328         if ( empty( $translation_to_load ) ) {
    2329                 return false;
    2330         }
    2331 
    2332         unload_textdomain( 'default' ); // Start over.
    2333         load_textdomain( 'default', WP_LANG_DIR . "/{$translation_to_load}.mo" );
    2334         load_textdomain( 'default', WP_LANG_DIR . "/admin-{$translation_to_load}.mo" );
    2335         return $translation_to_load;
    2336 }
  • src/wp-admin/install.php

     
    2323</html>
    2424<?php
    2525}
    26 
     26error_reporting(-1);
    2727/**
    2828 * We are installing WordPress.
    2929 *
     
    3838/** Load WordPress Administration Upgrade API */
    3939require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    4040
     41/** Load WordPress Translation Install API */
     42require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     43
    4144/** Load wpdb */
    4245require_once( ABSPATH . WPINC . '/wp-db.php' );
    4346
     
    178181        die( '<h1>' . __( 'Configuration Error' ) . '</h1><p>' . __( 'Your <code>wp-config.php</code> file has an empty database table prefix, which is not supported.' ) . '</p></body></html>' );
    179182}
    180183
     184$langugage = '';
     185if ( ! empty( $_REQUEST['language'] ) ) {
     186        $langugage = preg_replace( '/[^a-zA-Z_]/', '', $_REQUEST['language'] );
     187}
     188
    181189switch($step) {
    182190        case 0: // Step 0
    183191
    184                 if ( empty( $_GET['language'] ) && ( $languages = wp_get_available_translations_from_api() ) ) {
     192                if ( empty( $langugage ) && ( $languages = wp_get_available_translations() ) ) {
    185193                        display_header( 'language-chooser' );
    186194                        echo '<form id="setup" method="post" action="?step=1">';
    187195                        wp_install_language_form( $languages );
     
    192200                // Deliberately fall through if we can't reach the translations API.
    193201
    194202        case 1: // Step 1, direct link or from language chooser.
    195                 if ( ! empty( $_REQUEST['language'] ) ) {
    196                         $loaded_language = wp_install_download_language_pack( $_REQUEST['language'] );
     203                if ( ! empty( $langugage ) ) {
     204                        $loaded_language = wp_download_language_pack( $langugage );
    197205                        if ( $loaded_language ) {
    198                                 wp_install_load_language( $loaded_language );
     206                                load_default_textdomain( $loaded_language );
    199207                        }
    200208                }
    201209
     
    211219                display_setup_form();
    212220                break;
    213221        case 2:
    214                 if ( !empty( $_REQUEST['language'] ) ) {
    215                         $loaded_language = wp_install_load_language( $_REQUEST['language'] );
     222                if ( ! empty( $langugage ) && load_default_textdomain( $langugage ) ) {
     223                        $loaded_language = $langugage;
    216224                } else {
    217225                        $loaded_language = 'en_US';
    218226                }
     
    226234                $user_name = isset($_POST['user_name']) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
    227235                $admin_password = isset($_POST['admin_password']) ? wp_unslash( $_POST['admin_password'] ) : '';
    228236                $admin_password_check = isset($_POST['admin_password2']) ? wp_unslash( $_POST['admin_password2'] ) : '';
    229                 $admin_email  = isset( $_POST['admin_email']  ) ?trim( wp_unslash( $_POST['admin_email'] ) ) : '';
    230                 $public       = isset( $_POST['blog_public']  ) ? (int) $_POST['blog_public'] : 0;
     237                $admin_email  = isset( $_POST['admin_email'] ) ?trim( wp_unslash( $_POST['admin_email'] ) ) : '';
     238                $public       = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 0;
    231239
    232240                // Check e-mail address.
    233241                $error = false;
  • src/wp-admin/network/settings.php

     
    102102                                        <input name="admin_email" type="email" id="admin_email" class="regular-text" value="<?php echo esc_attr( get_site_option( 'admin_email' ) ) ?>" />
    103103                                        <p class="description">
    104104                                                <?php _e( 'This email address will receive notifications. Registration and support emails will also come from this address.' ); ?>
    105                                         </p>   
     105                                        </p>
    106106                                </td>
    107107                        </tr>
    108108                </table>
     
    165165<?php echo esc_textarea( $limited_email_domains == '' ? '' : implode( "\n", (array) $limited_email_domains ) ); ?></textarea>
    166166                                        <p class="description">
    167167                                                <?php _e( 'If you want to limit site registrations to certain domains. One domain per line.' ) ?>
    168                                         </p>   
     168                                        </p>
    169169                                </td>
    170170                        </tr>
    171171
     
    231231<?php echo esc_textarea( get_site_option( 'first_comment' ) ) ?></textarea>
    232232                                        <p class="description">
    233233                                                <?php _e( 'The first comment on a new site.' ) ?>
    234                                         </p>   
     234                                        </p>
    235235                                </td>
    236236                        </tr>
    237237                        <tr>
     
    273273                        </tr>
    274274                </table>
    275275
    276 <?php
     276                <?php
    277277                $languages = get_available_languages();
    278278                if ( ! empty( $languages ) ) {
    279                         $lang = get_site_option( 'WPLANG' );
    280 ?>
    281                 <h3><?php _e( 'Language Settings' ); ?></h3>
    282                 <table class="form-table">
     279                        ?>
     280                        <h3><?php _e( 'Language Settings' ); ?></h3>
     281                        <table class="form-table">
    283282                                <tr>
    284283                                        <th><label for="WPLANG"><?php _e( 'Default Language' ); ?></label></th>
    285284                                        <td>
    286                                                 <select name="WPLANG" id="WPLANG">
    287                                                         <?php mu_dropdown_languages( $languages, get_site_option( 'WPLANG' ) ); ?>
    288                                                 </select>
     285                                                <?php
     286                                                $lang = get_site_option( 'WPLANG' );
     287                                                if ( ! in_array( $lang, $languages ) ) {
     288                                                        $lang = '';
     289                                                }
     290
     291                                                wp_dropdown_languages( array(
     292                                                        'name'      => 'WPLANG',
     293                                                        'id'        => 'WPLANG',
     294                                                        'selected'  => $lang,
     295                                                        'languages' => $languages,
     296                                                ) );
     297                                                ?>
    289298                                        </td>
    290299                                </tr>
    291                 </table>
    292 <?php
    293                 } // languages
    294 ?>
     300                        </table>
     301                        <?php
     302                }
     303                ?>
    295304
    296305                <h3><?php _e( 'Menu Settings' ); ?></h3>
    297306                <table id="menu" class="form-table">
     
    324333                        </tr>
    325334                </table>
    326335
    327                 <?php 
     336                <?php
    328337                /**
    329338                 * Fires at the end of the Network Settings form, before the submit button.
    330339                 *
  • src/wp-admin/options-general.php

     
    302302</select></td>
    303303</tr>
    304304<?php do_settings_fields('general', 'default'); ?>
     305
    305306<?php
    306         $languages = get_available_languages();
    307         if ( $languages ) :
    308 ?>
     307$languages = get_available_languages();
     308if ( ! empty( $languages ) ) {
     309        ?>
    309310        <tr>
    310                 <th width="33%" scope="row"><label for="WPLANG"><?php _e('Site Language') ?></label></th>
     311                <th width="33%" scope="row"><label for="WPLANG"><?php _e( 'Site Language' ); ?></label></th>
    311312                <td>
    312                         <?php wp_dropdown_languages( array(
     313                        <?php
     314                        $locale = get_locale();
     315                        // Check if current locale is still installed. en_US will fail this test, but that's okay.
     316                        if ( ! in_array( $locale, $languages ) ) {
     317                                $locale = '';
     318                        }
     319
     320                        wp_dropdown_languages( array(
    313321                                'name'      => 'WPLANG',
    314322                                'id'        => 'WPLANG',
    315                                 'selected'  => get_option( 'WPLANG' ),
     323                                'selected'  => $locale,
    316324                                'languages' => $languages,
    317                         ) ); ?>
     325                        ) );
     326
     327                        // Add note about deprecated WPLANG constant.
     328                        if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && $locale !== WPLANG && is_super_admin() ) {
     329                                ?>
     330                                <p class="description">
     331                                        <?php _e( '<strong>Note:</strong> The <code>WPLANG</code> constant in your <code>wp-config.php</code> file is deprecated.' ); ?>
     332                                </p>
     333                                <?php
     334                        }
     335                        ?>
    318336                </td>
    319337        </tr>
    320 <?php
    321         endif;
     338        <?php
     339}
    322340?>
    323341</table>
    324342
  • src/wp-admin/options.php

     
    151151                $options = $whitelist_options[ $option_page ];
    152152        }
    153153
    154         // Handle custom date/time formats
     154        // Handle custom date/time formats.
    155155        if ( 'general' == $option_page ) {
    156156                if ( !empty($_POST['date_format']) && isset($_POST['date_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) )
    157157                        $_POST['date_format'] = $_POST['date_format_custom'];
     
    180180                        }
    181181                        update_option( $option, $value );
    182182                }
     183
     184                // Switch translation in case WPLANG was changed.
     185                $language = get_option( 'WPLANG' );
     186                if ( $language ) {
     187                        load_default_textdomain( $language );
     188                } else {
     189                        unload_textdomain( 'default' );
     190                }
    183191        }
    184192
    185193        /**
  • src/wp-admin/setup-config.php

     
    2626 *
    2727 * Set this to error_reporting( -1 ) for debugging
    2828 */
    29 error_reporting(0);
     29error_reporting(-1);
    3030
    3131define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' );
    3232
    3333require( ABSPATH . 'wp-settings.php' );
    3434
    35 require( ABSPATH . 'wp-admin/includes/upgrade.php' );
     35/** Load WordPress Administration Upgrade API */
     36require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    3637
     38/** Load WordPress Translation Install API */
     39require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     40
    3741nocache_headers();
    3842
    3943// Support wp-config-sample.php one level up, for the develop repo.
     
    8589<?php
    8690} // end function setup_config_display_header();
    8791
     92$language = '';
     93if ( ! empty( $_REQUEST['language'] ) ) {
     94        $language = preg_replace( '/[^a-zA-Z_]/', '', $_REQUEST['language'] );
     95}
    8896switch($step) {
    8997        case -1:
    90 
    91                 if ( empty( $_GET['language'] ) && ( $languages = wp_get_available_translations_from_api() ) ) {
     98                if ( empty( $language ) && ( $languages = wp_get_available_translations() ) ) {
    9299                        setup_config_display_header( 'language-chooser' );
    93100                        echo '<form id="setup" method="post" action="?step=0">';
    94101                        wp_install_language_form( $languages );
     
    99106                // Deliberately fall through if we can't reach the translations API.
    100107
    101108        case 0:
    102                 if ( ! empty( $_REQUEST['language'] ) ) {
    103                         $loaded_language = wp_install_download_language_pack( $_REQUEST['language'] );
     109                if ( ! empty( $language ) ) {
     110                        $loaded_language = wp_download_language_pack( $language );
    104111                        if ( $loaded_language ) {
    105                                 wp_install_load_language( $loaded_language );
     112                                load_default_textdomain( $loaded_language );
    106113                        }
    107114                }
    108115
     
    136143        break;
    137144
    138145        case 1:
    139                 $loaded_language = wp_install_load_language( $_REQUEST['language'] );
     146                load_default_textdomain( $language );
    140147                setup_config_display_header();
    141148        ?>
    142149<form method="post" action="setup-config.php?step=2">
     
    169176                </tr>
    170177        </table>
    171178        <?php if ( isset( $_GET['noapi'] ) ) { ?><input name="noapi" type="hidden" value="1" /><?php } ?>
    172         <input type="hidden" name="language" value="<?php echo esc_attr( $loaded_language ); ?>" />
     179        <input type="hidden" name="language" value="<?php echo esc_attr( $language ); ?>" />
    173180        <p class="step"><input name="submit" type="submit" value="<?php echo htmlspecialchars( __( 'Submit' ), ENT_QUOTES ); ?>" class="button button-large" /></p>
    174181</form>
    175182<?php
    176183        break;
    177184
    178185        case 2:
    179         $loaded_language = wp_install_load_language( $_REQUEST['language'] );
     186        load_default_textdomain( $language );
    180187        $dbname = trim( wp_unslash( $_POST[ 'dbname' ] ) );
    181188        $uname = trim( wp_unslash( $_POST[ 'uname' ] ) );
    182189        $pwd = trim( wp_unslash( $_POST[ 'pwd' ] ) );
     
    189196                $step_1 .= '&amp;noapi';
    190197        }
    191198
    192         if ( $loaded_language ) {
    193                 $step_1 .= '&amp;language=' . $loaded_language;
    194                 $install .= '?language=' . $loaded_language;
     199        if ( $language ) {
     200                $step_1 .= '&amp;language=' . $language;
     201                $install .= '?language=' . $language;
    195202        } else {
    196203                $install .= '?language=en_US';
    197204        }
  • src/wp-includes/l10n.php

     
    2424 * @return string The locale of the blog or from the 'locale' hook.
    2525 */
    2626function get_locale() {
    27         global $locale;
     27        global $locale, $wp_local_package;
    2828
    2929        if ( isset( $locale ) ) {
    3030                /**
     
    3838        }
    3939
    4040        // WPLANG is defined in wp-config.
    41         if ( defined( 'WPLANG' ) )
     41        if ( defined( 'WPLANG' ) ) {
    4242                $locale = WPLANG;
     43        }
    4344
     45        if ( isset( $wp_local_package ) ) {
     46                $locale = $wp_local_package;
     47        }
     48
    4449        // If multisite, check options.
    4550        if ( is_multisite() ) {
    4651                // Don't check blog option when installing.
    47                 if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) )
    48                         $ms_locale = get_site_option('WPLANG');
     52                if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) {
     53                        $ms_locale = get_site_option( 'WPLANG' );
     54                }
    4955
    50                 if ( $ms_locale !== false )
     56                if ( $ms_locale !== false ) {
    5157                        $locale = $ms_locale;
    52         } elseif ( ! defined( 'WP_INSTALLING' ) ) {
     58                }
     59        } else {
    5360                $db_locale = get_option( 'WPLANG' );
    54                 if ( $db_locale ) {
     61                if ( $db_locale !== false ) {
    5562                        $locale = $db_locale;
    5663                }
    5764        }
    5865
    59         if ( empty( $locale ) )
     66        if ( empty( $locale ) ) {
    6067                $locale = 'en_US';
     68        }
    6169
    6270        /** This filter is documented in wp-includes/l10n.php */
    6371        return apply_filters( 'locale', $locale );
     
    523531 * @see load_textdomain()
    524532 *
    525533 * @since 1.5.0
     534 *
     535 * @param string $locale Optional. Locale to load. Defaults to get_locale().
    526536 */
    527 function load_default_textdomain() {
    528         $locale = get_locale();
     537function load_default_textdomain( $locale = null ) {
     538        if ( null === $locale ) {
     539                $locale = get_locale();
     540        }
    529541
    530         load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" );
     542        // Unload previously loaded strings so we can switch translations.
     543        unload_textdomain( 'default' );
    531544
     545        $return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" );
     546
    532547        if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists(  WP_LANG_DIR . "/admin-$locale.mo" ) ) {
    533548                load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" );
    534                 return;
     549                return $return;
    535550        }
    536551
    537         if ( is_admin() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) )
     552        if ( is_admin() || defined( 'WP_INSTALLING' ) || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) {
    538553                load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );
     554        }
    539555
    540556        if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) )
    541557                load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" );
    542558
     559        return $return;
    543560}
    544561
    545562/**
     
    818835}
    819836
    820837/**
    821  * Language selector. More to come.
     838 * Language selector.
    822839 *
    823840 * @since 4.0.0
    824841 *
    825842 * @see get_available_languages()
     843 * @see wp_get_available_translations()
    826844 *
    827845 * @param array $args Optional arguments. Default empty array.
    828846 */
    829847function wp_dropdown_languages( $args = array() ) {
    830         if ( isset( $args['languages'] ) ) {
    831                 $languages = $args['languages'];
    832         } else {
    833                 $languages = get_available_languages();
     848        require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     849
     850        $args = wp_parse_args( $args, array(
     851                'id'        => '',
     852                'name'      => '',
     853                'languages' => array(),
     854                'selected'  => ''
     855        ) );
     856
     857        if ( empty( $args['languages'] ) ) {
     858                return false;
    834859        }
    835860
     861        $translations = wp_get_available_translations();
     862
     863        /*
     864         * $args['languages'] should only contain the locales. Find the locale in
     865         * $translations to get the native name. Fall back to locale.
     866         */
     867        $languages = array();
     868        foreach ( $args['languages'] as $locale ) {
     869                if ( isset( $translations[ $locale ] ) ) {
     870                        $translation = $translations[ $locale ];
     871                        $languages[] = $translation;
     872                } else {
     873                        $languages[] = array(
     874                                'language'    => $locale,
     875                                'native_name' => $locale,
     876                                'lang'        => '',
     877                        );
     878                }
     879        }
     880
    836881        printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
    837         echo '<option value="">en_US</option>';
     882
     883        // List installed languages.
     884        echo '<option value="">English (United States)</option>';
    838885        foreach ( $languages as $language ) {
    839                 $selected = selected( $language, $args['selected'], false );
    840                 echo '<option value="' . esc_attr( $language ) .'"' . $selected . '>' . $language . '</option>';
     886                $selected = selected( $language['language'], $args['selected'], false );
     887                printf(
     888                        '<option value="%s" lang="%s"%s>%s</option>',
     889                        esc_attr( $language['language'] ),
     890                        esc_attr( $language['iso'][1] ),
     891                        $selected,
     892                        esc_html( $language['native_name'] )
     893                );
    841894        }
     895
    842896        echo '</select>';
    843897}
  • src/wp-includes/version.php

     
    1111 *
    1212 * @global int $wp_db_version
    1313 */
    14 $wp_db_version = 29188;
     14$wp_db_version = 29600;
    1515
    1616/**
    1717 * Holds the TinyMCE version
  • wp-config-sample.php

     
    6262$table_prefix  = 'wp_';
    6363
    6464/**
    65  * WordPress Localized Language, defaults to English.
    66  *
    67  * Change this to localize WordPress. A corresponding MO file for the chosen
    68  * language must be installed to wp-content/languages. For example, install
    69  * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German
    70  * language support.
    71  */
    72 define('WPLANG', '');
    73 
    74 /**
    7565 * For developers: WordPress debugging mode.
    7666 *
    7767 * Change this to true to enable the display of notices during development.