Skip to content

Commit

Permalink
Use regex to fill in config-sample. Prevents translators from needing…
Browse files Browse the repository at this point in the history
… to manually translate 'database_name_here' (and friends). see #18180.

git-svn-id: http://svn.automattic.com/wordpress/trunk@19701 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
nacin committed Jan 6, 2012
1 parent f9b5548 commit e5589e0
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions wp-admin/setup-config.php
Expand Up @@ -52,7 +52,7 @@
if (!file_exists(ABSPATH . 'wp-config-sample.php'))
wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.');

$configFile = file(ABSPATH . 'wp-config-sample.php');
$config_file = file(ABSPATH . 'wp-config-sample.php');

// Check if wp-config.php has been created
if (file_exists(ABSPATH . 'wp-config.php'))
Expand Down Expand Up @@ -210,44 +210,48 @@ function get_bloginfo() {
$secret_keys[$k] = substr( $v, 28, 64 );
}
}

$key = 0;
foreach ( $config_file as &$line ) {
if ( '$table_prefix =' == substr( $line, 0, 16 ) ) {
$line = '$table_prefix = \'' . $prefix . "';\r\n";
continue;
}

foreach ($configFile as $line_num => $line) {
switch (substr($line,0,16)) {
case "define('DB_NAME'":
$configFile[$line_num] = str_replace("database_name_here", $dbname, $line);
break;
case "define('DB_USER'":
$configFile[$line_num] = str_replace("'username_here'", "'$uname'", $line);
break;
case "define('DB_PASSW":
$configFile[$line_num] = str_replace("'password_here'", "'$passwrd'", $line);
break;
case "define('DB_HOST'":
$configFile[$line_num] = str_replace("localhost", $dbhost, $line);
break;
case '$table_prefix =':
$configFile[$line_num] = str_replace('wp_', $prefix, $line);
if ( ! preg_match( '/^define\(\'([A-Z_]+)\',([ ]+)/', $line, $match ) )
continue;

$constant = $match[1];
$padding = $match[2];

switch ( $constant ) {
case 'DB_NAME' :
case 'DB_USER' :
case 'DB_PASSWORD' :
case 'DB_HOST' :
$line = "define('" . $constant . "'," . $padding . "'" . constant( $constant ) . "');\r\n";
break;
case "define('AUTH_KEY":
case "define('SECURE_A":
case "define('LOGGED_I":
case "define('NONCE_KE":
case "define('AUTH_SAL":
case "define('SECURE_A":
case "define('LOGGED_I":
case "define('NONCE_SA":
$configFile[$line_num] = str_replace('put your unique phrase here', $secret_keys[$key++], $line );
case 'AUTH_KEY' :
case 'SECURE_AUTH_KEY' :
case 'LOGGED_IN_KEY' :
case 'NONCE_KEY' :
case 'AUTH_SALT' :
case 'SECURE_AUTH_SALT' :
case 'LOGGED_IN_SALT' :
case 'NONCE_SALT' :
$line = "define('" . $constant . "'," . $padding . "'" . $secret_keys[$key++] . "');\r\n";
break;
}
}
unset( $line );

if ( ! is_writable(ABSPATH) ) :
display_header();
?>
<p>Sorry, but I can't write the <code>wp-config.php</code> file.</p>
<p>You can create the <code>wp-config.php</code> manually and paste the following text into it.</p>
<textarea cols="98" rows="15" class="code"><?php
foreach( $configFile as $line ) {
foreach( $config_file as $line ) {
echo htmlentities($line, ENT_COMPAT, 'UTF-8');
}
?></textarea>
Expand All @@ -256,7 +260,7 @@ function get_bloginfo() {
<?php
else :
$handle = fopen(ABSPATH . 'wp-config.php', 'w');
foreach( $configFile as $line ) {
foreach( $config_file as $line ) {
fwrite($handle, $line);
}
fclose($handle);
Expand Down

0 comments on commit e5589e0

Please sign in to comment.