<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[28774] trunk/src: Allow a language to be chosen before installing WordPress.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/28774">28774</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2014-06-18 19:57:21 +0000 (Wed, 18 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow a language to be chosen before installing WordPress. First pass. 

* Checks WordPress.org for available languages.
* In get_locale(), starts using the WPLANG option that has existed in multisite since the MU days.
* Adds new argument to wp_install() for setting WPLANG.

see <a href="http://core.trac.wordpress.org/ticket/28577">#28577</a>. </pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincssinstallcss">trunk/src/wp-admin/css/install.css</a></li>
<li><a href="#trunksrcwpadminincludesupgradephp">trunk/src/wp-admin/includes/upgrade.php</a></li>
<li><a href="#trunksrcwpadmininstallphp">trunk/src/wp-admin/install.php</a></li>
<li><a href="#trunksrcwpincludesl10nphp">trunk/src/wp-includes/l10n.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincssinstallcss"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/css/install.css (28773 => 28774)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/css/install.css       2014-06-18 19:48:46 UTC (rev 28773)
+++ trunk/src/wp-admin/css/install.css  2014-06-18 19:57:21 UTC (rev 28774)
</span><span class="lines">@@ -311,3 +311,38 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx"> }
</span><ins>+
+.language-chooser select {
+       margin: 1px;
+       padding: 8px;
+       width: 100%;
+       display: block;
+       border: 1px solid #ddd;
+       -webkit-border-radius: 0;
+       border-radius: 0; /* Reset mobile webkit's default element styling */
+       -webkit-transition: .05s border-color ease-in-out;
+       transition: .05s border-color ease-in-out;
+       outline: 0;
+       -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.07);
+       box-shadow: inset 0 1px 2px rgba(0,0,0,0.07);
+       background-color: #fff;
+       color: #333;
+       font-size: 16px;
+       font-family: inherit;
+       font-weight: inherit;
+}
+
+.language-chooser select:focus {
+       border-color: #5b9dd9;
+       -webkit-box-shadow: 0 0 2px rgba(30,140,190,0.8);
+       box-shadow: 0 0 2px rgba(30,140,190,0.8);
+}
+
+.wp-core-ui .language-chooser .button.button-hero {
+       font-size: 30px;
+       line-height: 30px;
+}
+
+.language-chooser p {
+       text-align: right;
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunksrcwpadminincludesupgradephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/upgrade.php (28773 => 28774)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/upgrade.php  2014-06-18 19:48:46 UTC (rev 28773)
+++ trunk/src/wp-admin/includes/upgrade.php     2014-06-18 19:57:21 UTC (rev 28774)
</span><span class="lines">@@ -32,9 +32,10 @@
</span><span class="cx">  * @param bool $public Whether blog is public.
</span><span class="cx">  * @param null $deprecated Optional. Not used.
</span><span class="cx">  * @param string $user_password Optional. User's chosen password. Will default to a random password.
</span><ins>+ * @param string $language Optional. Language chosen.
</ins><span class="cx">  * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
</span><span class="cx">  */
</span><del>-function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '' ) {
</del><ins>+function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) {
</ins><span class="cx">   if ( !empty( $deprecated ) )
</span><span class="cx">          _deprecated_argument( __FUNCTION__, '2.6' );
</span><span class="cx"> 
</span><span class="lines">@@ -48,6 +49,10 @@
</span><span class="cx">  update_option('admin_email', $user_email);
</span><span class="cx">  update_option('blog_public', $public);
</span><span class="cx"> 
</span><ins>+       if ( $language ) {
+               update_option( 'WPLANG', $language );
+       }
+
</ins><span class="cx">   $guessurl = wp_guess_url();
</span><span class="cx"> 
</span><span class="cx">  update_option('siteurl', $guessurl);
</span></span></pre></div>
<a id="trunksrcwpadmininstallphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/install.php (28773 => 28774)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/install.php   2014-06-18 19:48:46 UTC (rev 28773)
+++ trunk/src/wp-admin/install.php      2014-06-18 19:57:21 UTC (rev 28774)
</span><span class="lines">@@ -44,6 +44,28 @@
</span><span class="cx"> $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0;
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * @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 ) ) {
+               return $body;
+       }
+       return false;
+}
+
+/**
</ins><span class="cx">  * Display install header.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.5.0
</span><span class="lines">@@ -136,6 +158,7 @@
</span><span class="cx">          </tr>
</span><span class="cx">  </table>
</span><span class="cx">  <p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Install WordPress' ); ?>" class="button button-large" /></p>
</span><ins>+       <input type="hidden" name="language" value="<?php echo isset( $_POST['language'] ) ? esc_attr( $_POST['language'] ) : ''; ?>" />
</ins><span class="cx"> </form>
</span><span class="cx"> <?php
</span><span class="cx"> } // end display_setup_form()
</span><span class="lines">@@ -169,9 +192,51 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> switch($step) {
</span><del>-       case 0: // Step 1
-       case 1: // Step 1, direct link.
-         display_header();
</del><ins>+        case 0: // Step 0
+               if ( $body = wp_get_available_translations() ) {
+                       display_header();
+
+                       echo '<form id="setup" method="post" action="install.php?step=1">';
+                       echo '<div class="language-chooser">';
+                       echo '<select name="language" id="language-chooser" size="15">';
+                       echo '<option selected="selected" value="">English (United States)</option>';
+                       foreach ( $body['languages'] as $language ) {
+                               echo '<option value="' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</option>\n";
+                       }
+                       echo "</select>\n";
+                       echo '<p class="step"><input type="submit" class="button button-primary button-hero" value="&raquo;" /></p>';
+                       echo '</div>';
+                       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();
+                       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" );
+                       }
+               }
+
+               display_header();
</ins><span class="cx"> ?>
</span><span class="cx"> <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
</span><span class="cx"> <p><?php printf( __( 'Welcome to the famous five minute WordPress installation process! You may want to browse the <a href="%s">ReadMe documentation</a> at your leisure. Otherwise, just fill in the information below and you&#8217;ll be on your way to using the most extendable and powerful personal publishing platform in the world.' ), '../readme.html' ); ?></p>
</span><span class="lines">@@ -183,6 +248,16 @@
</span><span class="cx">          display_setup_form();
</span><span class="cx">          break;
</span><span class="cx">  case 2:
</span><ins>+               $loading_language = '';
+               if ( ! empty( $_POST['language'] ) ) {
+                       $available_languages = get_available_languages();
+                       if ( isset( $available_languages[ $_POST['language'] ] ) ) {
+                               $loading_language = $_POST['language'];
+                               load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" );
+                               load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" );
+                       }
+               }
+
</ins><span class="cx">           if ( ! empty( $wpdb->error ) )
</span><span class="cx">                  wp_die( $wpdb->error->get_error_message() );
</span><span class="cx"> 
</span><span class="lines">@@ -219,7 +294,7 @@
</span><span class="cx"> 
</span><span class="cx">          if ( $error === false ) {
</span><span class="cx">                  $wpdb->show_errors();
</span><del>-                       $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ) );
</del><ins>+                        $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loading_language );
</ins><span class="cx"> ?>
</span><span class="cx"> 
</span><span class="cx"> <h1><?php _e( 'Success!' ); ?></h1>
</span><span class="lines">@@ -250,7 +325,7 @@
</span><span class="cx"> }
</span><span class="cx"> if ( !wp_is_mobile() ) {
</span><span class="cx"> ?>
</span><del>-<script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script>
</del><ins>+<script type="text/javascript">var t = document.getElementById('weblog_title') || document.getElementById('language-chooser'); if (t){ t.focus(); }</script>
</ins><span class="cx"> <?php } ?>
</span><span class="cx"> <?php wp_print_scripts( 'user-profile' ); ?>
</span><span class="cx"> </body>
</span></span></pre></div>
<a id="trunksrcwpincludesl10nphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/l10n.php (28773 => 28774)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/l10n.php   2014-06-18 19:48:46 UTC (rev 28773)
+++ trunk/src/wp-includes/l10n.php      2014-06-18 19:57:21 UTC (rev 28774)
</span><span class="lines">@@ -26,7 +26,7 @@
</span><span class="cx"> function get_locale() {
</span><span class="cx">  global $locale;
</span><span class="cx"> 
</span><del>-       if ( isset( $locale ) )
</del><ins>+        if ( isset( $locale ) ) {
</ins><span class="cx">           /**
</span><span class="cx">           * Filter WordPress install's locale ID.
</span><span class="cx">           *
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx">           * @param string $locale The locale ID.
</span><span class="cx">           */
</span><span class="cx">          return apply_filters( 'locale', $locale );
</span><ins>+       }
</ins><span class="cx"> 
</span><span class="cx">  // WPLANG is defined in wp-config.
</span><span class="cx">  if ( defined( 'WPLANG' ) )
</span><span class="lines">@@ -48,6 +49,11 @@
</span><span class="cx"> 
</span><span class="cx">          if ( $ms_locale !== false )
</span><span class="cx">                  $locale = $ms_locale;
</span><ins>+       } elseif ( ! defined( 'WP_INSTALLING' ) ) {
+               $db_locale = get_option( 'WPLANG' );
+               if ( $db_locale ) {
+                       $locale = $db_locale;
+               }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  if ( empty( $locale ) )
</span></span></pre>
</div>
</div>

</body>
</html>