Ticket #15729: 15729-2.diff

File 15729-2.diff, 6.5 KB (added by kapeels, 2 years ago)
Line 
1Index: wp-admin/setup-config.php
2===================================================================
3--- wp-admin/setup-config.php   (revision 16800)
4+++ wp-admin/setup-config.php   (working copy)
5@@ -88,14 +88,14 @@
6 <link rel="stylesheet" href="css/install.css" type="text/css" />
7 
8 </head>
9-<body>
10+<body onload="setFocus();">
11 <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
12 <?php
13 }//end function display_header();
14 
15 switch($step) {
16        case 0:
17-               display_header();
18+               display_header();           
19 ?>
20 
21 <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>
22@@ -114,34 +114,64 @@
23        break;
24 
25        case 1:
26-               display_header();
27+            display_header();
28+            if(is_numeric($_POST['error'])) {
29+                switch($_POST['error']) {
30+                    case 1 :
31+                        $error_msg  =  "Cannot connect to the database server with the provided username and password.";
32+                        $focus_ele  =   "uname";
33+                    break;
34+                    case 2 :
35+                        $error_msg  =  "Cannot select the database.";
36+                        $focus_ele  =   "dbname";
37+                    break;
38+                    case 3 :
39+                        $error_msg  =  "The table prefix can contain only letters, numbers, and underscores.";
40+                        $focus_ele  =   "prefix";
41+                    break;
42+                }               
43+                ?>
44+                <script type="text/javascript">
45+                    function setFocus() {
46+                        document.getElementById('<?php echo $focus_ele; ?>').focus();
47+                    }
48+                </script>
49+                <p style="color:red;"><?php echo $error_msg; ?></p>
50+                <?php               
51+            }
52+            $dbname =   !empty($_POST['dbname']) ? trim($_POST['dbname']) : 'wordpress';
53+            $uname  =   !empty($_POST['uname']) ? trim($_POST['uname']) : 'username';
54+            // password can be left blank
55+            $passwrd=   isset($_POST['pwd']) ? $_POST['pwd'] : 'password';
56+            $dbhost =   !empty($_POST['dbhost']) ? trim($_POST['dbhost']) : 'localhost';
57+            $prefix =   !empty($_POST['prefix']) ? trim(htmlspecialchars($_POST['prefix']),ENT_QUOTES) : 'wp_';           
58        ?>
59 <form method="post" action="setup-config.php?step=2">
60        <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
61        <table class="form-table">
62                <tr>
63                        <th scope="row"><label for="dbname">Database Name</label></th>
64-                       <td><input name="dbname" id="dbname" type="text" size="25" value="wordpress" /></td>
65+                       <td><input name="dbname" id="dbname" type="text" size="25" value="<?php echo $dbname; ?>" /></td>
66                        <td>The name of the database you want to run WP in. </td>
67                </tr>
68                <tr>
69                        <th scope="row"><label for="uname">User Name</label></th>
70-                       <td><input name="uname" id="uname" type="text" size="25" value="username" /></td>
71+                       <td><input name="uname" id="uname" type="text" size="25" value="<?php echo $uname; ?>" /></td>
72                        <td>Your MySQL username</td>
73                </tr>
74                <tr>
75                        <th scope="row"><label for="pwd">Password</label></th>
76-                       <td><input name="pwd" id="pwd" type="text" size="25" value="password" /></td>
77+                       <td><input name="pwd" id="pwd" type="text" size="25" value="<?php echo $passwrd; ?>" /></td>
78                        <td>...and MySQL password.</td>
79                </tr>
80                <tr>
81                        <th scope="row"><label for="dbhost">Database Host</label></th>
82-                       <td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
83+                       <td><input name="dbhost" id="dbhost" type="text" size="25" value="<?php echo $dbhost; ?>" /></td>
84                        <td>You should be able to get this info from your web host, if <code>localhost</code> does not work.</td>
85                </tr>
86                <tr>
87                        <th scope="row"><label for="prefix">Table Prefix</label></th>
88-                       <td><input name="prefix" id="prefix" type="text" id="prefix" value="wp_" size="25" /></td>
89+                       <td><input name="prefix" id="prefix" type="text" id="prefix" value="<?php echo $prefix; ?>" size="25" /></td>
90                        <td>If you want to run multiple WordPress installations in a single database, change this.</td>
91                </tr>
92        </table>
93@@ -161,8 +191,10 @@
94                $prefix = 'wp_';
95 
96        // Validate $prefix: it can only contain letters, numbers and underscores
97-       if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
98-               wp_die( /*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ );
99+       if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) {               
100+                $prefix =   htmlspecialchars($prefix,ENT_QUOTES);
101+                setupconfigstep2error('<strong>ERROR</strong>: "Table Prefix" can only contain numbers, letters, and underscores.');                             
102+        }
103 
104        // Test the db connection.
105        /**#@+
106@@ -176,9 +208,8 @@
107 
108        // We'll fail here if the values are no good.
109        require_wp_db();
110-       if ( ! empty( $wpdb->error ) ) {
111-               $back = '<p class="step"><a href="setup-config.php?step=1" onclick="javascript:history.go(-1);return false;" class="button">Try Again</a></p>';
112-               wp_die( $wpdb->error->get_error_message() . $back );
113+       if ( ! empty( $wpdb->error ) ) {               
114+               setupconfigstep2error( $wpdb->error->get_error_message() );
115        }
116 
117        // Fetch or generate keys and salts.
118@@ -272,6 +303,37 @@
119        endif;
120        break;
121 }
122+
123+function setupconfigstep2error($message) {
124+    global $wpdb,$dbname,$uname,$passwrd,$dbhost,$prefix;
125+    $formdo =   '';             
126+    switch(key($wpdb->error->errors)) {
127+        case 'db_connect_fail':
128+           $formdo  =   1;
129+        break;
130+        case 'db_select_fail':
131+           $formdo  =   2;
132+        break;
133+        // table prefix error can't thrown by wpdb
134+        default :
135+           $formdo  =   3;
136+        break;
137+    }
138+       $back = <<<back
139+          <p class="step">
140+    <form action="setup-config.php?step=1" method="post"> 
141+        <input name="error" type="hidden" value="{$formdo}" />
142+        <input name="dbname" type="hidden" value="{$dbname}" />               
143+        <input name="uname" type="hidden" value="{$uname}" />         
144+        <input name="pwd" type="hidden" value="{$passwrd}" />                 
145+        <input name="dbhost" type="hidden" value="{$dbhost}" />               
146+        <input name="prefix" type="hidden" id="prefix" value="{$prefix}" />   
147+        <input type="submit" class="button" value="Try Again" name="try-again">
148+    </form>
149+          </p>
150+back;
151+        wp_die($message . $back);
152+}
153 ?>
154 </body>
155 </html>