Make WordPress Core

Ticket #18180: 18180.3.diff

File 18180.3.diff, 17.9 KB (added by SergeyBiryukov, 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/install.php

     
    6060        <title><?php _e( 'WordPress &rsaquo; Installation' ); ?></title>
    6161        <?php wp_admin_css( 'install', true ); ?>
    6262</head>
    63 <body>
     63<body<?php if ( is_rtl() ) : ?> class="rtl"<?php endif; ?>>
    6464<h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
    6565
    6666<?php
  • 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
     72if ( !empty( $wp_local_package ) ) {
     73        define('WPLANG', $wp_local_package);
     74        $locale_file = WP_LANG_DIR . "/$wp_local_package.php";
     75        if ( ( 0 === validate_file( $wp_local_package ) ) && is_readable( $locale_file ) )
     76                require( $locale_file );
     77}
     78
     79require_once( ABSPATH . WPINC . '/pomo/mo.php' );
     80require_once( ABSPATH . WPINC . '/l10n.php');
     81load_default_textdomain();
     82
    5783// 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>");
     84if ( file_exists(ABSPATH . 'wp-config.php') )
     85        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>") );
    6086
    6187// 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>");
     88if ( file_exists(ABSPATH . '../wp-config.php') && ! file_exists(ABSPATH . '../wp-settings.php') )
     89        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>") );
    6490
    65 if (isset($_GET['step']))
     91// @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.
     92if ( ! file_exists(ABSPATH . 'wp-config-sample.php') )
     93        wp_die( __('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.') );
     94
     95if ( isset($_GET['step']) )
    6696        $step = $_GET['step'];
    6797else
    6898        $step = 0;
    6999
     100display_header();
     101if ( 2 == $step )
     102        step_2();
     103elseif ( 1 == $step )
     104        step_1();
     105else
     106        step_0();
     107display_footer();
     108
    70109/**
    71110 * Display setup wp-config.php file header.
    72111 *
     
    76115 * @subpackage Installer_WP_Config
    77116 */
    78117function display_header() {
     118        global $text_direction;
    79119        header( 'Content-Type: text/html; charset=utf-8' );
    80120?>
    81121<!DOCTYPE html>
    82122<html xmlns="http://www.w3.org/1999/xhtml">
    83123<head>
    84 <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" />
    87 
     124        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     125        <title><?php _e('WordPress &rsaquo; Setup Configuration File'); ?></title>
     126        <link rel="stylesheet" href="css/install.css" type="text/css" />
    88127</head>
    89 <body>
     128<body<?php if ( 'rtl' == $text_direction ) : ?> class="rtl"<?php endif; ?>>
    90129<h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
    91130<?php
    92131}//end function display_header();
    93132
    94 switch($step) {
    95         case 0:
    96                 display_header();
     133function step_0() {
    97134?>
    98135
    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>
     136<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>
    100137<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>
     138        <li><?php _e('Database name'); ?></li>
     139        <li><?php _e('Database username'); ?></li>
     140        <li><?php _e('Database password'); ?></li>
     141        <li><?php _e('Database host'); ?></li>
     142        <li><?php _e('Table prefix (if you want to run more than one WordPress in a single database)'); ?></li>
    106143</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>
     144<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>
     145<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>
    109146
    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>
     147<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>
    111148<?php
    112         break;
     149}
    113150
    114         case 1:
    115                 display_header();
     151function step_1( $details = array(), $errors = array() ) {
     152        if ( empty($details) ) {
     153                $details = array(
     154                                        'dbname' => _x('wordpress', 'installer default database'),
     155                                        'uname'  => _x('username', 'installer default username'),
     156                                        'pwd'    => _x('password', 'installer default password'),
     157                                        'dbhost' => _x('localhost', 'installer default host'),
     158                                        'prefix' => _x('wp_', 'installer default table prefix'),
     159                                        );
     160        }
     161
     162        foreach ( $errors as $error ) {
     163                echo '<p class="error message">' . $error->get_error_message() . '</p>';
     164        }
     165
    116166        ?>
    117167<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>
     168        <p><?php _e("Below you should enter your database connection details. If you're not sure about these, contact your host."); ?></p>
    119169        <table class="form-table">
    120170                <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>
     171                        <th scope="row"><label for="dbname"><?php _e('Database Name'); ?></label></th>
     172                        <td><input name="dbname" id="dbname" type="text" size="25" value="<?php echo esc_attr($details['dbname']); ?>" /></td>
     173                        <td><?php _e('The name of the database you want to run WP in.'); ?></td>
    124174                </tr>
    125175                <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>
     176                        <th scope="row"><label for="uname"><?php _e('User Name'); ?></label></th>
     177                        <td><input name="uname" id="uname" type="text" size="25" value="<?php echo esc_attr($details['uname']); ?>" /></td>
     178                        <td><?php _e('Your MySQL username'); ?></td>
    129179                </tr>
    130180                <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>
     181                        <th scope="row"><label for="pwd"><?php _e('Password'); ?></label></th>
     182                        <td><input name="pwd" id="pwd" type="text" size="25" value="<?php echo esc_attr($details['pwd']); ?>" /></td>
     183                        <td><?php _e('...and MySQL password.'); ?></td>
    134184                </tr>
    135185                <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>
     186                        <th scope="row"><label for="dbhost"><?php _e('Database Host'); ?></label></th>
     187                        <td><input name="dbhost" id="dbhost" type="text" size="25" value="<?php echo esc_attr($details['dbhost']); ?>" /></td>
     188                        <td><?php _e('You should be able to get this info from your web host, if <code>localhost</code> does not work.'); ?></td>
    139189                </tr>
    140190                <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>
     191                        <th scope="row"><label for="prefix"><?php _e('Table Prefix'); ?></label></th>
     192                        <td><input name="prefix" id="prefix" type="text" value="<?php echo esc_attr($details['prefix']); ?>" size="25" /></td>
     193                        <td><?php _e('If you want to run multiple WordPress installations in a single database, change this.'); ?></td>
    144194                </tr>
    145195        </table>
    146196        <?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>
     197        <p class="step"><input name="submit" type="submit" value="<?php esc_attr_e('Submit'); ?>" class="button" /></p>
    148198</form>
    149199<?php
    150         break;
     200}
    151201
    152         case 2:
    153         $dbname  = trim($_POST['dbname']);
    154         $uname   = trim($_POST['uname']);
    155         $passwrd = trim($_POST['pwd']);
     202function step_2() {
     203        global $wpdb;
     204
     205        $dbname  = trim( stripslashes($_POST['dbname']) );
     206        $uname   = trim( stripslashes($_POST['uname'])) ;
     207        $pwd     = trim( stripslashes($_POST['pwd']) );
    156208        $dbhost  = trim($_POST['dbhost']);
    157209        $prefix  = trim($_POST['prefix']);
     210
     211        $errors = array();
     212
    158213        if ( empty($prefix) )
    159                 $prefix = 'wp_';
     214                $errors[] = new WP_Error('empty_prefix', __('"Table Prefix" must not be empty.') );
    160215
    161216        // Validate $prefix: it can only contain letters, numbers and underscores
    162217        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*/ );
     218                $errors[] = new WP_Error('invalid_prefix', __('"Table Prefix" can only contain numbers, letters, and underscores.') );
    164219
    165220        // Test the db connection.
    166221        /**#@+
     
    168223         */
    169224        define('DB_NAME', $dbname);
    170225        define('DB_USER', $uname);
    171         define('DB_PASSWORD', $passwrd);
     226        define('DB_PASSWORD', $pwd);
    172227        define('DB_HOST', $dbhost);
    173228        /**#@-*/
    174229
    175230        // We'll fail here if the values are no good.
    176231        require_wp_db();
     232
    177233        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 );
     234                if ( is_string($wpdb->error) ) {
     235                        $errors[] = new WP_Error( 'unknown', $wpdb->error );
     236                } else if ( 'db_connect_fail' == $wpdb->error->get_error_code() ) {
     237                        // bad creds
     238                        $errors[] = new WP_Error( 'credentials', __('An error occured whilst connecting to the Database server listed, Please check the details below are correct.') );
     239                } else if ( 'db_select_fail' == $wpdb->error->get_error_code() ) {
     240                        // database doesn't exist.
     241                        $errors[] = new WP_Error( 'dbname', __("WordPress couldn't select te specified database, Please ensure it exists and the above user account can access it.") );
     242                } else {
     243                        $errors[] = $wpdb->error;
     244                }
    180245        }
    181246
     247        if ( ! empty($errors) )
     248                step_1( compact( 'dbname', 'uname', 'pwd', 'dbhost', 'prefix' ), $errors);
     249        else
     250                write_config( $dbname, $uname, $pwd, $dbhost, $prefix );
     251}
     252
     253function write_config( $dbname, $uname, $pwd, $dbhost, $prefix ) {
     254        global $wpdb;
     255
    182256        // Fetch or generate keys and salts.
    183257        $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' );
    187258        if ( ! $no_api ) {
    188259                require_once( ABSPATH . WPINC . '/class-http.php' );
    189260                require_once( ABSPATH . WPINC . '/http.php' );
     
    212283        }
    213284        $key = 0;
    214285
    215         foreach ($configFile as $line_num => $line) {
     286        $config_file = file(ABSPATH . 'wp-config-sample.php');
     287
     288        foreach ( $config_file as $line_num => $line ) {
    216289                switch (substr($line,0,16)) {
    217290                        case "define('DB_NAME'":
    218                                 $configFile[$line_num] = str_replace("database_name_here", $dbname, $line);
     291                                $dbname = addcslashes($dbname, "\\'");
     292                                $config_file[$line_num] = str_replace("'database_name_here'", "'$dbname'", $line);
    219293                                break;
    220294                        case "define('DB_USER'":
    221                                 $configFile[$line_num] = str_replace("'username_here'", "'$uname'", $line);
     295                                $uname = addcslashes($uname, "\\'");
     296                                $config_file[$line_num] = str_replace("'username_here'", "'$uname'", $line);
    222297                                break;
    223298                        case "define('DB_PASSW":
    224                                 $configFile[$line_num] = str_replace("'password_here'", "'$passwrd'", $line);
     299                                $pwd = addcslashes($pwd, "\\'");
     300                                $config_file[$line_num] = str_replace("'password_here'", "'$pwd'", $line);
    225301                                break;
    226302                        case "define('DB_HOST'":
    227                                 $configFile[$line_num] = str_replace("localhost", $dbhost, $line);
     303                                $config_file[$line_num] = str_replace("'localhost'", "'$dbhost'", $line);
    228304                                break;
    229305                        case '$table_prefix  =':
    230                                 $configFile[$line_num] = str_replace('wp_', $prefix, $line);
     306                                $config_file[$line_num] = str_replace("'wp_'", "'$prefix'", $line);
    231307                                break;
    232308                        case "define('AUTH_KEY":
    233309                        case "define('SECURE_A":
     
    237313                        case "define('SECURE_A":
    238314                        case "define('LOGGED_I":
    239315                        case "define('NONCE_SA":
    240                                 $configFile[$line_num] = str_replace('put your unique phrase here', $secret_keys[$key++], $line );
     316                                $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 );
    241317                                break;
    242318                }
    243319        }
    244320        if ( ! is_writable(ABSPATH) ) :
    245                 display_header();
    246321?>
    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>
     322<p><?php _e("Sorry, but I can't write the <code>wp-config.php</code> file."); ?></p>
     323<p><?php _e('You can create the <code>wp-config.php</code> manually and paste the following text into it.'); ?></p>
    249324<textarea cols="98" rows="15" class="code"><?php
    250                 foreach( $configFile as $line ) {
    251                         echo htmlentities($line, ENT_COMPAT, 'UTF-8');
     325                foreach( $config_file as $line ) {
     326                        echo esc_textarea($line);
    252327                }
    253328?></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>
     329<p><?php _e('After you\'ve done that, click "Run the install."'); ?></p>
     330<p class="step"><a href="install.php" class="button"><?php _e('Run the install'); ?></a></p>
    256331<?php
    257332        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();
     333                file_put_contents( ABSPATH . 'wp-config.php', implode('', $config_file) );
     334                chmod(ABSPATH . 'wp-config.php', 0644);
    265335?>
    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>
     336<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>
    267337
    268 <p class="step"><a href="install.php" class="button">Run the install</a></p>
     338<p class="step"><a href="install.php" class="button"><?php _e('Run the install'); ?></a></p>
    269339<?php
    270340        endif;
    271         break;
    272341}
     342
     343function display_footer() {
    273344?>
    274345</body>
    275346</html>
     347<?php
     348}