wp/wp-admin/setup-config.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    10  */
    10  */
    11 
    11 
    12 /**
    12 /**
    13  * We are installing.
    13  * We are installing.
    14  */
    14  */
    15 define('WP_INSTALLING', true);
    15 define( 'WP_INSTALLING', true );
    16 
    16 
    17 /**
    17 /**
    18  * We are blissfully unaware of anything.
    18  * We are blissfully unaware of anything.
    19  */
    19  */
    20 define('WP_SETUP_CONFIG', true);
    20 define( 'WP_SETUP_CONFIG', true );
    21 
    21 
    22 /**
    22 /**
    23  * Disable error reporting
    23  * Disable error reporting
    24  *
    24  *
    25  * Set this to error_reporting( -1 ) for debugging
    25  * Set this to error_reporting( -1 ) for debugging
    26  */
    26  */
    27 error_reporting(0);
    27 error_reporting( 0 );
    28 
    28 
    29 if ( ! defined( 'ABSPATH' ) ) {
    29 if ( ! defined( 'ABSPATH' ) ) {
    30 	define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' );
    30 	define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' );
    31 }
    31 }
    32 
    32 
    44 if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) {
    44 if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) {
    45 	$config_file = file( ABSPATH . 'wp-config-sample.php' );
    45 	$config_file = file( ABSPATH . 'wp-config-sample.php' );
    46 } elseif ( file_exists( dirname( ABSPATH ) . '/wp-config-sample.php' ) ) {
    46 } elseif ( file_exists( dirname( ABSPATH ) . '/wp-config-sample.php' ) ) {
    47 	$config_file = file( dirname( ABSPATH ) . '/wp-config-sample.php' );
    47 	$config_file = file( dirname( ABSPATH ) . '/wp-config-sample.php' );
    48 } else {
    48 } else {
    49 	wp_die( sprintf(
    49 	wp_die(
    50 		/* translators: %s: wp-config-sample.php */
    50 		sprintf(
    51 		__( 'Sorry, I need a %s file to work from. Please re-upload this file to your WordPress installation.' ),
    51 			/* translators: %s: wp-config-sample.php */
    52 		'<code>wp-config-sample.php</code>'
    52 			__( 'Sorry, I need a %s file to work from. Please re-upload this file to your WordPress installation.' ),
    53 	) );
    53 			'<code>wp-config-sample.php</code>'
       
    54 		)
       
    55 	);
    54 }
    56 }
    55 
    57 
    56 // Check if wp-config.php has been created
    58 // Check if wp-config.php has been created
    57 if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
    59 if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
    58 	wp_die( '<p>' . sprintf(
    60 	wp_die(
    59 			/* translators: 1: wp-config.php 2: install.php */
    61 		'<p>' . sprintf(
       
    62 			/* translators: 1: wp-config.php, 2: install.php */
    60 			__( 'The file %1$s already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href="%2$s">installing now</a>.' ),
    63 			__( 'The file %1$s already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href="%2$s">installing now</a>.' ),
    61 			'<code>wp-config.php</code>',
    64 			'<code>wp-config.php</code>',
    62 			'install.php'
    65 			'install.php'
    63 		) . '</p>'
    66 		) . '</p>'
    64 	);
    67 	);
    65 }
    68 }
    66 
    69 
    67 // Check if wp-config.php exists above the root directory but is not part of another installation
    70 // Check if wp-config.php exists above the root directory but is not part of another installation
    68 if ( @file_exists( ABSPATH . '../wp-config.php' ) && ! @file_exists( ABSPATH . '../wp-settings.php' ) ) {
    71 if ( @file_exists( ABSPATH . '../wp-config.php' ) && ! @file_exists( ABSPATH . '../wp-settings.php' ) ) {
    69 	wp_die( '<p>' . sprintf(
    72 	wp_die(
    70 			/* translators: 1: wp-config.php 2: install.php */
    73 		'<p>' . sprintf(
       
    74 			/* translators: 1: wp-config.php, 2: install.php */
    71 			__( 'The file %1$s 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="%2$s">installing now</a>.' ),
    75 			__( 'The file %1$s 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="%2$s">installing now</a>.' ),
    72 			'<code>wp-config.php</code>',
    76 			'<code>wp-config.php</code>',
    73 			'install.php'
    77 			'install.php'
    74 		) . '</p>'
    78 		) . '</p>'
    75 	);
    79 	);
    87  * @global WP_Locale $wp_locale
    91  * @global WP_Locale $wp_locale
    88  *
    92  *
    89  * @param string|array $body_classes
    93  * @param string|array $body_classes
    90  */
    94  */
    91 function setup_config_display_header( $body_classes = array() ) {
    95 function setup_config_display_header( $body_classes = array() ) {
    92 	$body_classes = (array) $body_classes;
    96 	$body_classes   = (array) $body_classes;
    93 	$body_classes[] = 'wp-core-ui';
    97 	$body_classes[] = 'wp-core-ui';
       
    98 	$dir_attr       = '';
    94 	if ( is_rtl() ) {
    99 	if ( is_rtl() ) {
    95 		$body_classes[] = 'rtl';
   100 		$body_classes[] = 'rtl';
       
   101 		$dir_attr       = ' dir="rtl"';
    96 	}
   102 	}
    97 
   103 
    98 	header( 'Content-Type: text/html; charset=utf-8' );
   104 	header( 'Content-Type: text/html; charset=utf-8' );
    99 ?>
   105 	?>
   100 <!DOCTYPE html>
   106 <!DOCTYPE html>
   101 <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
   107 <html xmlns="http://www.w3.org/1999/xhtml"<?php echo $dir_attr; ?>>
   102 <head>
   108 <head>
   103 	<meta name="viewport" content="width=device-width" />
   109 	<meta name="viewport" content="width=device-width" />
   104 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   110 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   105 	<meta name="robots" content="noindex,nofollow" />
   111 	<meta name="robots" content="noindex,nofollow" />
   106 	<title><?php _e( 'WordPress &rsaquo; Setup Configuration File' ); ?></title>
   112 	<title><?php _e( 'WordPress &rsaquo; Setup Configuration File' ); ?></title>
   107 	<?php wp_admin_css( 'install', true ); ?>
   113 	<?php wp_admin_css( 'install', true ); ?>
   108 </head>
   114 </head>
   109 <body class="<?php echo implode( ' ', $body_classes ); ?>">
   115 <body class="<?php echo implode( ' ', $body_classes ); ?>">
   110 <p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>" tabindex="-1"><?php _e( 'WordPress' ); ?></a></p>
   116 <p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>"><?php _e( 'WordPress' ); ?></a></p>
   111 <?php
   117 	<?php
   112 } // end function setup_config_display_header();
   118 } // end function setup_config_display_header();
   113 
   119 
   114 $language = '';
   120 $language = '';
   115 if ( ! empty( $_REQUEST['language'] ) ) {
   121 if ( ! empty( $_REQUEST['language'] ) ) {
   116 	$language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] );
   122 	$language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] );
   117 } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
   123 } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
   118 	$language = $GLOBALS['wp_local_package'];
   124 	$language = $GLOBALS['wp_local_package'];
   119 }
   125 }
   120 
   126 
   121 switch($step) {
   127 switch ( $step ) {
   122 	case -1:
   128 	case -1:
   123 		if ( wp_can_install_language_pack() && empty( $language ) && ( $languages = wp_get_available_translations() ) ) {
   129 		if ( wp_can_install_language_pack() && empty( $language ) && ( $languages = wp_get_available_translations() ) ) {
   124 			setup_config_display_header( 'language-chooser' );
   130 			setup_config_display_header( 'language-chooser' );
   125 			echo '<h1 class="screen-reader-text">Select a default language</h1>';
   131 			echo '<h1 class="screen-reader-text">Select a default language</h1>';
   126 			echo '<form id="setup" method="post" action="?step=0">';
   132 			echo '<form id="setup" method="post" action="?step=0">';
   146 			$step_1 .= '&amp;noapi';
   152 			$step_1 .= '&amp;noapi';
   147 		}
   153 		}
   148 		if ( ! empty( $loaded_language ) ) {
   154 		if ( ! empty( $loaded_language ) ) {
   149 			$step_1 .= '&amp;language=' . $loaded_language;
   155 			$step_1 .= '&amp;language=' . $loaded_language;
   150 		}
   156 		}
   151 ?>
   157 		?>
   152 <h1 class="screen-reader-text"><?php _e( 'Before getting started' ) ?></h1>
   158 <h1 class="screen-reader-text"><?php _e( 'Before getting started' ); ?></h1>
   153 <p><?php _e( 'Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.' ) ?></p>
   159 <p><?php _e( 'Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.' ); ?></p>
   154 <ol>
   160 <ol>
   155 	<li><?php _e( 'Database name' ); ?></li>
   161 	<li><?php _e( 'Database name' ); ?></li>
   156 	<li><?php _e( 'Database username' ); ?></li>
   162 	<li><?php _e( 'Database username' ); ?></li>
   157 	<li><?php _e( 'Database password' ); ?></li>
   163 	<li><?php _e( 'Database password' ); ?></li>
   158 	<li><?php _e( 'Database host' ); ?></li>
   164 	<li><?php _e( 'Database host' ); ?></li>
   159 	<li><?php _e( 'Table prefix (if you want to run more than one WordPress in a single database)' ); ?></li>
   165 	<li><?php _e( 'Table prefix (if you want to run more than one WordPress in a single database)' ); ?></li>
   160 </ol>
   166 </ol>
   161 <p><?php
   167 <p>
   162 	/* translators: %s: wp-config.php */
   168 		<?php
   163 	printf( __( 'We&#8217;re going to use this information to create a %s file.' ),
   169 		/* translators: %s: wp-config.php */
   164 		'<code>wp-config.php</code>'
   170 		printf(
   165 	);
   171 			__( 'We&#8217;re going to use this information to create a %s file.' ),
   166 	?>
   172 			'<code>wp-config.php</code>'
   167 	<strong><?php
   173 		);
       
   174 		?>
       
   175 	<strong>
       
   176 		<?php
   168 		/* translators: 1: wp-config-sample.php, 2: wp-config.php */
   177 		/* translators: 1: wp-config-sample.php, 2: wp-config.php */
   169 		printf( __( 'If for any reason this automatic file creation doesn&#8217;t work, don&#8217;t worry. All this does is fill in the database information to a configuration file. You may also simply open %1$s in a text editor, fill in your information, and save it as %2$s.' ),
   178 		printf(
       
   179 			__( 'If for any reason this automatic file creation doesn&#8217;t work, don&#8217;t worry. All this does is fill in the database information to a configuration file. You may also simply open %1$s in a text editor, fill in your information, and save it as %2$s.' ),
   170 			'<code>wp-config-sample.php</code>',
   180 			'<code>wp-config-sample.php</code>',
   171 			'<code>wp-config.php</code>'
   181 			'<code>wp-config.php</code>'
   172 		);
   182 		);
   173 	?></strong>
   183 		?>
   174 	<?php
   184 	</strong>
   175 	/* translators: %s: Codex URL */
   185 		<?php
   176 	printf( __( 'Need more help? <a href="%s">We got it</a>.' ),
   186 		/* translators: %s: Codex URL */
   177 		__( 'https://codex.wordpress.org/Editing_wp-config.php' )
   187 		printf(
   178 	);
   188 			__( 'Need more help? <a href="%s">We got it</a>.' ),
   179 ?></p>
   189 			__( 'https://codex.wordpress.org/Editing_wp-config.php' )
       
   190 		);
       
   191 		?>
       
   192 </p>
   180 <p><?php _e( 'In all likelihood, these items were supplied to you by your Web Host. If you don&#8217;t have this information, then you will need to contact them before you can continue. If you&#8217;re all ready&hellip;' ); ?></p>
   193 <p><?php _e( 'In all likelihood, these items were supplied to you by your Web Host. If you don&#8217;t have this information, then you will need to contact them before you can continue. If you&#8217;re all ready&hellip;' ); ?></p>
   181 
   194 
   182 <p class="step"><a href="<?php echo $step_1; ?>" class="button button-large"><?php _e( 'Let&#8217;s go!' ); ?></a></p>
   195 <p class="step"><a href="<?php echo $step_1; ?>" class="button button-large"><?php _e( 'Let&#8217;s go!' ); ?></a></p>
   183 <?php
   196 		<?php
   184 	break;
   197 		break;
   185 
   198 
   186 	case 1:
   199 	case 1:
   187 		load_default_textdomain( $language );
   200 		load_default_textdomain( $language );
   188 		$GLOBALS['wp_locale'] = new WP_Locale();
   201 		$GLOBALS['wp_locale'] = new WP_Locale();
   189 
   202 
   190 		setup_config_display_header();
   203 		setup_config_display_header();
   191 	?>
   204 
   192 <h1 class="screen-reader-text"><?php _e( 'Set up your database connection' ) ?></h1>
   205 		$autofocus = wp_is_mobile() ? '' : ' autofocus';
       
   206 		?>
       
   207 <h1 class="screen-reader-text"><?php _e( 'Set up your database connection' ); ?></h1>
   193 <form method="post" action="setup-config.php?step=2">
   208 <form method="post" action="setup-config.php?step=2">
   194 	<p><?php _e( 'Below you should enter your database connection details. If you&#8217;re not sure about these, contact your host.' ); ?></p>
   209 	<p><?php _e( 'Below you should enter your database connection details. If you&#8217;re not sure about these, contact your host.' ); ?></p>
   195 	<table class="form-table">
   210 	<table class="form-table" role="presentation">
   196 		<tr>
   211 		<tr>
   197 			<th scope="row"><label for="dbname"><?php _e( 'Database Name' ); ?></label></th>
   212 			<th scope="row"><label for="dbname"><?php _e( 'Database Name' ); ?></label></th>
   198 			<td><input name="dbname" id="dbname" type="text" size="25" value="wordpress" /></td>
   213 			<td><input name="dbname" id="dbname" type="text" aria-describedby="dbname-desc" size="25" value="wordpress"<?php echo $autofocus; ?>/></td>
   199 			<td><?php _e( 'The name of the database you want to use with WordPress.' ); ?></td>
   214 			<td id="dbname-desc"><?php _e( 'The name of the database you want to use with WordPress.' ); ?></td>
   200 		</tr>
   215 		</tr>
   201 		<tr>
   216 		<tr>
   202 			<th scope="row"><label for="uname"><?php _e( 'Username' ); ?></label></th>
   217 			<th scope="row"><label for="uname"><?php _e( 'Username' ); ?></label></th>
   203 			<td><input name="uname" id="uname" type="text" size="25" value="<?php echo htmlspecialchars( _x( 'username', 'example username' ), ENT_QUOTES ); ?>" /></td>
   218 			<td><input name="uname" id="uname" type="text" aria-describedby="uname-desc" size="25" value="<?php echo htmlspecialchars( _x( 'username', 'example username' ), ENT_QUOTES ); ?>" /></td>
   204 			<td><?php _e( 'Your database username.' ); ?></td>
   219 			<td id="uname-desc"><?php _e( 'Your database username.' ); ?></td>
   205 		</tr>
   220 		</tr>
   206 		<tr>
   221 		<tr>
   207 			<th scope="row"><label for="pwd"><?php _e( 'Password' ); ?></label></th>
   222 			<th scope="row"><label for="pwd"><?php _e( 'Password' ); ?></label></th>
   208 			<td><input name="pwd" id="pwd" type="text" size="25" value="<?php echo htmlspecialchars( _x( 'password', 'example password' ), ENT_QUOTES ); ?>" autocomplete="off" /></td>
   223 			<td><input name="pwd" id="pwd" type="text" aria-describedby="pwd-desc" size="25" value="<?php echo htmlspecialchars( _x( 'password', 'example password' ), ENT_QUOTES ); ?>" autocomplete="off" /></td>
   209 			<td><?php _e( 'Your database password.' ); ?></td>
   224 			<td id="pwd-desc"><?php _e( 'Your database password.' ); ?></td>
   210 		</tr>
   225 		</tr>
   211 		<tr>
   226 		<tr>
   212 			<th scope="row"><label for="dbhost"><?php _e( 'Database Host' ); ?></label></th>
   227 			<th scope="row"><label for="dbhost"><?php _e( 'Database Host' ); ?></label></th>
   213 			<td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
   228 			<td><input name="dbhost" id="dbhost" type="text" aria-describedby="dbhost-desc" size="25" value="localhost" /></td>
   214 			<td><?php
   229 			<td id="dbhost-desc">
       
   230 			<?php
   215 				/* translators: %s: localhost */
   231 				/* translators: %s: localhost */
   216 				printf( __( 'You should be able to get this info from your web host, if %s doesn&#8217;t work.' ),'<code>localhost</code>' );
   232 				printf( __( 'You should be able to get this info from your web host, if %s doesn&#8217;t work.' ), '<code>localhost</code>' );
   217 			?></td>
   233 			?>
       
   234 			</td>
   218 		</tr>
   235 		</tr>
   219 		<tr>
   236 		<tr>
   220 			<th scope="row"><label for="prefix"><?php _e( 'Table Prefix' ); ?></label></th>
   237 			<th scope="row"><label for="prefix"><?php _e( 'Table Prefix' ); ?></label></th>
   221 			<td><input name="prefix" id="prefix" type="text" value="wp_" size="25" /></td>
   238 			<td><input name="prefix" id="prefix" type="text" aria-describedby="prefix-desc" value="wp_" size="25" /></td>
   222 			<td><?php _e( 'If you want to run multiple WordPress installations in a single database, change this.' ); ?></td>
   239 			<td id="prefix-desc"><?php _e( 'If you want to run multiple WordPress installations in a single database, change this.' ); ?></td>
   223 		</tr>
   240 		</tr>
   224 	</table>
   241 	</table>
   225 	<?php if ( isset( $_GET['noapi'] ) ) { ?><input name="noapi" type="hidden" value="1" /><?php } ?>
   242 		<?php
       
   243 		if ( isset( $_GET['noapi'] ) ) {
       
   244 			?>
       
   245 <input name="noapi" type="hidden" value="1" /><?php } ?>
   226 	<input type="hidden" name="language" value="<?php echo esc_attr( $language ); ?>" />
   246 	<input type="hidden" name="language" value="<?php echo esc_attr( $language ); ?>" />
   227 	<p class="step"><input name="submit" type="submit" value="<?php echo htmlspecialchars( __( 'Submit' ), ENT_QUOTES ); ?>" class="button button-large" /></p>
   247 	<p class="step"><input name="submit" type="submit" value="<?php echo htmlspecialchars( __( 'Submit' ), ENT_QUOTES ); ?>" class="button button-large" /></p>
   228 </form>
   248 </form>
   229 <?php
   249 		<?php
   230 	break;
   250 		break;
   231 
   251 
   232 	case 2:
   252 	case 2:
   233 	load_default_textdomain( $language );
   253 		load_default_textdomain( $language );
   234 	$GLOBALS['wp_locale'] = new WP_Locale();
   254 		$GLOBALS['wp_locale'] = new WP_Locale();
   235 
   255 
   236 	$dbname = trim( wp_unslash( $_POST[ 'dbname' ] ) );
   256 		$dbname = trim( wp_unslash( $_POST['dbname'] ) );
   237 	$uname = trim( wp_unslash( $_POST[ 'uname' ] ) );
   257 		$uname  = trim( wp_unslash( $_POST['uname'] ) );
   238 	$pwd = trim( wp_unslash( $_POST[ 'pwd' ] ) );
   258 		$pwd    = trim( wp_unslash( $_POST['pwd'] ) );
   239 	$dbhost = trim( wp_unslash( $_POST[ 'dbhost' ] ) );
   259 		$dbhost = trim( wp_unslash( $_POST['dbhost'] ) );
   240 	$prefix = trim( wp_unslash( $_POST[ 'prefix' ] ) );
   260 		$prefix = trim( wp_unslash( $_POST['prefix'] ) );
   241 
   261 
   242 	$step_1 = 'setup-config.php?step=1';
   262 		$step_1  = 'setup-config.php?step=1';
   243 	$install = 'install.php';
   263 		$install = 'install.php';
   244 	if ( isset( $_REQUEST['noapi'] ) ) {
   264 		if ( isset( $_REQUEST['noapi'] ) ) {
   245 		$step_1 .= '&amp;noapi';
   265 			$step_1 .= '&amp;noapi';
   246 	}
   266 		}
   247 
   267 
   248 	if ( ! empty( $language ) ) {
   268 		if ( ! empty( $language ) ) {
   249 		$step_1 .= '&amp;language=' . $language;
   269 			$step_1  .= '&amp;language=' . $language;
   250 		$install .= '?language=' . $language;
   270 			$install .= '?language=' . $language;
   251 	} else {
   271 		} else {
   252 		$install .= '?language=en_US';
   272 			$install .= '?language=en_US';
   253 	}
   273 		}
   254 
   274 
   255 	$tryagain_link = '</p><p class="step"><a href="' . $step_1 . '" onclick="javascript:history.go(-1);return false;" class="button button-large">' . __( 'Try again' ) . '</a>';
   275 		$tryagain_link = '</p><p class="step"><a href="' . $step_1 . '" onclick="javascript:history.go(-1);return false;" class="button button-large">' . __( 'Try again' ) . '</a>';
   256 
   276 
   257 	if ( empty( $prefix ) )
   277 		if ( empty( $prefix ) ) {
   258 		wp_die( __( '<strong>ERROR</strong>: "Table Prefix" must not be empty.' . $tryagain_link ) );
   278 			wp_die( __( '<strong>ERROR</strong>: "Table Prefix" must not be empty.' ) . $tryagain_link );
   259 
   279 		}
   260 	// Validate $prefix: it can only contain letters, numbers and underscores.
   280 
   261 	if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
   281 		// Validate $prefix: it can only contain letters, numbers and underscores.
   262 		wp_die( __( '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' . $tryagain_link ) );
   282 		if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) {
   263 
   283 			wp_die( __( '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' ) . $tryagain_link );
   264 	// Test the db connection.
   284 		}
   265 	/**#@+
   285 
   266 	 * @ignore
   286 		// Test the db connection.
   267 	 */
   287 		/**#@+
   268 	define('DB_NAME', $dbname);
   288 		 *
   269 	define('DB_USER', $uname);
   289 		 * @ignore
   270 	define('DB_PASSWORD', $pwd);
   290 		 */
   271 	define('DB_HOST', $dbhost);
   291 		define( 'DB_NAME', $dbname );
   272 	/**#@-*/
   292 		define( 'DB_USER', $uname );
   273 
   293 		define( 'DB_PASSWORD', $pwd );
   274 	// Re-construct $wpdb with these new values.
   294 		define( 'DB_HOST', $dbhost );
   275 	unset( $wpdb );
   295 		/**#@-*/
   276 	require_wp_db();
   296 
   277 
   297 		// Re-construct $wpdb with these new values.
   278 	/*
   298 		unset( $wpdb );
   279 	 * The wpdb constructor bails when WP_SETUP_CONFIG is set, so we must
   299 		require_wp_db();
   280 	 * fire this manually. We'll fail here if the values are no good.
   300 
   281 	 */
   301 		/*
   282 	$wpdb->db_connect();
   302 		* The wpdb constructor bails when WP_SETUP_CONFIG is set, so we must
   283 
   303 		* fire this manually. We'll fail here if the values are no good.
   284 	if ( ! empty( $wpdb->error ) )
   304 		*/
   285 		wp_die( $wpdb->error->get_error_message() . $tryagain_link );
   305 		$wpdb->db_connect();
   286 
   306 
   287 	$errors = $wpdb->hide_errors();
   307 		if ( ! empty( $wpdb->error ) ) {
   288 	$wpdb->query( "SELECT $prefix" );
   308 			wp_die( $wpdb->error->get_error_message() . $tryagain_link );
   289 	$wpdb->show_errors( $errors );
   309 		}
   290 	if ( ! $wpdb->last_error ) {
   310 
   291 		// MySQL was able to parse the prefix as a value, which we don't want. Bail.
   311 		$errors = $wpdb->hide_errors();
   292 		wp_die( __( '<strong>ERROR</strong>: "Table Prefix" is invalid.' ) );
   312 		$wpdb->query( "SELECT $prefix" );
   293 	}
   313 		$wpdb->show_errors( $errors );
   294 
   314 		if ( ! $wpdb->last_error ) {
   295 	// Generate keys and salts using secure CSPRNG; fallback to API if enabled; further fallback to original wp_generate_password().
   315 			// MySQL was able to parse the prefix as a value, which we don't want. Bail.
   296 	try {
   316 			wp_die( __( '<strong>ERROR</strong>: "Table Prefix" is invalid.' ) );
   297 		$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
   317 		}
   298 		$max = strlen($chars) - 1;
   318 
   299 		for ( $i = 0; $i < 8; $i++ ) {
   319 		// Generate keys and salts using secure CSPRNG; fallback to API if enabled; further fallback to original wp_generate_password().
   300 			$key = '';
   320 		try {
   301 			for ( $j = 0; $j < 64; $j++ ) {
   321 			$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
   302 				$key .= substr( $chars, random_int( 0, $max ), 1 );
   322 			$max   = strlen( $chars ) - 1;
   303 			}
       
   304 			$secret_keys[] = $key;
       
   305 		}
       
   306 	} catch ( Exception $ex ) {
       
   307 		$no_api = isset( $_POST['noapi'] );
       
   308 
       
   309 		if ( ! $no_api ) {
       
   310 			$secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
       
   311 		}
       
   312 
       
   313 		if ( $no_api || is_wp_error( $secret_keys ) ) {
       
   314 			$secret_keys = array();
       
   315 			for ( $i = 0; $i < 8; $i++ ) {
   323 			for ( $i = 0; $i < 8; $i++ ) {
   316 				$secret_keys[] = wp_generate_password( 64, true, true );
   324 				$key = '';
   317 			}
   325 				for ( $j = 0; $j < 64; $j++ ) {
   318 		} else {
   326 					$key .= substr( $chars, random_int( 0, $max ), 1 );
   319 			$secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) );
       
   320 			foreach ( $secret_keys as $k => $v ) {
       
   321 				$secret_keys[$k] = substr( $v, 28, 64 );
       
   322 			}
       
   323 		}
       
   324 	}
       
   325 
       
   326 	$key = 0;
       
   327 	foreach ( $config_file as $line_num => $line ) {
       
   328 		if ( '$table_prefix  =' == substr( $line, 0, 16 ) ) {
       
   329 			$config_file[ $line_num ] = '$table_prefix  = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n";
       
   330 			continue;
       
   331 		}
       
   332 
       
   333 		if ( ! preg_match( '/^define\(\'([A-Z_]+)\',([ ]+)/', $line, $match ) )
       
   334 			continue;
       
   335 
       
   336 		$constant = $match[1];
       
   337 		$padding  = $match[2];
       
   338 
       
   339 		switch ( $constant ) {
       
   340 			case 'DB_NAME'     :
       
   341 			case 'DB_USER'     :
       
   342 			case 'DB_PASSWORD' :
       
   343 			case 'DB_HOST'     :
       
   344 				$config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "');\r\n";
       
   345 				break;
       
   346 			case 'DB_CHARSET'  :
       
   347 				if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset && $wpdb->has_cap( 'utf8mb4' ) ) ) {
       
   348 					$config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'utf8mb4');\r\n";
       
   349 				}
   327 				}
   350 				break;
   328 				$secret_keys[] = $key;
   351 			case 'AUTH_KEY'         :
   329 			}
   352 			case 'SECURE_AUTH_KEY'  :
   330 		} catch ( Exception $ex ) {
   353 			case 'LOGGED_IN_KEY'    :
   331 			$no_api = isset( $_POST['noapi'] );
   354 			case 'NONCE_KEY'        :
   332 
   355 			case 'AUTH_SALT'        :
   333 			if ( ! $no_api ) {
   356 			case 'SECURE_AUTH_SALT' :
   334 				$secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
   357 			case 'LOGGED_IN_SALT'   :
   335 			}
   358 			case 'NONCE_SALT'       :
   336 
   359 				$config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'" . $secret_keys[$key++] . "');\r\n";
   337 			if ( $no_api || is_wp_error( $secret_keys ) ) {
   360 				break;
   338 				$secret_keys = array();
   361 		}
   339 				for ( $i = 0; $i < 8; $i++ ) {
   362 	}
   340 					$secret_keys[] = wp_generate_password( 64, true, true );
   363 	unset( $line );
   341 				}
   364 
   342 			} else {
   365 	if ( ! is_writable(ABSPATH) ) :
   343 				$secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) );
   366 		setup_config_display_header();
   344 				foreach ( $secret_keys as $k => $v ) {
   367 ?>
   345 					$secret_keys[ $k ] = substr( $v, 28, 64 );
   368 <p><?php
   346 				}
   369 	/* translators: %s: wp-config.php */
   347 			}
   370 	printf( __( 'Sorry, but I can&#8217;t write the %s file.' ), '<code>wp-config.php</code>' );
   348 		}
   371 ?></p>
   349 
   372 <p><?php
   350 		$key = 0;
   373 	/* translators: %s: wp-config.php */
   351 		foreach ( $config_file as $line_num => $line ) {
   374 	printf( __( 'You can create the %s file manually and paste the following text into it.' ), '<code>wp-config.php</code>' );
   352 			if ( '$table_prefix =' == substr( $line, 0, 15 ) ) {
   375 ?></p>
   353 				$config_file[ $line_num ] = '$table_prefix = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n";
   376 <textarea id="wp-config" cols="98" rows="15" class="code" readonly="readonly"><?php
   354 				continue;
   377 		foreach ( $config_file as $line ) {
   355 			}
   378 			echo htmlentities($line, ENT_COMPAT, 'UTF-8');
   356 
   379 		}
   357 			if ( ! preg_match( '/^define\(\s*\'([A-Z_]+)\',([ ]+)/', $line, $match ) ) {
   380 ?></textarea>
   358 				continue;
       
   359 			}
       
   360 
       
   361 			$constant = $match[1];
       
   362 			$padding  = $match[2];
       
   363 
       
   364 			switch ( $constant ) {
       
   365 				case 'DB_NAME':
       
   366 				case 'DB_USER':
       
   367 				case 'DB_PASSWORD':
       
   368 				case 'DB_HOST':
       
   369 					$config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "' );\r\n";
       
   370 					break;
       
   371 				case 'DB_CHARSET':
       
   372 					if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset && $wpdb->has_cap( 'utf8mb4' ) ) ) {
       
   373 						$config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'utf8mb4' );\r\n";
       
   374 					}
       
   375 					break;
       
   376 				case 'AUTH_KEY':
       
   377 				case 'SECURE_AUTH_KEY':
       
   378 				case 'LOGGED_IN_KEY':
       
   379 				case 'NONCE_KEY':
       
   380 				case 'AUTH_SALT':
       
   381 				case 'SECURE_AUTH_SALT':
       
   382 				case 'LOGGED_IN_SALT':
       
   383 				case 'NONCE_SALT':
       
   384 					$config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'" . $secret_keys[ $key++ ] . "' );\r\n";
       
   385 					break;
       
   386 			}
       
   387 		}
       
   388 		unset( $line );
       
   389 
       
   390 		if ( ! is_writable( ABSPATH ) ) :
       
   391 			setup_config_display_header();
       
   392 			?>
       
   393 	<p>
       
   394 			<?php
       
   395 			/* translators: %s: wp-config.php */
       
   396 			printf( __( 'Sorry, but I can&#8217;t write the %s file.' ), '<code>wp-config.php</code>' );
       
   397 			?>
       
   398 </p>
       
   399 <p>
       
   400 			<?php
       
   401 			/* translators: %s: wp-config.php */
       
   402 			printf( __( 'You can create the %s file manually and paste the following text into it.' ), '<code>wp-config.php</code>' );
       
   403 
       
   404 			$config_text = '';
       
   405 
       
   406 			foreach ( $config_file as $line ) {
       
   407 				$config_text .= htmlentities( $line, ENT_COMPAT, 'UTF-8' );
       
   408 			}
       
   409 			?>
       
   410 </p>
       
   411 <textarea id="wp-config" cols="98" rows="15" class="code" readonly="readonly"><?php echo $config_text; ?></textarea>
   381 <p><?php _e( 'After you&#8217;ve done that, click &#8220;Run the installation.&#8221;' ); ?></p>
   412 <p><?php _e( 'After you&#8217;ve done that, click &#8220;Run the installation.&#8221;' ); ?></p>
   382 <p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the installation' ); ?></a></p>
   413 <p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the installation' ); ?></a></p>
   383 <script>
   414 <script>
   384 (function(){
   415 (function(){
   385 if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) {
   416 if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) {
   387 	el.focus();
   418 	el.focus();
   388 	el.select();
   419 	el.select();
   389 }
   420 }
   390 })();
   421 })();
   391 </script>
   422 </script>
   392 <?php
   423 			<?php
   393 	else :
   424 	else :
   394 		/*
   425 		/*
   395 		 * If this file doesn't exist, then we are using the wp-config-sample.php
   426 		 * If this file doesn't exist, then we are using the wp-config-sample.php
   396 		 * file one level up, which is for the develop repo.
   427 		 * file one level up, which is for the develop repo.
   397 		 */
   428 		 */
   398 		if ( file_exists( ABSPATH . 'wp-config-sample.php' ) )
   429 		if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) {
   399 			$path_to_wp_config = ABSPATH . 'wp-config.php';
   430 			$path_to_wp_config = ABSPATH . 'wp-config.php';
   400 		else
   431 		} else {
   401 			$path_to_wp_config = dirname( ABSPATH ) . '/wp-config.php';
   432 			$path_to_wp_config = dirname( ABSPATH ) . '/wp-config.php';
       
   433 		}
   402 
   434 
   403 		$handle = fopen( $path_to_wp_config, 'w' );
   435 		$handle = fopen( $path_to_wp_config, 'w' );
   404 		foreach ( $config_file as $line ) {
   436 		foreach ( $config_file as $line ) {
   405 			fwrite( $handle, $line );
   437 			fwrite( $handle, $line );
   406 		}
   438 		}
   407 		fclose( $handle );
   439 		fclose( $handle );
   408 		chmod( $path_to_wp_config, 0666 );
   440 		chmod( $path_to_wp_config, 0666 );
   409 		setup_config_display_header();
   441 		setup_config_display_header();
   410 ?>
   442 		?>
   411 <h1 class="screen-reader-text"><?php _e( 'Successful database connection' ) ?></h1>
   443 <h1 class="screen-reader-text"><?php _e( 'Successful database connection' ); ?></h1>
   412 <p><?php _e( 'All right, sparky! You&#8217;ve made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to&hellip;' ); ?></p>
   444 <p><?php _e( 'All right, sparky! You&#8217;ve made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to&hellip;' ); ?></p>
   413 
   445 
   414 <p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the installation' ); ?></a></p>
   446 <p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the installation' ); ?></a></p>
   415 <?php
   447 		<?php
   416 	endif;
   448 	endif;
   417 	break;
   449 		break;
   418 }
   450 }
   419 ?>
   451 ?>
   420 <?php wp_print_scripts( 'language-chooser' ); ?>
   452 <?php wp_print_scripts( 'language-chooser' ); ?>
   421 </body>
   453 </body>
   422 </html>
   454 </html>