wp/wp-admin/install.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     8 
     8 
     9 // Sanity check.
     9 // Sanity check.
    10 if ( false ) {
    10 if ( false ) {
    11 	?>
    11 	?>
    12 <!DOCTYPE html>
    12 <!DOCTYPE html>
    13 <html xmlns="http://www.w3.org/1999/xhtml">
    13 <html>
    14 <head>
    14 <head>
    15 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    15 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    16 	<title>Error: PHP is not running</title>
    16 	<title>Error: PHP is not running</title>
    17 </head>
    17 </head>
    18 <body class="wp-core-ui">
    18 <body class="wp-core-ui">
    31  * @var bool
    31  * @var bool
    32  */
    32  */
    33 define( 'WP_INSTALLING', true );
    33 define( 'WP_INSTALLING', true );
    34 
    34 
    35 /** Load WordPress Bootstrap */
    35 /** Load WordPress Bootstrap */
    36 require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
    36 require_once dirname( __DIR__ ) . '/wp-load.php';
    37 
    37 
    38 /** Load WordPress Administration Upgrade API */
    38 /** Load WordPress Administration Upgrade API */
    39 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    39 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    40 
    40 
    41 /** Load WordPress Translation Install API */
    41 /** Load WordPress Translation Install API */
    42 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
    42 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
    43 
    43 
    44 /** Load wpdb */
    44 /** Load wpdb */
    45 require_once( ABSPATH . WPINC . '/wp-db.php' );
    45 require_once ABSPATH . WPINC . '/wp-db.php';
    46 
    46 
    47 nocache_headers();
    47 nocache_headers();
    48 
    48 
    49 $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0;
    49 $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0;
    50 
    50 
    63 	if ( $body_classes ) {
    63 	if ( $body_classes ) {
    64 		$body_classes = ' ' . $body_classes;
    64 		$body_classes = ' ' . $body_classes;
    65 	}
    65 	}
    66 	?>
    66 	?>
    67 <!DOCTYPE html>
    67 <!DOCTYPE html>
    68 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    68 <html <?php language_attributes(); ?>>
    69 <head>
    69 <head>
    70 	<meta name="viewport" content="width=device-width" />
    70 	<meta name="viewport" content="width=device-width" />
    71 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    71 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    72 	<meta name="robots" content="noindex,nofollow" />
    72 	<meta name="robots" content="noindex,nofollow" />
    73 	<title><?php _e( 'WordPress &rsaquo; Installation' ); ?></title>
    73 	<title><?php _e( 'WordPress &rsaquo; Installation' ); ?></title>
    74 	<?php wp_admin_css( 'install', true ); ?>
    74 	<?php wp_admin_css( 'install', true ); ?>
    75 </head>
    75 </head>
    76 <body class="wp-core-ui<?php echo $body_classes; ?>">
    76 <body class="wp-core-ui<?php echo $body_classes; ?>">
    77 <p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>"><?php _e( 'WordPress' ); ?></a></p>
    77 <p id="logo"><?php _e( 'WordPress' ); ?></p>
    78 
    78 
    79 	<?php
    79 	<?php
    80 } // end display_header()
    80 } // End display_header().
    81 
    81 
    82 /**
    82 /**
    83  * Display installer setup form.
    83  * Display installer setup form.
    84  *
    84  *
    85  * @since 2.8.0
    85  * @since 2.8.0
    89  * @param string|null $error
    89  * @param string|null $error
    90  */
    90  */
    91 function display_setup_form( $error = null ) {
    91 function display_setup_form( $error = null ) {
    92 	global $wpdb;
    92 	global $wpdb;
    93 
    93 
    94 	$sql        = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->users ) );
    94 	$user_table = ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->users ) ) ) !== null );
    95 	$user_table = ( $wpdb->get_var( $sql ) != null );
    95 
    96 
    96 	// Ensure that sites appear in search engines by default.
    97 	// Ensure that Blogs appear in search engines by default.
       
    98 	$blog_public = 1;
    97 	$blog_public = 1;
    99 	if ( isset( $_POST['weblog_title'] ) ) {
    98 	if ( isset( $_POST['weblog_title'] ) ) {
   100 		$blog_public = isset( $_POST['blog_public'] );
    99 		$blog_public = isset( $_POST['blog_public'] );
   101 	}
   100 	}
   102 
   101 
   178 			<th scope="row"><label for="admin_email"><?php _e( 'Your Email' ); ?></label></th>
   177 			<th scope="row"><label for="admin_email"><?php _e( 'Your Email' ); ?></label></th>
   179 			<td><input name="admin_email" type="email" id="admin_email" size="25" value="<?php echo esc_attr( $admin_email ); ?>" />
   178 			<td><input name="admin_email" type="email" id="admin_email" size="25" value="<?php echo esc_attr( $admin_email ); ?>" />
   180 			<p><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
   179 			<p><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
   181 		</tr>
   180 		</tr>
   182 		<tr>
   181 		<tr>
   183 			<th scope="row"><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site Visibility' ) : _e( 'Search Engine Visibility' ); ?></th>
   182 			<th scope="row"><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site visibility' ) : _e( 'Search engine visibility' ); ?></th>
   184 			<td>
   183 			<td>
   185 				<fieldset>
   184 				<fieldset>
   186 					<legend class="screen-reader-text"><span><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site Visibility' ) : _e( 'Search Engine Visibility' ); ?> </span></legend>
   185 					<legend class="screen-reader-text"><span><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site visibility' ) : _e( 'Search engine visibility' ); ?> </span></legend>
   187 					<?php
   186 					<?php
   188 					if ( has_action( 'blog_privacy_selector' ) ) {
   187 					if ( has_action( 'blog_privacy_selector' ) ) {
   189 						?>
   188 						?>
   190 						<input id="blog-public" type="radio" name="blog_public" value="1" <?php checked( 1, $blog_public ); ?> />
   189 						<input id="blog-public" type="radio" name="blog_public" value="1" <?php checked( 1, $blog_public ); ?> />
   191 						<label for="blog-public"><?php _e( 'Allow search engines to index this site' ); ?></label><br/>
   190 						<label for="blog-public"><?php _e( 'Allow search engines to index this site' ); ?></label><br/>
   207 	</table>
   206 	</table>
   208 	<p class="step"><?php submit_button( __( 'Install WordPress' ), 'large', 'Submit', false, array( 'id' => 'submit' ) ); ?></p>
   207 	<p class="step"><?php submit_button( __( 'Install WordPress' ), 'large', 'Submit', false, array( 'id' => 'submit' ) ); ?></p>
   209 	<input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" />
   208 	<input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" />
   210 </form>
   209 </form>
   211 	<?php
   210 	<?php
   212 } // end display_setup_form()
   211 } // End display_setup_form().
   213 
   212 
   214 // Let's check to make sure WP isn't already installed.
   213 // Let's check to make sure WP isn't already installed.
   215 if ( is_blog_installed() ) {
   214 if ( is_blog_installed() ) {
   216 	display_header();
   215 	display_header();
   217 	die(
   216 	die(
   221 		'</body></html>'
   220 		'</body></html>'
   222 	);
   221 	);
   223 }
   222 }
   224 
   223 
   225 /**
   224 /**
   226  * @global string $wp_version
   225  * @global string $wp_version             The WordPress version string.
   227  * @global string $required_php_version
   226  * @global string $required_php_version   The required PHP version string.
   228  * @global string $required_mysql_version
   227  * @global string $required_mysql_version The required MySQL version string.
   229  */
   228  */
   230 global $wp_version, $required_php_version, $required_mysql_version;
   229 global $wp_version, $required_php_version, $required_mysql_version;
   231 
   230 
   232 $php_version   = phpversion();
   231 $php_version   = phpversion();
   233 $mysql_version = $wpdb->db_version();
   232 $mysql_version = $wpdb->db_version();
   234 $php_compat    = version_compare( $php_version, $required_php_version, '>=' );
   233 $php_compat    = version_compare( $php_version, $required_php_version, '>=' );
   235 $mysql_compat  = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' );
   234 $mysql_compat  = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' );
   236 
   235 
   237 $version_url = sprintf(
   236 $version_url = sprintf(
   238 	/* translators: %s: WordPress version */
   237 	/* translators: %s: WordPress version. */
   239 	esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
   238 	esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
   240 	sanitize_title( $wp_version )
   239 	sanitize_title( $wp_version )
   241 );
   240 );
   242 
   241 
   243 /* translators: %s: Update PHP page URL */
   242 /* translators: %s: URL to Update PHP page. */
   244 $php_update_message = '</p><p>' . sprintf( __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) );
   243 $php_update_message = '</p><p>' . sprintf(
       
   244 	__( '<a href="%s">Learn more about updating PHP</a>.' ),
       
   245 	esc_url( wp_get_update_php_url() )
       
   246 );
   245 
   247 
   246 $annotation = wp_get_update_php_annotation();
   248 $annotation = wp_get_update_php_annotation();
       
   249 
   247 if ( $annotation ) {
   250 if ( $annotation ) {
   248 	$php_update_message .= '</p><p><em>' . $annotation . '</em>';
   251 	$php_update_message .= '</p><p><em>' . $annotation . '</em>';
   249 }
   252 }
   250 
   253 
   251 if ( ! $mysql_compat && ! $php_compat ) {
   254 if ( ! $mysql_compat && ! $php_compat ) {
   252 	/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number */
   255 	$compat = sprintf(
   253 	$compat = sprintf( __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ), $version_url, $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version ) . $php_update_message;
   256 		/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number. */
       
   257 		__( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ),
       
   258 		$version_url,
       
   259 		$wp_version,
       
   260 		$required_php_version,
       
   261 		$required_mysql_version,
       
   262 		$php_version,
       
   263 		$mysql_version
       
   264 	) . $php_update_message;
   254 } elseif ( ! $php_compat ) {
   265 } elseif ( ! $php_compat ) {
   255 	/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number */
   266 	$compat = sprintf(
   256 	$compat = sprintf( __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ), $version_url, $wp_version, $required_php_version, $php_version ) . $php_update_message;
   267 		/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
       
   268 		__( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ),
       
   269 		$version_url,
       
   270 		$wp_version,
       
   271 		$required_php_version,
       
   272 		$php_version
       
   273 	) . $php_update_message;
   257 } elseif ( ! $mysql_compat ) {
   274 } elseif ( ! $mysql_compat ) {
   258 	/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number */
   275 	$compat = sprintf(
   259 	$compat = sprintf( __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ), $version_url, $wp_version, $required_mysql_version, $mysql_version );
   276 		/* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
       
   277 		__( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ),
       
   278 		$version_url,
       
   279 		$wp_version,
       
   280 		$required_mysql_version,
       
   281 		$mysql_version
       
   282 	);
   260 }
   283 }
   261 
   284 
   262 if ( ! $mysql_compat || ! $php_compat ) {
   285 if ( ! $mysql_compat || ! $php_compat ) {
   263 	display_header();
   286 	display_header();
   264 	die( '<h1>' . __( 'Insufficient Requirements' ) . '</h1><p>' . $compat . '</p></body></html>' );
   287 	die( '<h1>' . __( 'Requirements Not Met' ) . '</h1><p>' . $compat . '</p></body></html>' );
   265 }
   288 }
   266 
   289 
   267 if ( ! is_string( $wpdb->base_prefix ) || '' === $wpdb->base_prefix ) {
   290 if ( ! is_string( $wpdb->base_prefix ) || '' === $wpdb->base_prefix ) {
   268 	display_header();
   291 	display_header();
   269 	die(
   292 	die(
   288 		) . '</p></body></html>'
   311 		) . '</p></body></html>'
   289 	);
   312 	);
   290 }
   313 }
   291 
   314 
   292 /**
   315 /**
   293  * @global string    $wp_local_package
   316  * @global string    $wp_local_package Locale code of the package.
   294  * @global WP_Locale $wp_locale
   317  * @global WP_Locale $wp_locale        WordPress date and time locale object.
   295  */
   318  */
   296 $language = '';
   319 $language = '';
   297 if ( ! empty( $_REQUEST['language'] ) ) {
   320 if ( ! empty( $_REQUEST['language'] ) ) {
   298 	$language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] );
   321 	$language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] );
   299 } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
   322 } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
   301 }
   324 }
   302 
   325 
   303 $scripts_to_print = array( 'jquery' );
   326 $scripts_to_print = array( 'jquery' );
   304 
   327 
   305 switch ( $step ) {
   328 switch ( $step ) {
   306 	case 0: // Step 0
   329 	case 0: // Step 0.
   307 		if ( wp_can_install_language_pack() && empty( $language ) && ( $languages = wp_get_available_translations() ) ) {
   330 		if ( wp_can_install_language_pack() && empty( $language ) ) {
   308 			$scripts_to_print[] = 'language-chooser';
   331 			$languages = wp_get_available_translations();
   309 			display_header( 'language-chooser' );
   332 			if ( $languages ) {
   310 			echo '<form id="setup" method="post" action="?step=1">';
   333 				$scripts_to_print[] = 'language-chooser';
   311 			wp_install_language_form( $languages );
   334 				display_header( 'language-chooser' );
   312 			echo '</form>';
   335 				echo '<form id="setup" method="post" action="?step=1">';
   313 			break;
   336 				wp_install_language_form( $languages );
       
   337 				echo '</form>';
       
   338 				break;
       
   339 			}
   314 		}
   340 		}
   315 
   341 
   316 		// Deliberately fall through if we can't reach the translations API.
   342 		// Deliberately fall through if we can't reach the translations API.
   317 
   343 
   318 	case 1: // Step 1, direct link or from language chooser.
   344 	case 1: // Step 1, direct link or from language chooser.
   350 		}
   376 		}
   351 
   377 
   352 		$scripts_to_print[] = 'user-profile';
   378 		$scripts_to_print[] = 'user-profile';
   353 
   379 
   354 		display_header();
   380 		display_header();
   355 		// Fill in the data we gathered
   381 		// Fill in the data we gathered.
   356 		$weblog_title         = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
   382 		$weblog_title         = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
   357 		$user_name            = isset( $_POST['user_name'] ) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
   383 		$user_name            = isset( $_POST['user_name'] ) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
   358 		$admin_password       = isset( $_POST['admin_password'] ) ? wp_unslash( $_POST['admin_password'] ) : '';
   384 		$admin_password       = isset( $_POST['admin_password'] ) ? wp_unslash( $_POST['admin_password'] ) : '';
   359 		$admin_password_check = isset( $_POST['admin_password2'] ) ? wp_unslash( $_POST['admin_password2'] ) : '';
   385 		$admin_password_check = isset( $_POST['admin_password2'] ) ? wp_unslash( $_POST['admin_password2'] ) : '';
   360 		$admin_email          = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
   386 		$admin_email          = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
   361 		$public               = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 1;
   387 		$public               = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 1;
   362 
   388 
   363 		// Check email address.
   389 		// Check email address.
   364 		$error = false;
   390 		$error = false;
   365 		if ( empty( $user_name ) ) {
   391 		if ( empty( $user_name ) ) {
   366 			// TODO: poka-yoke
   392 			// TODO: Poka-yoke.
   367 			display_setup_form( __( 'Please provide a valid username.' ) );
   393 			display_setup_form( __( 'Please provide a valid username.' ) );
   368 			$error = true;
   394 			$error = true;
   369 		} elseif ( $user_name != sanitize_user( $user_name, true ) ) {
   395 		} elseif ( sanitize_user( $user_name, true ) !== $user_name ) {
   370 			display_setup_form( __( 'The username you provided has invalid characters.' ) );
   396 			display_setup_form( __( 'The username you provided has invalid characters.' ) );
   371 			$error = true;
   397 			$error = true;
   372 		} elseif ( $admin_password != $admin_password_check ) {
   398 		} elseif ( $admin_password !== $admin_password_check ) {
   373 			// TODO: poka-yoke
   399 			// TODO: Poka-yoke.
   374 			display_setup_form( __( 'Your passwords do not match. Please try again.' ) );
   400 			display_setup_form( __( 'Your passwords do not match. Please try again.' ) );
   375 			$error = true;
   401 			$error = true;
   376 		} elseif ( empty( $admin_email ) ) {
   402 		} elseif ( empty( $admin_email ) ) {
   377 			// TODO: poka-yoke
   403 			// TODO: Poka-yoke.
   378 			display_setup_form( __( 'You must provide an email address.' ) );
   404 			display_setup_form( __( 'You must provide an email address.' ) );
   379 			$error = true;
   405 			$error = true;
   380 		} elseif ( ! is_email( $admin_email ) ) {
   406 		} elseif ( ! is_email( $admin_email ) ) {
   381 			// TODO: poka-yoke
   407 			// TODO: Poka-yoke.
   382 			display_setup_form( __( 'Sorry, that isn&#8217;t a valid email address. Email addresses look like <code>username@example.com</code>.' ) );
   408 			display_setup_form( __( 'Sorry, that isn&#8217;t a valid email address. Email addresses look like <code>username@example.com</code>.' ) );
   383 			$error = true;
   409 			$error = true;
   384 		}
   410 		}
   385 
   411 
   386 		if ( $error === false ) {
   412 		if ( false === $error ) {
   387 			$wpdb->show_errors();
   413 			$wpdb->show_errors();
   388 			$result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
   414 			$result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
   389 			?>
   415 			?>
   390 
   416 
   391 <h1><?php _e( 'Success!' ); ?></h1>
   417 <h1><?php _e( 'Success!' ); ?></h1>