Make WordPress Core

Ticket #18180: 18180.4.diff

File 18180.4.diff, 17.9 KB (added by dd32, 13 years ago)
  • wp-admin/css/install.dev.css

     
    211211        margin: 5px 0 15px;
    212212        background-color: #ffffe0;
    213213}
     214.error {
     215        background-color: #ffebe8;
     216        border-color: #c00;
     217}
    214218
    215219
    216220/* install-rtl */
  • wp-admin/setup-config.php

     
    2929 * Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging
    3030 */
    3131error_reporting(0);
     32error_reporting( E_ALL & ~E_STRICT & ~E_DEPRECATED ); // DEBUG Dev edition
    3233
    3334/**#@+
    3435 * These three defines are required to allow us to use require_wp_db() to load
    3536 * the database class while being wp-content/db.php aware.
    3637 * @ignore
    3738 */
    38 define('ABSPATH', dirname(dirname(__FILE__)).'/');
     39define('ABSPATH', dirname(dirname(__FILE__)) . '/');
    3940define('WPINC', 'wp-includes');
    4041define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
    4142define('WP_DEBUG', false);
    4243/**#@-*/
    4344
    4445require_once(ABSPATH . WPINC . '/load.php');
     46
    4547require_once(ABSPATH . WPINC . '/version.php');
    4648wp_check_php_mysql_versions();
    4749
    4850require_once(ABSPATH . WPINC . '/compat.php');
    4951require_once(ABSPATH . WPINC . '/functions.php');
     52require_once(ABSPATH . WPINC . '/plugin.php');
     53require_once(ABSPATH . WPINC . '/formatting.php');
    5054require_once(ABSPATH . WPINC . '/class-wp-error.php');
     55require_once(ABSPATH . WPINC . '/kses.php');
     56require_once( ABSPATH . WPINC . '/pomo/mo.php' );
     57require_once( ABSPATH . WPINC . '/l10n.php');
    5158
    52 if (!file_exists(ABSPATH . 'wp-config-sample.php'))
    53         wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.');
     59wp_start_object_cache();
     60wp_set_lang_dir();
    5461
    55 $configFile = file(ABSPATH . 'wp-config-sample.php');
     62/**#@+
     63 * Set the Language to this installs default language
     64 * @ignore
     65 */
     66if ( !empty($wp_local_package) )
     67        define('WPLANG', $wp_local_package);
     68/**#@-*/
    5669
     70// Load the default text localization domain.
     71load_default_textdomain();
     72
     73// Find the blog locale.
     74$locale = get_locale();
     75$locale_file = WP_LANG_DIR . "/$locale.php";
     76if ( ( 0 === validate_file( $locale ) ) && is_readable( $locale_file ) )
     77        require( $locale_file );
     78unset($locale_file);
     79
     80add_filter('wp_die_handler', '_installer_wp_die');
     81function _installer_wp_die($handler) {
     82        return '_installer_wp_die_handler';
     83}
     84function _installer_wp_die_handler($error) {
     85        display_header();
     86        if ( is_wp_error($error) )
     87                $error = $error->get_error_message();
     88        echo "<p>$error</p>";
     89        display_footer();
     90        die();
     91}
     92
    5793// Check if wp-config.php has been created
    58 if (file_exists(ABSPATH . 'wp-config.php'))
    59         wp_die("<p>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 <a href='install.php'>installing now</a>.</p>");
     94if ( file_exists(ABSPATH . 'wp-config.php' ))
     95        wp_die( __("<p>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 <a href='install.php'>installing now</a>.</p>") );
    6096
    6197// Check if wp-config.php exists above the root directory but is not part of another install
    62 if (file_exists(ABSPATH . '../wp-config.php') && ! file_exists(ABSPATH . '../wp-settings.php'))
    63         wp_die("<p>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 <a href='install.php'>installing now</a>.</p>");
     98if ( file_exists(ABSPATH . '../wp-config.php') && ! file_exists(ABSPATH . '../wp-settings.php') )
     99        wp_die( __("<p>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 <a href='install.php'>installing now</a>.</p>") );
    64100
    65 if (isset($_GET['step']))
     101if ( ! file_exists(ABSPATH . 'wp-config-sample.php') )
     102        wp_die( __('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.') );
     103
     104if ( isset($_GET['step']) )
    66105        $step = $_GET['step'];
    67106else
    68107        $step = 0;
    69108
     109display_header();
     110if ( 2 == $step )
     111        step_2();
     112elseif ( 1 == $step )
     113        step_1();
     114else
     115        step_0();
     116display_footer();
     117
    70118/**
    71119 * Display setup wp-config.php file header.
    72120 *
     
    76124 * @subpackage Installer_WP_Config
    77125 */
    78126function display_header() {
     127        global $text_direction;
     128        $is_rtl = ( !empty($text_direction) && 'rtl' == $text_direction);
    79129        header( 'Content-Type: text/html; charset=utf-8' );
    80130?>
    81131<!DOCTYPE html>
    82 <html xmlns="http://www.w3.org/1999/xhtml">
     132<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo ( $is_rtl ? 'rtl' : 'ltr' ); ?>">
    83133<head>
    84134<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    85 <title>WordPress &rsaquo; Setup Configuration File</title>
    86 <link rel="stylesheet" href="css/install.css" type="text/css" />
     135<title><?php _e('WordPress &rsaquo; Setup Configuration File'); ?></title>
     136<!-- Dev Edition: .dev.css to be minified later -->
     137<link rel="stylesheet" href="css/install.dev.css" type="text/css" />
    87138
    88139</head>
    89 <body>
     140<body<?php if ( $is_rtl ) echo ' class="rtl"'; ?>>
    90141<h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
    91142<?php
    92143}//end function display_header();
    93144
    94 switch($step) {
    95         case 0:
    96                 display_header();
     145function step_0() {
    97146?>
    98147
    99 <p>Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.</p>
     148<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>
    100149<ol>
    101         <li>Database name</li>
    102         <li>Database username</li>
    103         <li>Database password</li>
    104         <li>Database host</li>
    105         <li>Table prefix (if you want to run more than one WordPress in a single database) </li>
     150        <li><?php _e('Database name'); ?></li>
     151        <li><?php _e('Database username'); ?></li>
     152        <li><?php _e('Database password'); ?></li>
     153        <li><?php _e('Database host'); ?></li>
     154        <li><?php _e('Table prefix (if you want to run more than one WordPress in a single database)'); ?></li>
    106155</ol>
    107 <p><strong>If for any reason this automatic file creation doesn't work, don'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>
    108 <p>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>
     156<p><?php _e("<strong>If for any reason this automatic file creation doesn't work, don'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>
     157<p>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>
    109158
    110 <p class="step"><a href="setup-config.php?step=1<?php if ( isset( $_GET['noapi'] ) ) echo '&amp;noapi'; ?>" class="button">Let&#8217;s go!</a></p>
     159<p class="step"><a href="setup-config.php?step=1<?php if ( isset( $_GET['noapi'] ) ) echo '&amp;noapi'; ?>" class="button"><?php _e('Let&#8217;s go!'); ?></a></p>
    111160<?php
    112         break;
     161}
    113162
    114         case 1:
    115                 display_header();
     163function step_1( $details = array(), $errors = array() ) {
     164        if ( empty($details) ) {
     165                $details = array(
     166                                        'dbname' => 'wordpress',
     167                                        'uname'  => _x('username', 'installer default username'),
     168                                        'pwd'    => _x('password', 'installer default password'),
     169                                        'dbhost' => 'localhost',
     170                                        'prefix' => 'wp_',
     171                                        );
     172        }
     173
     174        foreach ( $errors as $error ) {
     175                echo '<p class="error message">' . $error->get_error_message() . '</p>';
     176        }
     177
    116178        ?>
    117179<form method="post" action="setup-config.php?step=2">
    118         <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
     180        <p><?php _e("Below you should enter your database connection details. If you're not sure about these, contact your host."); ?></p>
    119181        <table class="form-table">
    120182                <tr>
    121                         <th scope="row"><label for="dbname">Database Name</label></th>
    122                         <td><input name="dbname" id="dbname" type="text" size="25" value="wordpress" /></td>
    123                         <td>The name of the database you want to run WP in. </td>
     183                        <th scope="row"><label for="dbname"><?php _e('Database Name'); ?></label></th>
     184                        <td><input name="dbname" id="dbname" type="text" size="25" value="<?php echo esc_attr($details['dbname']); ?>" /></td>
     185                        <td><?php _e('The name of the database you want to run WP in.'); ?></td>
    124186                </tr>
    125187                <tr>
    126                         <th scope="row"><label for="uname">User Name</label></th>
    127                         <td><input name="uname" id="uname" type="text" size="25" value="username" /></td>
    128                         <td>Your MySQL username</td>
     188                        <th scope="row"><label for="uname"><?php _e('User Name'); ?></label></th>
     189                        <td><input name="uname" id="uname" type="text" size="25" value="<?php echo esc_attr($details['uname']); ?>" /></td>
     190                        <td><?php _e('Your MySQL username'); ?></td>
    129191                </tr>
    130192                <tr>
    131                         <th scope="row"><label for="pwd">Password</label></th>
    132                         <td><input name="pwd" id="pwd" type="text" size="25" value="password" /></td>
    133                         <td>...and MySQL password.</td>
     193                        <th scope="row"><label for="pwd"><?php _e('Password'); ?></label></th>
     194                        <td><input name="pwd" id="pwd" type="text" size="25" value="<?php echo esc_attr($details['pwd']); ?>" /></td>
     195                        <td><?php _e('...and MySQL password.'); ?></td>
    134196                </tr>
    135197                <tr>
    136                         <th scope="row"><label for="dbhost">Database Host</label></th>
    137                         <td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
    138                         <td>You should be able to get this info from your web host, if <code>localhost</code> does not work.</td>
     198                        <th scope="row"><label for="dbhost"><?php _e('Database Host'); ?></label></th>
     199                        <td><input name="dbhost" id="dbhost" type="text" size="25" value="<?php echo esc_attr($details['dbhost']); ?>" /></td>
     200                        <td><?php _e('You should be able to get this info from your web host, if <code>localhost</code> does not work.'); ?></td>
    139201                </tr>
    140202                <tr>
    141                         <th scope="row"><label for="prefix">Table Prefix</label></th>
    142                         <td><input name="prefix" id="prefix" type="text" value="wp_" size="25" /></td>
    143                         <td>If you want to run multiple WordPress installations in a single database, change this.</td>
     203                        <th scope="row"><label for="prefix"><?php _e('Table Prefix'); ?></label></th>
     204                        <td><input name="prefix" id="prefix" type="text" value="<?php echo esc_attr($details['prefix']); ?>" size="25" /></td>
     205                        <td><?php _e('If you want to run multiple WordPress installations in a single database, change this.'); ?></td>
    144206                </tr>
    145207        </table>
    146208        <?php if ( isset( $_GET['noapi'] ) ) { ?><input name="noapi" type="hidden" value="true" /><?php } ?>
    147         <p class="step"><input name="submit" type="submit" value="Submit" class="button" /></p>
     209        <p class="step"><input name="submit" type="submit" value="<?php esc_attr_e('Submit'); ?>" class="button" /></p>
    148210</form>
    149211<?php
    150         break;
     212}
    151213
    152         case 2:
    153         $dbname  = trim($_POST['dbname']);
    154         $uname   = trim($_POST['uname']);
    155         $passwrd = trim($_POST['pwd']);
    156         $dbhost  = trim($_POST['dbhost']);
    157         $prefix  = trim($_POST['prefix']);
     214function step_2() {
     215        global $wpdb;
     216
     217        $dbname  = trim( stripslashes($_POST['dbname']) );
     218        $uname   = trim( stripslashes($_POST['uname']) );
     219        $pwd     = trim( stripslashes($_POST['pwd']) );
     220        $dbhost  = trim( stripslashes($_POST['dbhost']) );
     221        $prefix  = trim( stripslashes($_POST['prefix']) );
     222
     223        $errors = array();
     224
    158225        if ( empty($prefix) )
    159                 $prefix = 'wp_';
     226                $errors[] = new WP_Error('empty_prefix', __('"Table Prefix" must not be empty.') );
    160227
    161228        // Validate $prefix: it can only contain letters, numbers and underscores
    162229        if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
    163                 wp_die( /*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ );
     230                $errors[] = new WP_Error('invalid_prefix', __('"Table Prefix" can only contain numbers, letters, and underscores.') );
    164231
    165232        // Test the db connection.
    166233        /**#@+
     
    168235         */
    169236        define('DB_NAME', $dbname);
    170237        define('DB_USER', $uname);
    171         define('DB_PASSWORD', $passwrd);
     238        define('DB_PASSWORD', $pwd);
    172239        define('DB_HOST', $dbhost);
    173240        /**#@-*/
    174241
    175242        // We'll fail here if the values are no good.
    176243        require_wp_db();
     244
    177245        if ( ! empty( $wpdb->error ) ) {
    178                 $back = '<p class="step"><a href="setup-config.php?step=1" onclick="javascript:history.go(-1);return false;" class="button">Try Again</a></p>';
    179                 wp_die( $wpdb->error->get_error_message() . $back );
     246                if ( is_string($wpdb->error) ) {
     247                        $errors[] = new WP_Error( 'unknown', $wpdb->error );
     248                } else if ( 'db_connect_fail' == $wpdb->error->get_error_code() ) {
     249                        // bad creds
     250                        $errors[] = new WP_Error( 'credentials', __('An error occured whilst connecting to the Database server listed, Please check the details below are correct.') );
     251                } else if ( 'db_select_fail' == $wpdb->error->get_error_code() ) {
     252                        // database doesn't exist.
     253                        $errors[] = new WP_Error( 'dbname', __("WordPress couldn't select te specified database, Please ensure it exists and the above user account can access it.") );
     254                } else {
     255                        $errors[] = $wpdb->error;
     256                }
    180257        }
    181258
     259        if ( ! empty($errors) )
     260                step_1( compact( 'dbname', 'uname', 'pwd', 'dbhost', 'prefix' ), $errors);
     261        else
     262                write_config( $dbname, $uname, $pwd, $dbhost, $prefix );
     263}
     264
     265function write_config( $dbname, $uname, $pwd, $dbhost, $prefix ) {
     266        global $wpdb;
     267
    182268        // Fetch or generate keys and salts.
    183269        $no_api = isset( $_POST['noapi'] );
    184         require_once( ABSPATH . WPINC . '/plugin.php' );
    185         require_once( ABSPATH . WPINC . '/l10n.php' );
    186         require_once( ABSPATH . WPINC . '/pomo/translations.php' );
    187270        if ( ! $no_api ) {
    188271                require_once( ABSPATH . WPINC . '/class-http.php' );
    189272                require_once( ABSPATH . WPINC . '/http.php' );
     
    212295        }
    213296        $key = 0;
    214297
    215         foreach ($configFile as $line_num => $line) {
     298        $config_file = file(ABSPATH . 'wp-config-sample.php');
     299
     300        foreach ( $config_file as $line_num => $line ) {
    216301                switch (substr($line,0,16)) {
    217302                        case "define('DB_NAME'":
    218                                 $configFile[$line_num] = str_replace("database_name_here", $dbname, $line);
     303                                $dbname = addcslashes($dbname, "\\'");
     304                                $config_file[$line_num] = str_replace("'database_name_here'", "'$dbname'", $line);
    219305                                break;
    220306                        case "define('DB_USER'":
    221                                 $configFile[$line_num] = str_replace("'username_here'", "'$uname'", $line);
     307                                $uname = addcslashes($uname, "\\'");
     308                                $config_file[$line_num] = str_replace("'username_here'", "'$uname'", $line);
    222309                                break;
    223310                        case "define('DB_PASSW":
    224                                 $configFile[$line_num] = str_replace("'password_here'", "'$passwrd'", $line);
     311                                $pwd = addcslashes($pwd, "\\'");
     312                                $config_file[$line_num] = str_replace("'password_here'", "'$pwd'", $line);
    225313                                break;
    226314                        case "define('DB_HOST'":
    227                                 $configFile[$line_num] = str_replace("localhost", $dbhost, $line);
     315                                $config_file[$line_num] = str_replace("'localhost'", "'$dbhost'", $line);
    228316                                break;
    229317                        case '$table_prefix  =':
    230                                 $configFile[$line_num] = str_replace('wp_', $prefix, $line);
     318                                $config_file[$line_num] = str_replace("'wp_'", "'$prefix'", $line);
    231319                                break;
    232320                        case "define('AUTH_KEY":
    233321                        case "define('SECURE_A":
     
    237325                        case "define('SECURE_A":
    238326                        case "define('LOGGED_I":
    239327                        case "define('NONCE_SA":
    240                                 $configFile[$line_num] = str_replace('put your unique phrase here', $secret_keys[$key++], $line );
     328                                $config_file[$line_num] = str_replace( _x('put your unique phrase here', 'MUST MATCH PLACE HOLDER IN SECRET KEYS IN wp-config-sample.php'), $secret_keys[$key++], $line );
    241329                                break;
    242330                }
    243331        }
    244332        if ( ! is_writable(ABSPATH) ) :
    245                 display_header();
    246333?>
    247 <p>Sorry, but I can't write the <code>wp-config.php</code> file.</p>
    248 <p>You can create the <code>wp-config.php</code> manually and paste the following text into it.</p>
     334<p><?php _e("Sorry, but I can't write the <code>wp-config.php</code> file."); ?></p>
     335<p><?php _e('You can create the <code>wp-config.php</code> manually and paste the following text into it.'); ?></p>
    249336<textarea cols="98" rows="15" class="code"><?php
    250                 foreach( $configFile as $line ) {
    251                         echo htmlentities($line, ENT_COMPAT, 'UTF-8');
     337                foreach( $config_file as $line ) {
     338                        echo esc_textarea($line);
    252339                }
    253340?></textarea>
    254 <p>After you've done that, click "Run the install."</p>
    255 <p class="step"><a href="install.php" class="button">Run the install</a></p>
     341<p><?php _e('After you\'ve done that, click "Run the install."'); ?></p>
     342<p class="step"><a href="install.php" class="button"><?php _e('Run the install'); ?></a></p>
    256343<?php
    257344        else :
    258                 $handle = fopen(ABSPATH . 'wp-config.php', 'w');
    259                 foreach( $configFile as $line ) {
    260                         fwrite($handle, $line);
    261                 }
    262                 fclose($handle);
    263                 chmod(ABSPATH . 'wp-config.php', 0666);
    264                 display_header();
     345                file_put_contents( ABSPATH . 'wp-config.php', implode('', $config_file) );
     346                chmod(ABSPATH . 'wp-config.php', 0644);
    265347?>
    266 <p>All right sparky! You'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>
     348<p><?php _e("All right sparky! You'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>
    267349
    268 <p class="step"><a href="install.php" class="button">Run the install</a></p>
     350<p class="step"><a href="install.php" class="button"><?php _e('Run the install'); ?></a></p>
    269351<?php
    270352        endif;
    271         break;
    272353}
     354
     355function display_footer() {
    273356?>
    274357</body>
    275358</html>
     359<?php
     360}