Make WordPress Core

Changeset 19701


Ignore:
Timestamp:
01/06/2012 06:23:51 PM (13 years ago)
Author:
nacin
Message:

Use regex to fill in config-sample. Prevents translators from needing to manually translate 'database_name_here' (and friends). see #18180.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/setup-config.php

    r19297 r19701  
    5353    wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.');
    5454
    55 $configFile = file(ABSPATH . 'wp-config-sample.php');
     55$config_file = file(ABSPATH . 'wp-config-sample.php');
    5656
    5757// Check if wp-config.php has been created
     
    211211        }
    212212    }
     213
    213214    $key = 0;
    214 
    215     foreach ($configFile as $line_num => $line) {
    216         switch (substr($line,0,16)) {
    217             case "define('DB_NAME'":
    218                 $configFile[$line_num] = str_replace("database_name_here", $dbname, $line);
     215    foreach ( $config_file as &$line ) {
     216        if ( '$table_prefix  =' == substr( $line, 0, 16 ) ) {
     217            $line = '$table_prefix  = \'' . $prefix . "';\r\n";
     218            continue;
     219        }
     220
     221        if ( ! preg_match( '/^define\(\'([A-Z_]+)\',([ ]+)/', $line, $match ) )
     222            continue;
     223
     224        $constant = $match[1];
     225        $padding  = $match[2];
     226
     227        switch ( $constant ) {
     228            case 'DB_NAME'     :
     229            case 'DB_USER'     :
     230            case 'DB_PASSWORD' :
     231            case 'DB_HOST'     :
     232                $line = "define('" . $constant . "'," . $padding . "'" . constant( $constant ) . "');\r\n";
    219233                break;
    220             case "define('DB_USER'":
    221                 $configFile[$line_num] = str_replace("'username_here'", "'$uname'", $line);
     234            case 'AUTH_KEY'         :
     235            case 'SECURE_AUTH_KEY'  :
     236            case 'LOGGED_IN_KEY'    :
     237            case 'NONCE_KEY'        :
     238            case 'AUTH_SALT'        :
     239            case 'SECURE_AUTH_SALT' :
     240            case 'LOGGED_IN_SALT'   :
     241            case 'NONCE_SALT'       :
     242                $line = "define('" . $constant . "'," . $padding . "'" . $secret_keys[$key++] . "');\r\n";
    222243                break;
    223             case "define('DB_PASSW":
    224                 $configFile[$line_num] = str_replace("'password_here'", "'$passwrd'", $line);
    225                 break;
    226             case "define('DB_HOST'":
    227                 $configFile[$line_num] = str_replace("localhost", $dbhost, $line);
    228                 break;
    229             case '$table_prefix  =':
    230                 $configFile[$line_num] = str_replace('wp_', $prefix, $line);
    231                 break;
    232             case "define('AUTH_KEY":
    233             case "define('SECURE_A":
    234             case "define('LOGGED_I":
    235             case "define('NONCE_KE":
    236             case "define('AUTH_SAL":
    237             case "define('SECURE_A":
    238             case "define('LOGGED_I":
    239             case "define('NONCE_SA":
    240                 $configFile[$line_num] = str_replace('put your unique phrase here', $secret_keys[$key++], $line );
    241                 break;
    242         }
    243     }
     244        }
     245    }
     246    unset( $line );
     247
    244248    if ( ! is_writable(ABSPATH) ) :
    245249        display_header();
     
    248252<p>You can create the <code>wp-config.php</code> manually and paste the following text into it.</p>
    249253<textarea cols="98" rows="15" class="code"><?php
    250         foreach( $configFile as $line ) {
     254        foreach( $config_file as $line ) {
    251255            echo htmlentities($line, ENT_COMPAT, 'UTF-8');
    252256        }
     
    257261    else :
    258262        $handle = fopen(ABSPATH . 'wp-config.php', 'w');
    259         foreach( $configFile as $line ) {
     263        foreach( $config_file as $line ) {
    260264            fwrite($handle, $line);
    261265        }
Note: See TracChangeset for help on using the changeset viewer.