X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/6c8f14c09105d0afa4c1574215c59b5021040e76..a9fa37e08fa731c7bd108a175c24876823bc071b:/wp-admin/setup-config.php diff --git a/wp-admin/setup-config.php b/wp-admin/setup-config.php index 7409d010..befa6937 100644 --- a/wp-admin/setup-config.php +++ b/wp-admin/setup-config.php @@ -13,8 +13,6 @@ /** * We are installing. - * - * @package WordPress */ define('WP_INSTALLING', true); @@ -26,89 +24,124 @@ define('WP_SETUP_CONFIG', true); /** * Disable error reporting * - * Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging + * Set this to error_reporting( -1 ) for debugging */ error_reporting(0); -/**#@+ - * These three defines are required to allow us to use require_wp_db() to load - * the database class while being wp-content/db.php aware. - * @ignore - */ -define('ABSPATH', dirname(dirname(__FILE__)).'/'); -define('WPINC', 'wp-includes'); -define('WP_CONTENT_DIR', ABSPATH . 'wp-content'); -define('WP_DEBUG', false); -/**#@-*/ - -require(ABSPATH . WPINC . '/load.php'); -require(ABSPATH . WPINC . '/version.php'); - -// Check for the required PHP version and for the MySQL extension or a database drop-in. -wp_check_php_mysql_versions(); +define( 'ABSPATH', dirname( dirname( __FILE__ ) ) . '/' ); -require_once(ABSPATH . WPINC . '/functions.php'); +require( ABSPATH . 'wp-settings.php' ); -// Also loads plugin.php, l10n.php, pomo/mo.php (all required by setup-config.php) -wp_load_translations_early(); +/** Load WordPress Administration Upgrade API */ +require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); -// Turn register_globals off. -wp_unregister_GLOBALS(); +/** Load WordPress Translation Install API */ +require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); -require_once(ABSPATH . WPINC . '/compat.php'); -require_once(ABSPATH . WPINC . '/class-wp-error.php'); -require_once(ABSPATH . WPINC . '/formatting.php'); +nocache_headers(); -// Add magic quotes and set up $_REQUEST ( $_GET + $_POST ) -wp_magic_quotes(); - -if ( ! file_exists( ABSPATH . 'wp-config-sample.php' ) ) - wp_die( __( 'Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.' ) ); - -$config_file = file(ABSPATH . 'wp-config-sample.php'); +// Support wp-config-sample.php one level up, for the develop repo. +if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) + $config_file = file( ABSPATH . 'wp-config-sample.php' ); +elseif ( file_exists( dirname( ABSPATH ) . '/wp-config-sample.php' ) ) + $config_file = file( dirname( ABSPATH ) . '/wp-config-sample.php' ); +else + wp_die( __( 'Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file to your WordPress installation.' ) ); // Check if wp-config.php has been created if ( file_exists( ABSPATH . 'wp-config.php' ) ) - wp_die( '

' . sprintf( __( "The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now." ), 'install.php' ) . '

' ); + wp_die( '

' . sprintf( + /* translators: %s: install.php */ + __( "The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now." ), + 'install.php' + ) . '

' + ); // Check if wp-config.php exists above the root directory but is not part of another install -if ( file_exists(ABSPATH . '../wp-config.php' ) && ! file_exists( ABSPATH . '../wp-settings.php' ) ) - wp_die( '

' . 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 installing now."), 'install.php' ) . '

' ); +if ( @file_exists( ABSPATH . '../wp-config.php' ) && ! @file_exists( ABSPATH . '../wp-settings.php' ) ) { + wp_die( '

' . sprintf( + /* translators: %s: install.php */ + __( "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 installing now." ), + 'install.php' + ) . '

' + ); +} -$step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0; +$step = isset( $_GET['step'] ) ? (int) $_GET['step'] : -1; /** * Display setup wp-config.php file header. * * @ignore * @since 2.3.0 - * @package WordPress - * @subpackage Installer_WP_Config + * + * @global string $wp_local_package + * @global WP_Locale $wp_locale + * + * @param string|array $body_classes */ -function setup_config_display_header() { - global $wp_version; +function setup_config_display_header( $body_classes = array() ) { + $body_classes = (array) $body_classes; + $body_classes[] = 'wp-core-ui'; + if ( is_rtl() ) { + $body_classes[] = 'rtl'; + } header( 'Content-Type: text/html; charset=utf-8' ); ?> > - -<?php _e( 'WordPress › Setup Configuration File' ); ?> - - - + + + + <?php _e( 'WordPress › Setup Configuration File' ); ?> + - -

+ + Select a default language'; + echo '
'; + wp_install_language_form( $languages ); + echo '
'; + break; + } + + // Deliberately fall through if we can't reach the translations API. + case 0: + if ( ! empty( $language ) ) { + $loaded_language = wp_download_language_pack( $language ); + if ( $loaded_language ) { + load_default_textdomain( $loaded_language ); + $GLOBALS['wp_locale'] = new WP_Locale(); + } + } + setup_config_display_header(); + $step_1 = 'setup-config.php?step=1'; + if ( isset( $_REQUEST['noapi'] ) ) { + $step_1 .= '&noapi'; + } + if ( ! empty( $loaded_language ) ) { + $step_1 .= '&language=' . $loaded_language; + } ?> - +

  1. @@ -117,38 +150,63 @@ switch($step) {
-

wp-config-sample.php in a text editor, fill in your information, and save it as wp-config.php." ); ?>

-

- -

+

wp-config.php' + ); + ?> + wp-config-sample.php', + 'wp-config.php' + ); + ?> + We got it.' ), + __( 'https://codex.wordpress.org/Editing_wp-config.php' ) + ); +?>

+

+ +

+

-

+

- + - + - + - - + + - + @@ -157,16 +215,36 @@ switch($step) {
localhost does not work.' ); ?>localhost' ); + ?>
+

' . __( 'Try again' ) . ''; + if ( ! empty( $language ) ) { + $step_1 .= '&language=' . $language; + $install .= '?language=' . $language; + } else { + $install .= '?language=en_US'; + } + + $tryagain_link = '

' . __( 'Try again' ) . ''; if ( empty( $prefix ) ) wp_die( __( 'ERROR: "Table Prefix" must not be empty.' . $tryagain_link ) ); @@ -185,37 +263,47 @@ switch($step) { define('DB_HOST', $dbhost); /**#@-*/ - // We'll fail here if the values are no good. + // Re-construct $wpdb with these new values. + unset( $wpdb ); require_wp_db(); + + /* + * The wpdb constructor bails when WP_SETUP_CONFIG is set, so we must + * fire this manually. We'll fail here if the values are no good. + */ + $wpdb->db_connect(); + if ( ! empty( $wpdb->error ) ) wp_die( $wpdb->error->get_error_message() . $tryagain_link ); - // Fetch or generate keys and salts. - $no_api = isset( $_POST['noapi'] ); - if ( ! $no_api ) { - require_once( ABSPATH . WPINC . '/class-http.php' ); - require_once( ABSPATH . WPINC . '/http.php' ); - wp_fix_server_vars(); - /**#@+ - * @ignore - */ - function get_bloginfo() { - return ( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . str_replace( $_SERVER['PHP_SELF'], '/wp-admin/setup-config.php', '' ) ); + // Generate keys and salts using secure CSPRNG; fallback to API if enabled; further fallback to original wp_generate_password(). + try { + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|'; + $max = strlen($chars) - 1; + for ( $i = 0; $i < 8; $i++ ) { + $key = ''; + for ( $j = 0; $j < 64; $j++ ) { + $key .= substr( $chars, random_int( 0, $max ), 1 ); + } + $secret_keys[] = $key; } - /**#@-*/ - $secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); - } + } catch ( Exception $ex ) { + $no_api = isset( $_POST['noapi'] ); - if ( $no_api || is_wp_error( $secret_keys ) ) { - $secret_keys = array(); - require_once( ABSPATH . WPINC . '/pluggable.php' ); - for ( $i = 0; $i < 8; $i++ ) { - $secret_keys[] = wp_generate_password( 64, true, true ); + if ( ! $no_api ) { + $secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); } - } else { - $secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) ); - foreach ( $secret_keys as $k => $v ) { - $secret_keys[$k] = substr( $v, 28, 64 ); + + if ( $no_api || is_wp_error( $secret_keys ) ) { + $secret_keys = array(); + for ( $i = 0; $i < 8; $i++ ) { + $secret_keys[] = wp_generate_password( 64, true, true ); + } + } else { + $secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) ); + foreach ( $secret_keys as $k => $v ) { + $secret_keys[$k] = substr( $v, 28, 64 ); + } } } @@ -240,6 +328,11 @@ switch($step) { case 'DB_HOST' : $config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "');\r\n"; break; + case 'DB_CHARSET' : + if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset && $wpdb->has_cap( 'utf8mb4' ) ) ) { + $config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'utf8mb4');\r\n"; + } + break; case 'AUTH_KEY' : case 'SECURE_AUTH_KEY' : case 'LOGGED_IN_KEY' : @@ -257,39 +350,58 @@ switch($step) { if ( ! is_writable(ABSPATH) ) : setup_config_display_header(); ?> -

wp-config.php file." ); ?>

-

wp-config.php manually and paste the following text into it.' ); ?>

+

wp-config.php' ); +?>

+

wp-config.php' ); +?>

-

+

-

+

+

-

+

+