Use regex to fill in config-sample. Prevents translators from needing 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
This commit is contained in:
nacin 2012-01-06 18:23:51 +00:00
parent f9b554814e
commit e5589e02b7
1 changed files with 33 additions and 29 deletions

View File

@ -52,7 +52,7 @@ require_once(ABSPATH . WPINC . '/class-wp-error.php');
if (!file_exists(ABSPATH . 'wp-config-sample.php')) 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.'); 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 // Check if wp-config.php has been created
if (file_exists(ABSPATH . 'wp-config.php')) if (file_exists(ABSPATH . 'wp-config.php'))
@ -210,44 +210,48 @@ switch($step) {
$secret_keys[$k] = substr( $v, 28, 64 ); $secret_keys[$k] = substr( $v, 28, 64 );
} }
} }
$key = 0;
foreach ($configFile as $line_num => $line) { $key = 0;
switch (substr($line,0,16)) { foreach ( $config_file as &$line ) {
case "define('DB_NAME'": if ( '$table_prefix =' == substr( $line, 0, 16 ) ) {
$configFile[$line_num] = str_replace("database_name_here", $dbname, $line); $line = '$table_prefix = \'' . $prefix . "';\r\n";
continue;
}
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; break;
case "define('DB_USER'": case 'AUTH_KEY' :
$configFile[$line_num] = str_replace("'username_here'", "'$uname'", $line); case 'SECURE_AUTH_KEY' :
break; case 'LOGGED_IN_KEY' :
case "define('DB_PASSW": case 'NONCE_KEY' :
$configFile[$line_num] = str_replace("'password_here'", "'$passwrd'", $line); case 'AUTH_SALT' :
break; case 'SECURE_AUTH_SALT' :
case "define('DB_HOST'": case 'LOGGED_IN_SALT' :
$configFile[$line_num] = str_replace("localhost", $dbhost, $line); case 'NONCE_SALT' :
break; $line = "define('" . $constant . "'," . $padding . "'" . $secret_keys[$key++] . "');\r\n";
case '$table_prefix =':
$configFile[$line_num] = str_replace('wp_', $prefix, $line);
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 );
break; break;
} }
} }
unset( $line );
if ( ! is_writable(ABSPATH) ) : if ( ! is_writable(ABSPATH) ) :
display_header(); display_header();
?> ?>
<p>Sorry, but I can't write the <code>wp-config.php</code> file.</p> <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> <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 <textarea cols="98" rows="15" class="code"><?php
foreach( $configFile as $line ) { foreach( $config_file as $line ) {
echo htmlentities($line, ENT_COMPAT, 'UTF-8'); echo htmlentities($line, ENT_COMPAT, 'UTF-8');
} }
?></textarea> ?></textarea>
@ -256,7 +260,7 @@ switch($step) {
<?php <?php
else : else :
$handle = fopen(ABSPATH . 'wp-config.php', 'w'); $handle = fopen(ABSPATH . 'wp-config.php', 'w');
foreach( $configFile as $line ) { foreach( $config_file as $line ) {
fwrite($handle, $line); fwrite($handle, $line);
} }
fclose($handle); fclose($handle);