Changeset 29006
- Timestamp:
- 07/05/2014 05:13:05 AM (10 years ago)
- Location:
- trunk/src/wp-admin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r28774 r29006 2159 2159 } 2160 2160 endif; 2161 2162 function 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="»" /></p>'; 2183 } 2184 2185 /** 2186 * @todo rename, move 2187 */ 2188 function 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 2213 function 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 2249 function 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 45 45 46 46 /** 47 * @todo rename, move48 */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 code65 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 /**75 47 * Display install header. 76 48 * … … 172 144 </table> 173 145 <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'] ) : ''; ?>" /> 175 147 </form> 176 148 <?php … … 207 179 switch($step) { 208 180 case 0: // Step 0 209 $body = wp_get_available_translations(); 210 if ( $body) {181 182 if ( empty( $_GET['language'] ) && ( $body = wp_get_available_translations() ) ) { 211 183 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="»" /></p>'; 184 echo '<form id="setup" method="post" action="?step=1">'; 185 wp_install_language_form( $body ); 233 186 echo '</form>'; 234 187 break; 235 188 } 189 236 190 // Deliberately fall through if we can't reach the translations API. 237 191 238 192 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 ); 263 197 } 264 198 } … … 276 210 break; 277 211 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'] ); 287 213 288 214 if ( ! empty( $wpdb->error ) ) … … 322 248 if ( $error === false ) { 323 249 $wpdb->show_errors(); 324 $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $load ing_language );250 $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language ); 325 251 ?> 326 252 -
trunk/src/wp-admin/setup-config.php
r29005 r29006 27 27 * Set this to error_reporting( -1 ) for debugging 28 28 */ 29 error_reporting( -1);29 error_reporting(0); 30 30 31 31 define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' ); 32 32 33 33 require( ABSPATH . 'wp-settings.php' ); 34 35 require( ABSPATH . 'wp-admin/includes/upgrade.php' ); 34 36 35 37 // Support wp-config-sample.php one level up, for the develop repo. … … 49 51 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>' ); 50 52 51 $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0;53 $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : -1; 52 54 53 55 /** … … 57 59 * @since 2.3.0 58 60 */ 59 function setup_config_display_header( ) {61 function setup_config_display_header( $body_classes = array() ) { 60 62 global $wp_version; 63 $body_classes = (array) $body_classes; 64 $body_classes[] = 'wp-core-ui'; 65 if ( is_rtl() ) { 66 $body_classes[] = 'rtl'; 67 } 61 68 62 69 header( 'Content-Type: text/html; charset=utf-8' ); … … 72 79 73 80 </head> 74 <body class=" wp-core-ui<?php if ( is_rtl() ) echo ' rtl'; ?>">81 <body class="<?php echo implode( ' ', $body_classes ); ?>"> 75 82 <h1 id="logo"><a href="<?php esc_attr_e( 'https://wordpress.org/' ); ?>" tabindex="-1"><?php _e( 'WordPress' ); ?></a></h1> 76 83 <?php … … 78 85 79 86 switch($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 80 99 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 81 107 setup_config_display_header(); 108 $step_1 = 'setup-config.php?step=1'; 109 if ( isset( $_REQUEST['noapi'] ) ) { 110 $step_1 .= '&noapi'; 111 } 112 if ( ! empty( $loaded_language ) ) { 113 $step_1 .= '&language=' . $loaded_language; 114 } 82 115 ?> 83 116 … … 97 130 <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’re all ready…" ); ?></p> 98 131 99 <p class="step"><a href=" setup-config.php?step=1<?php if ( isset( $_GET['noapi'] ) ) echo '&noapi'; ?>" class="button button-large"><?php _e( 'Let’s go!' ); ?></a></p>132 <p class="step"><a href="<?php echo $step_1; ?>" class="button button-large"><?php _e( 'Let’s go!' ); ?></a></p> 100 133 <?php 101 134 break; 102 135 103 136 case 1: 137 $loaded_language = wp_install_load_language( $_REQUEST['language'] ); 104 138 setup_config_display_header(); 105 139 ?> … … 134 168 </table> 135 169 <?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 ); ?>" /> 136 171 <p class="step"><input name="submit" type="submit" value="<?php echo htmlspecialchars( __( 'Submit' ), ENT_QUOTES ); ?>" class="button button-large" /></p> 137 172 </form> … … 140 175 141 176 case 2: 177 $loaded_language = wp_install_load_language( $_REQUEST['language'] ); 142 178 $dbname = trim( wp_unslash( $_POST[ 'dbname' ] ) ); 143 179 $uname = trim( wp_unslash( $_POST[ 'uname' ] ) ); … … 146 182 $prefix = trim( wp_unslash( $_POST[ 'prefix' ] ) ); 147 183 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 .= '&noapi'; 188 } 189 if ( $loaded_language ) { 190 $step_1 .= '&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>'; 149 194 150 195 if ( empty( $prefix ) ) … … 240 285 ?></textarea> 241 286 <p><?php _e( 'After you’ve done that, click “Run the install.”' ); ?></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> 243 288 <script> 244 289 (function(){ … … 267 312 <p><?php _e( "All right, sparky! You’ve made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to…" ); ?></p> 268 313 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> 270 315 <?php 271 316 endif;
Note: See TracChangeset
for help on using the changeset viewer.