Ticket #15729: 15729-7.diff
File 15729-7.diff, 7.8 KB (added by , 14 years ago) |
---|
-
wp-admin/setup-config.php
88 88 <link rel="stylesheet" href="css/install.css" type="text/css" /> 89 89 90 90 </head> 91 <body >91 <body onload="setFocus();"> 92 92 <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1> 93 93 <?php 94 94 }//end function display_header(); … … 114 114 break; 115 115 116 116 case 1: 117 display_header(); 117 display_header(); 118 if ( isset( $_POST['setup_error'] ) ) { 119 switch( $_POST['setup_error'] ) { 120 case 'db_connect_fail' : 121 $error_msg = "Cannot connect to the database server with the provided username,password and host combination."; 122 $focus_element = "uname"; 123 break; 124 case 'db_select_fail' : 125 $error_msg = "Cannot select the database."; 126 $focus_element = "dbname"; 127 break; 128 case 'invalid_prefix' : 129 $error_msg = "The table prefix can contain only letters, numbers, and underscores."; 130 $focus_element = "prefix"; 131 break; 132 } 133 ?> 134 <script type="text/javascript"> 135 function setFocus() { 136 document.getElementById( '<?php echo $focus_element; ?>' ).focus(); 137 } 138 </script> 139 <p style="color:red;"><?php echo $error_msg; ?></p> 140 <?php 141 } 142 $dbname = !empty( $_POST['dbname'] ) ? trim( $_POST['dbname'] ) : 'wordpress'; 143 $uname = !empty( $_POST['uname'] ) ? trim( $_POST['uname'] ) : 'username'; 144 // password can be left blank 145 $password= isset( $_POST['pwd'] ) ? $_POST['pwd'] : 'password'; 146 $dbhost = !empty( $_POST['dbhost'] ) ? trim( $_POST['dbhost'] ) : 'localhost'; 147 $prefix = !empty( $_POST['prefix'] ) ? trim( $_POST['prefix'] ) : 'wp_'; 118 148 ?> 119 149 <form method="post" action="setup-config.php?step=2"> 120 150 <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p> 121 151 <table class="form-table"> 122 152 <tr> 123 153 <th scope="row"><label for="dbname">Database Name</label></th> 124 <td><input name="dbname" id="dbname" type="text" size="25" value=" wordpress" /></td>154 <td><input name="dbname" id="dbname" type="text" size="25" value="<?php echo htmlspecialchars( $dbname, ENT_QUOTES ); ?>" /></td> 125 155 <td>The name of the database you want to run WP in. </td> 126 156 </tr> 127 157 <tr> 128 158 <th scope="row"><label for="uname">User Name</label></th> 129 <td><input name="uname" id="uname" type="text" size="25" value=" username" /></td>159 <td><input name="uname" id="uname" type="text" size="25" value="<?php echo htmlspecialchars( $uname, ENT_QUOTES ); ?>" /></td> 130 160 <td>Your MySQL username</td> 131 161 </tr> 132 162 <tr> 133 163 <th scope="row"><label for="pwd">Password</label></th> 134 <td><input name="pwd" id="pwd" type="text" size="25" value=" password" /></td>164 <td><input name="pwd" id="pwd" type="text" size="25" value="<?php echo htmlspecialchars( $password, ENT_QUOTES ); ?>" /></td> 135 165 <td>...and MySQL password.</td> 136 166 </tr> 137 167 <tr> 138 168 <th scope="row"><label for="dbhost">Database Host</label></th> 139 <td><input name="dbhost" id="dbhost" type="text" size="25" value=" localhost" /></td>169 <td><input name="dbhost" id="dbhost" type="text" size="25" value="<?php echo htmlspecialchars( $dbhost, ENT_QUOTES ); ?>" /></td> 140 170 <td>You should be able to get this info from your web host, if <code>localhost</code> does not work.</td> 141 171 </tr> 142 172 <tr> 143 173 <th scope="row"><label for="prefix">Table Prefix</label></th> 144 <td><input name="prefix" id="prefix" type="text" id="prefix" value=" wp_" size="25" /></td>174 <td><input name="prefix" id="prefix" type="text" id="prefix" value="<?php echo htmlspecialchars( $prefix, ENT_QUOTES ); ?>" size="25" /></td> 145 175 <td>If you want to run multiple WordPress installations in a single database, change this.</td> 146 176 </tr> 147 177 </table> … … 154 184 case 2: 155 185 $dbname = trim($_POST['dbname']); 156 186 $uname = trim($_POST['uname']); 157 $passw rd = trim($_POST['pwd']);187 $password = trim($_POST['pwd']); 158 188 $dbhost = trim($_POST['dbhost']); 159 189 $prefix = trim($_POST['prefix']); 160 190 if ( empty($prefix) ) 161 $prefix = 'wp_'; 162 191 $prefix = 'wp_'; 192 $setup_error = null; 163 193 // Validate $prefix: it can only contain letters, numbers and underscores 164 if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) 165 wp_die( /*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ ); 194 if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) { 195 $prefix = htmlspecialchars( $prefix, ENT_QUOTES ); 196 $setup_error = new WP_Error( 'invalid_prefix', '<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.' ); 197 } 198 // prefix is good, let's continue 199 else { 200 // Test the db connection. 201 /**#@+ 202 * @ignore 203 */ 204 define('DB_NAME', $dbname); 205 define('DB_USER', $uname); 206 define('DB_PASSWORD', $password); 207 define('DB_HOST', $dbhost); 208 /**#@-*/ 166 209 167 // Test the db connection. 168 /**#@+ 169 * @ignore 170 */ 171 define('DB_NAME', $dbname); 172 define('DB_USER', $uname); 173 define('DB_PASSWORD', $passwrd); 174 define('DB_HOST', $dbhost); 175 /**#@-*/ 176 177 // We'll fail here if the values are no good. 178 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 } 183 210 // We'll fail here if the values are no good. 211 require_wp_db(); 212 if ( ! empty( $wpdb->error ) ) { 213 $setup_error = $wpdb->error; 214 } 215 } 216 // check if any error occured above 217 if ( $setup_error->get_error_code() ) { 218 $try_again = '<p class="step"> 219 <form action="setup-config.php?step=1" method="post"> 220 <input name="setup_error" type="hidden" value="' . $setup_error->get_error_code() . '" /> 221 <input name="dbname" type="hidden" value="' . htmlspecialchars( $dbname, ENT_QUOTES ) . '" /> 222 <input name="uname" type="hidden" value="' . htmlspecialchars( $uname, ENT_QUOTES ) . '" /> 223 <input name="pwd" type="hidden" value="' . htmlspecialchars( $password, ENT_QUOTES ) . '" /> 224 <input name="dbhost" type="hidden" value="' . htmlspecialchars( $dbhost, ENT_QUOTES ) . '" /> 225 <input name="prefix" type="hidden" id="prefix" value="' . $prefix . '" /> 226 <input type="submit" class="button" value="Try Again" name="try-again" /> 227 </form> 228 </p>'; 229 wp_die( $setup_error->get_error_message() . $try_again ); 230 } 184 231 // Fetch or generate keys and salts. 185 232 $no_api = isset( $_POST['noapi'] ); 186 233 require_once( ABSPATH . WPINC . '/plugin.php' ); … … 223 270 $configFile[$line_num] = str_replace("'username_here'", "'$uname'", $line); 224 271 break; 225 272 case "define('DB_PASSW": 226 $configFile[$line_num] = str_replace("'password_here'", "'$passw rd'", $line);273 $configFile[$line_num] = str_replace("'password_here'", "'$password'", $line); 227 274 break; 228 275 case "define('DB_HOST'": 229 276 $configFile[$line_num] = str_replace("localhost", $dbhost, $line);