Make WordPress Core

Ticket #13839: 13839.6.diff

File 13839.6.diff, 3.2 KB (added by SergeyBiryukov, 13 years ago)
  • wp-admin/setup-config.php

     
    5151
    5252require_once(ABSPATH . WPINC . '/compat.php');
    5353require_once(ABSPATH . WPINC . '/class-wp-error.php');
     54require_once(ABSPATH . WPINC . '/formatting.php');
    5455
    5556if ( ! file_exists( ABSPATH . 'wp-config-sample.php' ) )
    5657        wp_die( __( 'Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.' ) );
     
    152153        break;
    153154
    154155        case 2:
    155         $dbname  = trim($_POST['dbname']);
    156         $uname   = trim($_POST['uname']);
    157         $passwrd = trim($_POST['pwd']);
    158         $dbhost  = trim($_POST['dbhost']);
    159         $prefix  = trim($_POST['prefix']);
    160         if ( empty($prefix) )
    161                 $prefix = 'wp_';
     156        // Turn register_globals off.
     157        wp_unregister_GLOBALS();
    162158
    163         // Validate $prefix: it can only contain letters, numbers and underscores
     159        // Add magic quotes.
     160        wp_magic_quotes();
     161
     162        foreach ( array( 'dbname', 'uname', 'pwd', 'dbhost', 'prefix' ) as $key )
     163                $$key = trim( stripslashes( $_POST[ $key ] ) );
     164
     165        $tryagain_link = '</p><p class="step"><a href="setup-config.php?step=1" onclick="javascript:history.go(-1);return false;" class="button">' . __( 'Try Again' ) . '</a>';
     166
     167        if ( empty( $prefix ) )
     168                wp_die( __( '<strong>ERROR</strong>: "Table Prefix" must not be empty.' . $tryagain_link ) );
     169
     170        // Validate $prefix: it can only contain letters, numbers and underscores.
    164171        if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
    165                 wp_die( __( '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' ) );
     172                wp_die( __( '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' . $tryagain_link ) );
    166173
    167174        // Test the db connection.
    168175        /**#@+
     
    170177         */
    171178        define('DB_NAME', $dbname);
    172179        define('DB_USER', $uname);
    173         define('DB_PASSWORD', $passwrd);
     180        define('DB_PASSWORD', $pwd);
    174181        define('DB_HOST', $dbhost);
    175182        /**#@-*/
    176183
    177184        // We'll fail here if the values are no good.
    178185        require_wp_db();
    179         if ( ! empty( $wpdb->error ) ) {
    180                 $back = '<p class="step"><a href="setup-config.php?step=1" onclick="javascript:history.go(-1);return false;" class="button">' . __( 'Try Again' ) . '</a></p>';
    181                 wp_die( $wpdb->error->get_error_message() . $back );
    182         }
     186        if ( ! empty( $wpdb->error ) )
     187                wp_die( $wpdb->error->get_error_message() . $tryagain_link );
    183188
    184189        // Fetch or generate keys and salts.
    185190        $no_api = isset( $_POST['noapi'] );
     
    213218        $key = 0;
    214219        foreach ( $config_file as &$line ) {
    215220                if ( '$table_prefix  =' == substr( $line, 0, 16 ) ) {
    216                         $line = '$table_prefix  = \'' . $prefix . "';\r\n";
     221                        $line = '$table_prefix  = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n";
    217222                        continue;
    218223                }
    219224
     
    228233                        case 'DB_USER'     :
    229234                        case 'DB_PASSWORD' :
    230235                        case 'DB_HOST'     :
    231                                 $line = "define('" . $constant . "'," . $padding . "'" . constant( $constant ) . "');\r\n";
     236                                $line = "define('" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "');\r\n";
    232237                                break;
    233238                        case 'AUTH_KEY'         :
    234239                        case 'SECURE_AUTH_KEY'  :