Skip to content

Commit a7c3b23

Browse files
committed
Simplify the setup-config.php UI flow and load process.
When no configuration file is detected, we now redirect to setup-config.php. This process now uses the WordPress bootstrap, rather than a set of fragile hacks. fixes #28740. git-svn-id: https://develop.svn.wordpress.org/trunk@28978 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 26e262f commit a7c3b23

6 files changed

Lines changed: 41 additions & 55 deletions

File tree

src/wp-admin/load-scripts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Disable error reporting
55
*
6-
* Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging
6+
* Set this to error_reporting( -1 ) for debugging
77
*/
88
error_reporting(0);
99

src/wp-admin/load-styles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Disable error reporting
55
*
6-
* Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging
6+
* Set this to error_reporting( -1 ) for debugging
77
*/
88
error_reporting(0);
99

src/wp-admin/setup-config.php

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,15 @@
2424
/**
2525
* Disable error reporting
2626
*
27-
* Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging
27+
* Set this to error_reporting( -1 ) for debugging
2828
*/
29-
error_reporting(0);
29+
error_reporting(-1);
3030

31-
/**#@+
32-
* These three defines are required to allow us to use require_wp_db() to load
33-
* the database class while being wp-content/db.php aware.
34-
* @ignore
35-
*/
36-
define('ABSPATH', dirname(dirname(__FILE__)).'/');
37-
define('WPINC', 'wp-includes');
38-
define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
39-
define('WP_DEBUG', false);
40-
/**#@-*/
41-
42-
require(ABSPATH . WPINC . '/load.php');
43-
require(ABSPATH . WPINC . '/version.php');
44-
45-
// Check for the required PHP version and for the MySQL extension or a database drop-in.
46-
wp_check_php_mysql_versions();
47-
48-
require_once(ABSPATH . WPINC . '/functions.php');
49-
50-
// Also loads plugin.php, l10n.php, pomo/mo.php (all required by setup-config.php)
51-
wp_load_translations_early();
31+
define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' );
5232

53-
// Turn register_globals off.
54-
wp_unregister_GLOBALS();
55-
56-
// Standardize $_SERVER variables across setups.
57-
wp_fix_server_vars();
58-
59-
require_once(ABSPATH . WPINC . '/compat.php');
60-
require_once(ABSPATH . WPINC . '/class-wp-error.php');
61-
require_once(ABSPATH . WPINC . '/formatting.php');
62-
63-
// Add magic quotes and set up $_REQUEST ( $_GET + $_POST )
64-
wp_magic_quotes();
33+
require_once( ABSPATH . 'wp-includes/plugin.php' );
34+
add_action( 'plugins_loaded', 'wp_load_translations_early' );
35+
require( ABSPATH . 'wp-settings.php' );
6536

6637
// Support wp-config-sample.php one level up, for the develop repo.
6738
if ( file_exists( ABSPATH . 'wp-config-sample.php' ) )
@@ -120,7 +91,11 @@ function setup_config_display_header() {
12091
<li><?php _e( 'Database host' ); ?></li>
12192
<li><?php _e( 'Table prefix (if you want to run more than one WordPress in a single database)' ); ?></li>
12293
</ol>
123-
<p><strong><?php _e( "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 <code>wp-config-sample.php</code> in a text editor, fill in your information, and save it as <code>wp-config.php</code>." ); ?></strong></p>
94+
<p>
95+
<?php _e( 'We&#8217;re going to use this information to create a <code>wp-config.php</code> file.' ); ?>
96+
<strong><?php _e( "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 <code>wp-config-sample.php</code> in a text editor, fill in your information, and save it as <code>wp-config.php</code>." ); ?></strong>
97+
<?php _e( "Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>." ); ?>
98+
</p>
12499
<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&#8217;re all ready&hellip;" ); ?></p>
125100

126101
<p class="step"><a href="setup-config.php?step=1<?php if ( isset( $_GET['noapi'] ) ) echo '&amp;noapi'; ?>" class="button button-large"><?php _e( 'Let&#8217;s go!' ); ?></a></p>
@@ -191,29 +166,25 @@ function setup_config_display_header() {
191166
define('DB_HOST', $dbhost);
192167
/**#@-*/
193168

194-
// We'll fail here if the values are no good.
169+
// Re-construct $wpdb with these new values.
170+
unset( $wpdb );
195171
require_wp_db();
172+
173+
// The wpdb constructor bails when WP_SETUP_CONFIG is set, so we must
174+
// fire this manually. We'll fail here if the values are no good.
175+
$wpdb->db_connect();
176+
196177
if ( ! empty( $wpdb->error ) )
197178
wp_die( $wpdb->error->get_error_message() . $tryagain_link );
198179

199180
// Fetch or generate keys and salts.
200181
$no_api = isset( $_POST['noapi'] );
201182
if ( ! $no_api ) {
202-
require_once( ABSPATH . WPINC . '/class-http.php' );
203-
require_once( ABSPATH . WPINC . '/http.php' );
204-
/**#@+
205-
* @ignore
206-
*/
207-
function get_bloginfo() {
208-
return wp_guess_url();
209-
}
210-
/**#@-*/
211183
$secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
212184
}
213185

214186
if ( $no_api || is_wp_error( $secret_keys ) ) {
215187
$secret_keys = array();
216-
require_once( ABSPATH . WPINC . '/pluggable.php' );
217188
for ( $i = 0; $i < 8; $i++ ) {
218189
$secret_keys[] = wp_generate_password( 64, true, true );
219190
}

src/wp-includes/js/tinymce/wp-tinymce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Disable error reporting
44
*
5-
* Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging
5+
* Set this to error_reporting( -1 ) for debugging
66
*/
77
error_reporting(0);
88

src/wp-includes/wp-db.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,11 @@ public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
604604
$this->dbname = $dbname;
605605
$this->dbhost = $dbhost;
606606

607+
// wp-config.php creation will manually connect when ready.
608+
if ( defined( 'WP_SETUP_CONFIG' ) ) {
609+
return;
610+
}
611+
607612
$this->db_connect();
608613
}
609614

src/wp-load.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@
3838
// A config file doesn't exist
3939

4040
define( 'WPINC', 'wp-includes' );
41-
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
4241
require_once( ABSPATH . WPINC . '/load.php' );
43-
require_once( ABSPATH . WPINC . '/version.php' );
44-
45-
wp_check_php_mysql_versions();
46-
wp_load_translations_early();
4742

4843
// Standardize $_SERVER variables across setups.
4944
wp_fix_server_vars();
@@ -52,6 +47,21 @@
5247

5348
$path = wp_guess_url() . '/wp-admin/setup-config.php';
5449

50+
/* We're going to redirect to setup-config.php. While this shouldn't result
51+
* in an infinite loop, that's a silly thing to assume, don't you think? If
52+
* we're traveling in circles, our last-ditch effort is "Need more help?"
53+
*/
54+
if ( false === strpos( $_SERVER['REQUEST_URI'], 'setup-config' ) ) {
55+
header( 'Location: ' . $path );
56+
exit;
57+
}
58+
59+
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
60+
require_once( ABSPATH . WPINC . '/version.php' );
61+
62+
wp_check_php_mysql_versions();
63+
wp_load_translations_early();
64+
5565
// Die with an error message
5666
$die = __( "There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started." ) . '</p>';
5767
$die .= '<p>' . __( "Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>." ) . '</p>';

0 commit comments

Comments
 (0)