wp/wp-admin/setup-config.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    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( __DIR__ ) . '/' );
    31 }
    31 }
    32 
    32 
    33 require( ABSPATH . 'wp-settings.php' );
    33 require ABSPATH . 'wp-settings.php';
    34 
    34 
    35 /** Load WordPress Administration Upgrade API */
    35 /** Load WordPress Administration Upgrade API */
    36 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    36 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    37 
    37 
    38 /** Load WordPress Translation Installation API */
    38 /** Load WordPress Translation Installation API */
    39 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
    39 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
    40 
    40 
    41 nocache_headers();
    41 nocache_headers();
    42 
    42 
    43 // Support wp-config-sample.php one level up, for the develop repo.
    43 // Support wp-config-sample.php one level up, for the develop repo.
    44 if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) {
    44 if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) {
    53 			'<code>wp-config-sample.php</code>'
    53 			'<code>wp-config-sample.php</code>'
    54 		)
    54 		)
    55 	);
    55 	);
    56 }
    56 }
    57 
    57 
    58 // Check if wp-config.php has been created
    58 // Check if wp-config.php has been created.
    59 if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
    59 if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
    60 	wp_die(
    60 	wp_die(
    61 		'<p>' . sprintf(
    61 		'<p>' . sprintf(
    62 			/* translators: 1: wp-config.php, 2: install.php */
    62 			/* translators: 1: wp-config.php, 2: install.php */
    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>.' ),
    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>.' ),
    64 			'<code>wp-config.php</code>',
    64 			'<code>wp-config.php</code>',
    65 			'install.php'
    65 			'install.php'
    66 		) . '</p>'
    66 		) . '</p>',
       
    67 		409
    67 	);
    68 	);
    68 }
    69 }
    69 
    70 
    70 // Check if wp-config.php exists above the root directory but is not part of another installation
    71 // Check if wp-config.php exists above the root directory but is not part of another installation.
    71 if ( @file_exists( ABSPATH . '../wp-config.php' ) && ! @file_exists( ABSPATH . '../wp-settings.php' ) ) {
    72 if ( @file_exists( ABSPATH . '../wp-config.php' ) && ! @file_exists( ABSPATH . '../wp-settings.php' ) ) {
    72 	wp_die(
    73 	wp_die(
    73 		'<p>' . sprintf(
    74 		'<p>' . sprintf(
    74 			/* translators: 1: wp-config.php, 2: install.php */
    75 			/* translators: 1: wp-config.php, 2: install.php */
    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>.' ),
    76 			__( '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>.' ),
    76 			'<code>wp-config.php</code>',
    77 			'<code>wp-config.php</code>',
    77 			'install.php'
    78 			'install.php'
    78 		) . '</p>'
    79 		) . '</p>',
       
    80 		409
    79 	);
    81 	);
    80 }
    82 }
    81 
    83 
    82 $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : -1;
    84 $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : -1;
    83 
    85 
    85  * Display setup wp-config.php file header.
    87  * Display setup wp-config.php file header.
    86  *
    88  *
    87  * @ignore
    89  * @ignore
    88  * @since 2.3.0
    90  * @since 2.3.0
    89  *
    91  *
    90  * @global string    $wp_local_package
    92  * @global string    $wp_local_package Locale code of the package.
    91  * @global WP_Locale $wp_locale
    93  * @global WP_Locale $wp_locale        WordPress date and time locale object.
    92  *
    94  *
    93  * @param string|array $body_classes
    95  * @param string|array $body_classes
    94  */
    96  */
    95 function setup_config_display_header( $body_classes = array() ) {
    97 function setup_config_display_header( $body_classes = array() ) {
    96 	$body_classes   = (array) $body_classes;
    98 	$body_classes   = (array) $body_classes;
   102 	}
   104 	}
   103 
   105 
   104 	header( 'Content-Type: text/html; charset=utf-8' );
   106 	header( 'Content-Type: text/html; charset=utf-8' );
   105 	?>
   107 	?>
   106 <!DOCTYPE html>
   108 <!DOCTYPE html>
   107 <html xmlns="http://www.w3.org/1999/xhtml"<?php echo $dir_attr; ?>>
   109 <html<?php echo $dir_attr; ?>>
   108 <head>
   110 <head>
   109 	<meta name="viewport" content="width=device-width" />
   111 	<meta name="viewport" content="width=device-width" />
   110 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   112 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   111 	<meta name="robots" content="noindex,nofollow" />
   113 	<meta name="robots" content="noindex,nofollow" />
   112 	<title><?php _e( 'WordPress &rsaquo; Setup Configuration File' ); ?></title>
   114 	<title><?php _e( 'WordPress &rsaquo; Setup Configuration File' ); ?></title>
   113 	<?php wp_admin_css( 'install', true ); ?>
   115 	<?php wp_admin_css( 'install', true ); ?>
   114 </head>
   116 </head>
   115 <body class="<?php echo implode( ' ', $body_classes ); ?>">
   117 <body class="<?php echo implode( ' ', $body_classes ); ?>">
   116 <p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>"><?php _e( 'WordPress' ); ?></a></p>
   118 <p id="logo"><?php _e( 'WordPress' ); ?></p>
   117 	<?php
   119 	<?php
   118 } // end function setup_config_display_header();
   120 } // End function setup_config_display_header();
   119 
   121 
   120 $language = '';
   122 $language = '';
   121 if ( ! empty( $_REQUEST['language'] ) ) {
   123 if ( ! empty( $_REQUEST['language'] ) ) {
   122 	$language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] );
   124 	$language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] );
   123 } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
   125 } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
   124 	$language = $GLOBALS['wp_local_package'];
   126 	$language = $GLOBALS['wp_local_package'];
   125 }
   127 }
   126 
   128 
   127 switch ( $step ) {
   129 switch ( $step ) {
   128 	case -1:
   130 	case -1:
   129 		if ( wp_can_install_language_pack() && empty( $language ) && ( $languages = wp_get_available_translations() ) ) {
   131 		if ( wp_can_install_language_pack() && empty( $language ) ) {
   130 			setup_config_display_header( 'language-chooser' );
   132 			$languages = wp_get_available_translations();
   131 			echo '<h1 class="screen-reader-text">Select a default language</h1>';
   133 			if ( $languages ) {
   132 			echo '<form id="setup" method="post" action="?step=0">';
   134 				setup_config_display_header( 'language-chooser' );
   133 			wp_install_language_form( $languages );
   135 				echo '<h1 class="screen-reader-text">Select a default language</h1>';
   134 			echo '</form>';
   136 				echo '<form id="setup" method="post" action="?step=0">';
   135 			break;
   137 				wp_install_language_form( $languages );
       
   138 				echo '</form>';
       
   139 				break;
       
   140 			}
   136 		}
   141 		}
   137 
   142 
   138 		// Deliberately fall through if we can't reach the translations API.
   143 		// Deliberately fall through if we can't reach the translations API.
   139 
   144 
   140 	case 0:
   145 	case 0:
   164 	<li><?php _e( 'Database host' ); ?></li>
   169 	<li><?php _e( 'Database host' ); ?></li>
   165 	<li><?php _e( 'Table prefix (if you want to run more than one WordPress in a single database)' ); ?></li>
   170 	<li><?php _e( 'Table prefix (if you want to run more than one WordPress in a single database)' ); ?></li>
   166 </ol>
   171 </ol>
   167 <p>
   172 <p>
   168 		<?php
   173 		<?php
   169 		/* translators: %s: wp-config.php */
       
   170 		printf(
   174 		printf(
       
   175 			/* translators: %s: wp-config.php */
   171 			__( 'We&#8217;re going to use this information to create a %s file.' ),
   176 			__( 'We&#8217;re going to use this information to create a %s file.' ),
   172 			'<code>wp-config.php</code>'
   177 			'<code>wp-config.php</code>'
   173 		);
   178 		);
   174 		?>
   179 		?>
   175 	<strong>
   180 	<strong>
   176 		<?php
   181 		<?php
   177 		/* translators: 1: wp-config-sample.php, 2: wp-config.php */
       
   178 		printf(
   182 		printf(
       
   183 			/* translators: 1: wp-config-sample.php, 2: wp-config.php */
   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.' ),
   184 			__( '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.' ),
   180 			'<code>wp-config-sample.php</code>',
   185 			'<code>wp-config-sample.php</code>',
   181 			'<code>wp-config.php</code>'
   186 			'<code>wp-config.php</code>'
   182 		);
   187 		);
   183 		?>
   188 		?>
   184 	</strong>
   189 	</strong>
   185 		<?php
   190 		<?php
   186 		/* translators: %s: Codex URL */
       
   187 		printf(
   191 		printf(
       
   192 			/* translators: %s: Documentation URL. */
   188 			__( 'Need more help? <a href="%s">We got it</a>.' ),
   193 			__( 'Need more help? <a href="%s">We got it</a>.' ),
   189 			__( 'https://codex.wordpress.org/Editing_wp-config.php' )
   194 			__( 'https://wordpress.org/support/article/editing-wp-config-php/' )
   190 		);
   195 		);
   191 		?>
   196 		?>
   192 </p>
   197 </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>
   198 <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>
   194 
   199 
   270 			$install .= '?language=' . $language;
   275 			$install .= '?language=' . $language;
   271 		} else {
   276 		} else {
   272 			$install .= '?language=en_US';
   277 			$install .= '?language=en_US';
   273 		}
   278 		}
   274 
   279 
   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>';
   280 		$tryagain_link = '</p><p class="step"><a href="' . $step_1 . '" onclick="javascript:history.go(-1);return false;" class="button button-large">' . __( 'Try Again' ) . '</a>';
   276 
   281 
   277 		if ( empty( $prefix ) ) {
   282 		if ( empty( $prefix ) ) {
   278 			wp_die( __( '<strong>ERROR</strong>: "Table Prefix" must not be empty.' ) . $tryagain_link );
   283 			wp_die( __( '<strong>Error</strong>: "Table Prefix" must not be empty.' ) . $tryagain_link );
   279 		}
   284 		}
   280 
   285 
   281 		// Validate $prefix: it can only contain letters, numbers and underscores.
   286 		// Validate $prefix: it can only contain letters, numbers and underscores.
   282 		if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) {
   287 		if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) {
   283 			wp_die( __( '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' ) . $tryagain_link );
   288 			wp_die( __( '<strong>Error</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' ) . $tryagain_link );
   284 		}
   289 		}
   285 
   290 
   286 		// Test the db connection.
   291 		// Test the DB connection.
   287 		/**#@+
   292 		/**#@+
   288 		 *
   293 		 *
   289 		 * @ignore
   294 		 * @ignore
   290 		 */
   295 		 */
   291 		define( 'DB_NAME', $dbname );
   296 		define( 'DB_NAME', $dbname );
   311 		$errors = $wpdb->hide_errors();
   316 		$errors = $wpdb->hide_errors();
   312 		$wpdb->query( "SELECT $prefix" );
   317 		$wpdb->query( "SELECT $prefix" );
   313 		$wpdb->show_errors( $errors );
   318 		$wpdb->show_errors( $errors );
   314 		if ( ! $wpdb->last_error ) {
   319 		if ( ! $wpdb->last_error ) {
   315 			// MySQL was able to parse the prefix as a value, which we don't want. Bail.
   320 			// MySQL was able to parse the prefix as a value, which we don't want. Bail.
   316 			wp_die( __( '<strong>ERROR</strong>: "Table Prefix" is invalid.' ) );
   321 			wp_die( __( '<strong>Error</strong>: "Table Prefix" is invalid.' ) );
   317 		}
   322 		}
   318 
   323 
   319 		// Generate keys and salts using secure CSPRNG; fallback to API if enabled; further fallback to original wp_generate_password().
   324 		// Generate keys and salts using secure CSPRNG; fallback to API if enabled; further fallback to original wp_generate_password().
   320 		try {
   325 		try {
   321 			$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
   326 			$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
   347 			}
   352 			}
   348 		}
   353 		}
   349 
   354 
   350 		$key = 0;
   355 		$key = 0;
   351 		foreach ( $config_file as $line_num => $line ) {
   356 		foreach ( $config_file as $line_num => $line ) {
   352 			if ( '$table_prefix =' == substr( $line, 0, 15 ) ) {
   357 			if ( '$table_prefix =' === substr( $line, 0, 15 ) ) {
   353 				$config_file[ $line_num ] = '$table_prefix = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n";
   358 				$config_file[ $line_num ] = '$table_prefix = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n";
   354 				continue;
   359 				continue;
   355 			}
   360 			}
   356 
   361 
   357 			if ( ! preg_match( '/^define\(\s*\'([A-Z_]+)\',([ ]+)/', $line, $match ) ) {
   362 			if ( ! preg_match( '/^define\(\s*\'([A-Z_]+)\',([ ]+)/', $line, $match ) ) {
   391 			setup_config_display_header();
   396 			setup_config_display_header();
   392 			?>
   397 			?>
   393 	<p>
   398 	<p>
   394 			<?php
   399 			<?php
   395 			/* translators: %s: wp-config.php */
   400 			/* translators: %s: wp-config.php */
   396 			printf( __( 'Sorry, but I can&#8217;t write the %s file.' ), '<code>wp-config.php</code>' );
   401 			printf( __( 'Unable to write to %s file.' ), '<code>wp-config.php</code>' );
   397 			?>
   402 			?>
   398 </p>
   403 </p>
   399 <p>
   404 <p>
   400 			<?php
   405 			<?php
   401 			/* translators: %s: wp-config.php */
   406 			/* translators: %s: wp-config.php */
   407 				$config_text .= htmlentities( $line, ENT_COMPAT, 'UTF-8' );
   412 				$config_text .= htmlentities( $line, ENT_COMPAT, 'UTF-8' );
   408 			}
   413 			}
   409 			?>
   414 			?>
   410 </p>
   415 </p>
   411 <textarea id="wp-config" cols="98" rows="15" class="code" readonly="readonly"><?php echo $config_text; ?></textarea>
   416 <textarea id="wp-config" cols="98" rows="15" class="code" readonly="readonly"><?php echo $config_text; ?></textarea>
   412 <p><?php _e( 'After you&#8217;ve done that, click &#8220;Run the installation.&#8221;' ); ?></p>
   417 <p><?php _e( 'After you&#8217;ve done that, click &#8220;Run the installation&#8221;.' ); ?></p>
   413 <p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the installation' ); ?></a></p>
   418 <p class="step"><a href="<?php echo $install; ?>" class="button button-large"><?php _e( 'Run the installation' ); ?></a></p>
   414 <script>
   419 <script>
   415 (function(){
   420 (function(){
   416 if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) {
   421 if ( ! /iPad|iPod|iPhone/.test( navigator.userAgent ) ) {
   417 	var el = document.getElementById('wp-config');
   422 	var el = document.getElementById('wp-config');