Ticket #15729: 15729-3.diff
File 15729-3.diff, 6.5 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(); 95 95 96 96 switch($step) { 97 97 case 0: 98 display_header(); 98 display_header(); 99 99 ?> 100 100 101 101 <p>Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.</p> … … 114 114 break; 115 115 116 116 case 1: 117 display_header(); 117 display_header(); 118 if(is_numeric($_POST['error'])) { 119 switch($_POST['error']) { 120 case 1 : 121 $error_msg = "Cannot connect to the database server with the provided username and password."; 122 $focus_ele = "uname"; 123 break; 124 case 2 : 125 $error_msg = "Cannot select the database."; 126 $focus_ele = "dbname"; 127 break; 128 case 3 : 129 $error_msg = "The table prefix can contain only letters, numbers, and underscores."; 130 $focus_ele = "prefix"; 131 break; 132 } 133 ?> 134 <script type="text/javascript"> 135 function setFocus() { 136 document.getElementById('<?php echo $focus_ele; ?>').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 $passwrd= isset($_POST['pwd']) ? $_POST['pwd'] : 'password'; 146 $dbhost = !empty($_POST['dbhost']) ? trim($_POST['dbhost']) : 'localhost'; 147 $prefix = !empty($_POST['prefix']) ? trim(htmlspecialchars($_POST['prefix']),ENT_QUOTES) : '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 $dbname; ?>" /></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 $uname; ?>" /></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 $passwrd; ?>" /></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 $dbhost; ?>" /></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 $prefix; ?>" 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> … … 161 191 $prefix = 'wp_'; 162 192 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 setupconfigstep2error('<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.'); 197 } 166 198 167 199 // Test the db connection. 168 200 /**#@+ … … 176 208 177 209 // We'll fail here if the values are no good. 178 210 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 ); 211 if ( ! empty( $wpdb->error ) ) { 212 setupconfigstep2error( $wpdb->error->get_error_message() ); 182 213 } 183 214 184 215 // Fetch or generate keys and salts. … … 272 303 endif; 273 304 break; 274 305 } 306 307 function setupconfigstep2error($message) { 308 global $wpdb,$dbname,$uname,$passwrd,$dbhost,$prefix; 309 $formdo = ''; 310 switch(key($wpdb->error->errors)) { 311 case 'db_connect_fail': 312 $formdo = 1; 313 break; 314 case 'db_select_fail': 315 $formdo = 2; 316 break; 317 // table prefix error can't thrown by wpdb 318 default : 319 $formdo = 3; 320 break; 321 } 322 $back = '<p class="step"> 323 <form action="setup-config.php?step=1" method="post"> 324 <input name="error" type="hidden" value="' . $formdo . '" /> 325 <input name="dbname" type="hidden" value="' .$dbname. '" /> 326 <input name="uname" type="hidden" value="' .$uname. '" /> 327 <input name="pwd" type="hidden" value="' .$passwrd. '" /> 328 <input name="dbhost" type="hidden" value="' .$dbhost. '" /> 329 <input name="prefix" type="hidden" id="prefix" value="' .$prefix. '" /> 330 <input type="submit" class="button" value="Try Again" name="try-again"> 331 </form> 332 </p>'; 333 wp_die($message . $back); 334 } 275 335 ?> 276 336 </body> 277 337 </html>