Make WordPress Core

Ticket #18180: 18180.2.diff

File 18180.2.diff, 17.2 KB (added by dd32, 12 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

     
    3535 * the database class while being wp-content/db.php aware.
    3636 * @ignore
    3737 */
    38 define('ABSPATH', dirname(dirname(__FILE__)).'/');
     38define('ABSPATH', dirname(dirname(__FILE__)) . '/');
    3939define('WPINC', 'wp-includes');
    4040define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
    4141define('WP_DEBUG', false);
    4242/**#@-*/
    4343
    4444require_once(ABSPATH . WPINC . '/load.php');
     45
    4546require_once(ABSPATH . WPINC . '/version.php');
    4647wp_check_php_mysql_versions();
    4748
    4849require_once(ABSPATH . WPINC . '/compat.php');
    4950require_once(ABSPATH . WPINC . '/functions.php');
     51require_once(ABSPATH . WPINC . '/plugin.php');
     52require_once(ABSPATH . WPINC . '/formatting.php');
    5053require_once(ABSPATH . WPINC . '/class-wp-error.php');
     54require_once(ABSPATH . WPINC . '/kses.php');
    5155
    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.');
     56wp_start_object_cache();
     57wp_set_lang_dir();
    5458
    55 $configFile = file(ABSPATH . 'wp-config-sample.php');
     59add_filter('wp_die_handler', '_installer_wp_die');
     60function _installer_wp_die($handler) {
     61        return '_installer_wp_die_handler';
     62}
     63function _installer_wp_die_handler($error) {
     64        display_header();
     65        echo '<p>';
     66        echo is_wp_error($error) ? $error->get_error_message() : $error;
     67        echo '</p>';
     68        display_footer();
     69        die();
     70}
    5671
     72
     73/**#@+
     74 * A hacky way to set WPLANG to the installs default.
     75 * @TODO This should be set somehow a little bit less hacky, $text_direction also needs to be set.
     76 * @ignore
     77 */
     78if ( is_dir( WP_LANG_DIR ) && preg_match( '!define\(.+WPLANG.+[\'"]([A-z_]+)[\'"]!', file_get_contents( ABSPATH . 'wp-config-sample.php' ), $lang_match ) ) {
     79        define('WPLANG', $lang_match[1]);
     80}
     81/**#@-*/
     82
     83require_once( ABSPATH . WPINC . '/pomo/mo.php' );
     84require_once( ABSPATH . WPINC . '/l10n.php');
     85load_default_textdomain();
     86
    5787// 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>");
     88if ( file_exists(ABSPATH . 'wp-config.php' ))
     89        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>") );
    6090
    6191// 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>");
     92if ( file_exists(ABSPATH . '../wp-config.php') && ! file_exists(ABSPATH . '../wp-settings.php') )
     93        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>") );
    6494
    65 if (isset($_GET['step']))
     95// @TODO: Err, This string can't be translated this way, If the config file doesnt exist, we can't set the language. See TODO of setting the default language another way.
     96if ( ! file_exists(ABSPATH . 'wp-config-sample.php') )
     97        wp_die( __('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.') );
     98
     99if ( isset($_GET['step']) )
    66100        $step = $_GET['step'];
    67101else
    68102        $step = 0;
    69103
     104display_header();
     105if ( 2 == $step )
     106        step_2();
     107elseif ( 1 == $step )
     108        step_1();
     109else
     110        step_0();
     111display_footer();
     112
    70113/**
    71114 * Display setup wp-config.php file header.
    72115 *
     
    82125<html xmlns="http://www.w3.org/1999/xhtml">
    83126<head>
    84127<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" />
     128<title><?php _e('WordPress &rsaquo; Setup Configuration File'); ?></title>
     129<link rel="stylesheet" href="css/install.dev.css" type="text/css" />
    87130
    88131</head>
    89132<body>
     
    91134<?php
    92135}//end function display_header();
    93136
    94 switch($step) {
    95         case 0:
    96                 display_header();
     137function step_0() {
    97138?>
    98139
    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>
     140<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>
    100141<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>
     142        <li><?php _e('Database name'); ?></li>
     143        <li><?php _e('Database username'); ?></li>
     144        <li><?php _e('Database password'); ?></li>
     145        <li><?php _e('Database host'); ?></li>
     146        <li><?php _e('Table prefix (if you want to run more than one WordPress in a single database)'); ?></li>
    106147</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>
     148<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>
     149<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>
    109150
    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>
     151<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>
    111152<?php
    112         break;
     153}
    113154
    114         case 1:
    115                 display_header();
     155function step_1( $details = array(), $errors = array() ) {
     156        if ( empty($details) ) {
     157                $details = array(
     158                                        'dbname' => _x('wordpress', 'installer default database'),
     159                                        'uname'  => _x('username', 'installer default username'),
     160                                        'pwd'    => _x('password', 'installer default password'),
     161                                        'dbhost' => _x('localhost', 'installer default host'),
     162                                        'prefix' => _x('wp_', 'installer default table prefix'),
     163                                        );
     164        }
     165
     166        foreach ( $errors as $error ) {
     167                echo '<p class="error message">' . $error->get_error_message() . '</p>';
     168        }
     169
    116170        ?>
    117171<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>
     172        <p><?php _e("Below you should enter your database connection details. If you're not sure about these, contact your host."); ?></p>
    119173        <table class="form-table">
    120174                <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>
     175                        <th scope="row"><label for="dbname"><?php _e('Database Name'); ?></label></th>
     176                        <td><input name="dbname" id="dbname" type="text" size="25" value="<?php echo esc_attr($details['dbname']); ?>" /></td>
     177                        <td><?php _e('The name of the database you want to run WP in.'); ?></td>
    124178                </tr>
    125179                <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>
     180                        <th scope="row"><label for="uname"><?php _e('User Name'); ?></label></th>
     181                        <td><input name="uname" id="uname" type="text" size="25" value="<?php echo esc_attr($details['uname']); ?>" /></td>
     182                        <td><?php _e('Your MySQL username'); ?></td>
    129183                </tr>
    130184                <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>
     185                        <th scope="row"><label for="pwd"><?php _e('Password'); ?></label></th>
     186                        <td><input name="pwd" id="pwd" type="text" size="25" value="<?php echo esc_attr($details['pwd']); ?>" /></td>
     187                        <td><?php _e('...and MySQL password.'); ?></td>
    134188                </tr>
    135189                <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>
     190                        <th scope="row"><label for="dbhost"><?php _e('Database Host'); ?></label></th>
     191                        <td><input name="dbhost" id="dbhost" type="text" size="25" value="<?php echo esc_attr($details['dbhost']); ?>" /></td>
     192                        <td><?php _e('You should be able to get this info from your web host, if <code>localhost</code> does not work.'); ?></td>
    139193                </tr>
    140194                <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>
     195                        <th scope="row"><label for="prefix"><?php _e('Table Prefix'); ?></label></th>
     196                        <td><input name="prefix" id="prefix" type="text" value="<?php echo esc_attr($details['prefix']); ?>" size="25" /></td>
     197                        <td><?php _e('If you want to run multiple WordPress installations in a single database, change this.'); ?></td>
    144198                </tr>
    145199        </table>
    146200        <?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>
     201        <p class="step"><input name="submit" type="submit" value="<?php esc_attr_e('Submit'); ?>" class="button" /></p>
    148202</form>
    149203<?php
    150         break;
     204}
    151205
    152         case 2:
     206function step_2() {
     207        global $wpdb;
     208
    153209        $dbname  = trim($_POST['dbname']);
    154210        $uname   = trim($_POST['uname']);
    155         $passwrd = trim($_POST['pwd']);
     211        $pwd    = trim($_POST['pwd']);
    156212        $dbhost  = trim($_POST['dbhost']);
    157213        $prefix  = trim($_POST['prefix']);
     214
     215        $errors = array();
     216
    158217        if ( empty($prefix) )
    159                 $prefix = 'wp_';
     218                $errors[] = new WP_Error('empty_prefix', __('"Table Prefix" must not be empty.') );
    160219
    161220        // Validate $prefix: it can only contain letters, numbers and underscores
    162221        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*/ );
     222                $errors[] = new WP_Error('invalid_prefix', __('"Table Prefix" can only contain numbers, letters, and underscores.') );
    164223
    165224        // Test the db connection.
    166225        /**#@+
     
    168227         */
    169228        define('DB_NAME', $dbname);
    170229        define('DB_USER', $uname);
    171         define('DB_PASSWORD', $passwrd);
     230        define('DB_PASSWORD', $pwd);
    172231        define('DB_HOST', $dbhost);
    173232        /**#@-*/
    174233
    175234        // We'll fail here if the values are no good.
    176235        require_wp_db();
     236
    177237        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 );
     238                if ( is_string($wpdb->error) ) {
     239                        $errors[] = new WP_Error( 'unknown', $wpdb->error );
     240                } else if ( 'db_connect_fail' == $wpdb->error->get_error_code() ) {
     241                        // bad creds
     242                        $errors[] = new WP_Error( 'credentials', __('An error occured whilst connecting to the Database server listed, Please check the details below are correct.') );
     243                } else if ( 'db_select_fail' == $wpdb->error->get_error_code() ) {
     244                        // database doesn't exist.
     245                        $errors[] = new WP_Error( 'dbname', __("WordPress couldn't select te specified database, Please ensure it exists and the above user account can access it.") );
     246                } else {
     247                        $errors[] = $wpdb->error;
     248                }
    180249        }
    181250
     251        if ( ! empty($errors) )
     252                step_1( compact( 'dbname', 'uname', 'pwd', 'dbhost', 'prefix' ), $errors);
     253        else
     254                write_config( $dbname, $uname, $pwd, $dbhost, $prefix );
     255}
     256
     257function write_config( $dbname, $uname, $pwd, $dbhost, $prefix ) {
     258        global $wpdb;
     259
    182260        // Fetch or generate keys and salts.
    183261        $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' );
    187262        if ( ! $no_api ) {
    188263                require_once( ABSPATH . WPINC . '/class-http.php' );
    189264                require_once( ABSPATH . WPINC . '/http.php' );
     
    212287        }
    213288        $key = 0;
    214289
    215         foreach ($configFile as $line_num => $line) {
     290        $config_file = file(ABSPATH . 'wp-config-sample.php');
     291
     292        foreach ( $config_file as $line_num => $line ) {
    216293                switch (substr($line,0,16)) {
    217294                        case "define('DB_NAME'":
    218                                 $configFile[$line_num] = str_replace("database_name_here", $dbname, $line);
     295                                $dbname = addcslashes($dbname, "\\'");
     296                                $config_file[$line_num] = str_replace("'database_name_here'", "'$dbname'", $line);
    219297                                break;
    220298                        case "define('DB_USER'":
    221                                 $configFile[$line_num] = str_replace("'username_here'", "'$uname'", $line);
     299                                $uname = addcslashes($uname, "\\'");
     300                                $config_file[$line_num] = str_replace("'username_here'", "'$uname'", $line);
    222301                                break;
    223302                        case "define('DB_PASSW":
    224                                 $configFile[$line_num] = str_replace("'password_here'", "'$passwrd'", $line);
     303                                $pwd = addcslashes($pwd, "\\'");
     304                                $config_file[$line_num] = str_replace("'password_here'", "'$pwd'", $line);
    225305                                break;
    226306                        case "define('DB_HOST'":
    227                                 $configFile[$line_num] = str_replace("localhost", $dbhost, $line);
     307                                $dbhost = addcslashes($dbhost, "\\'");
     308                                $config_file[$line_num] = str_replace("'localhost'", "'$dbhost'", $line);
    228309                                break;
    229310                        case '$table_prefix  =':
    230                                 $configFile[$line_num] = str_replace('wp_', $prefix, $line);
     311                                $config_file[$line_num] = str_replace("'wp_'", "'$prefix'", $line);
    231312                                break;
    232313                        case "define('AUTH_KEY":
    233314                        case "define('SECURE_A":
     
    237318                        case "define('SECURE_A":
    238319                        case "define('LOGGED_I":
    239320                        case "define('NONCE_SA":
    240                                 $configFile[$line_num] = str_replace('put your unique phrase here', $secret_keys[$key++], $line );
     321                                $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 );
    241322                                break;
    242323                }
    243324        }
    244325        if ( ! is_writable(ABSPATH) ) :
    245                 display_header();
    246326?>
    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>
     327<p><?php _e("Sorry, but I can't write the <code>wp-config.php</code> file."); ?></p>
     328<p><?php _e('You can create the <code>wp-config.php</code> manually and paste the following text into it.'); ?></p>
    249329<textarea cols="98" rows="15" class="code"><?php
    250                 foreach( $configFile as $line ) {
    251                         echo htmlentities($line, ENT_COMPAT, 'UTF-8');
     330                foreach( $config_file as $line ) {
     331                        echo esc_textarea($line);
    252332                }
    253333?></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>
     334<p><?php _e('After you\'ve done that, click "Run the install."'); ?></p>
     335<p class="step"><a href="install.php" class="button"><?php _e('Run the install'); ?></a></p>
    256336<?php
    257337        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();
     338                file_put_contents( ABSPATH . 'wp-config.php', implode('', $config_file) );
     339                chmod(ABSPATH . 'wp-config.php', 0644);
    265340?>
    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>
     341<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>
    267342
    268 <p class="step"><a href="install.php" class="button">Run the install</a></p>
     343<p class="step"><a href="install.php" class="button"><?php _e('Run the install'); ?></a></p>
    269344<?php
    270345        endif;
    271         break;
    272346}
     347
     348function display_footer() {
    273349?>
    274350</body>
    275351</html>
     352<?php
     353}