Wordpress 2.3.2
[autoinstalls/wordpress.git] / wp-admin / setup-config.php
1 <?php
2 define('WP_INSTALLING', true);
3
4 require_once('../wp-includes/compat.php');
5 require_once('../wp-includes/functions.php');
6 require_once('../wp-includes/classes.php');
7
8 if (!file_exists('../wp-config-sample.php'))
9         wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.');
10
11 $configFile = file('../wp-config-sample.php');
12
13 if ( !is_writable('../')) 
14         wp_die("Sorry, I can't write to the directory. You'll have to either change the permissions on your WordPress directory or create your wp-config.php manually.");
15
16 // Check if wp-config.php has been created
17 if (file_exists('../wp-config.php'))
18         wp_die("<p>The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href='install.php'>installing now</a>.</p>");
19
20 if (isset($_GET['step']))
21         $step = $_GET['step'];
22 else
23         $step = 0;
24
25 function display_header(){
26         header( 'Content-Type: text/html; charset=utf-8' );
27 ?>
28 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
29 <html xmlns="http://www.w3.org/1999/xhtml">
30 <head>
31 <title>WordPress &rsaquo; Setup Configuration File</title>
32 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
33 <style media="screen" type="text/css">
34         <!--
35         html {
36                 background: #eee;
37         }
38         body {
39                 background: #fff;
40                 color: #000;
41                 font-family: Georgia, "Times New Roman", Times, serif;
42                 margin-left: 20%;
43                 margin-right: 20%;
44                 padding: .2em 2em;
45         }
46
47         h1 {
48                 color: #006;
49                 font-size: 18px;
50                 font-weight: lighter;
51         }
52
53         h2 {
54                 font-size: 16px;
55         }
56
57         p, li, dt {
58                 line-height: 140%;
59                 padding-bottom: 2px;
60         }
61
62         ul, ol {
63                 padding: 5px 5px 5px 20px;
64         }
65         #logo {
66                 margin-bottom: 2em;
67         }
68         .step a, .step input {
69                 font-size: 2em;
70         }
71         td input {
72                 font-size: 1.5em;
73         }
74         .step, th {
75                 text-align: right;
76         }
77         #footer {
78                 text-align: center;
79                 border-top: 1px solid #ccc;
80                 padding-top: 1em;
81                 font-style: italic;
82         }
83         -->
84         </style>
85 </head>
86 <body>
87 <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
88 <?php
89 }//end function display_header();
90
91 switch($step) {
92         case 0:
93                 display_header();
94 ?>
95
96 <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>
97 <ol>
98         <li>Database name</li>
99         <li>Database username</li>
100         <li>Database password</li>
101         <li>Database host</li>
102         <li>Table prefix (if you want to run more than one WordPress in a single database) </li>
103 </ol>
104 <p><strong>If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open <code>wp-config-sample.php</code> in a text editor, fill in your information, and save it as <code>wp-config.php</code>. </strong></p>
105 <p>In all likelihood, these items were supplied to you by your ISP. If you do not have this information, then you will need to contact them before you can continue. If you&#8217;re all ready, <a href="setup-config.php?step=1">let&#8217;s go</a>! </p>
106 <?php
107         break;
108
109         case 1:
110                 display_header();
111         ?>
112 </p>
113 <form method="post" action="setup-config.php?step=2">
114         <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
115         <table>
116                 <tr>
117                         <th scope="row">Database Name</th>
118                         <td><input name="dbname" type="text" size="25" value="wordpress" /></td>
119                         <td>The name of the database you want to run WP in. </td>
120                 </tr>
121                 <tr>
122                         <th scope="row">User Name</th>
123                         <td><input name="uname" type="text" size="25" value="username" /></td>
124                         <td>Your MySQL username</td>
125                 </tr>
126                 <tr>
127                         <th scope="row">Password</th>
128                         <td><input name="pwd" type="text" size="25" value="password" /></td>
129                         <td>...and MySQL password.</td>
130                 </tr>
131                 <tr>
132                         <th scope="row">Database Host</th>
133                         <td><input name="dbhost" type="text" size="25" value="localhost" /></td>
134                         <td>99% chance you won't need to change this value.</td>
135                 </tr>
136                 <tr>
137                         <th scope="row">Table Prefix</th>
138                         <td><input name="prefix" type="text" id="prefix" value="wp_" size="25" /></td>
139                         <td>If you want to run multiple WordPress installations in a single database, change this.</td>
140                 </tr>
141         </table>
142         <h2 class="step">
143         <input name="submit" type="submit" value="Submit" />
144         </h2>
145 </form>
146 <?php
147         break;
148
149         case 2:
150         $dbname  = trim($_POST['dbname']);
151         $uname   = trim($_POST['uname']);
152         $passwrd = trim($_POST['pwd']);
153         $dbhost  = trim($_POST['dbhost']);
154         $prefix  = trim($_POST['prefix']);
155         if (empty($prefix)) $prefix = 'wp_';
156
157         // Test the db connection.
158         define('DB_NAME', $dbname);
159         define('DB_USER', $uname);
160         define('DB_PASSWORD', $passwrd);
161         define('DB_HOST', $dbhost);
162
163         // We'll fail here if the values are no good.
164         require_once('../wp-includes/wp-db.php');
165         if ( !empty($wpdb->error) )
166                 wp_die($wpdb->error->get_error_message());
167
168         $handle = fopen('../wp-config.php', 'w');
169
170         foreach ($configFile as $line_num => $line) {
171                 switch (substr($line,0,16)) {
172                         case "define('DB_NAME'":
173                                 fwrite($handle, str_replace("putyourdbnamehere", $dbname, $line));
174                                 break;
175                         case "define('DB_USER'":
176                                 fwrite($handle, str_replace("'usernamehere'", "'$uname'", $line));
177                                 break;
178                         case "define('DB_PASSW":
179                                 fwrite($handle, str_replace("'yourpasswordhere'", "'$passwrd'", $line));
180                                 break;
181                         case "define('DB_HOST'":
182                                 fwrite($handle, str_replace("localhost", $dbhost, $line));
183                                 break;
184                         case '$table_prefix  =':
185                                 fwrite($handle, str_replace('wp_', $prefix, $line));
186                                 break;
187                         default:
188                                 fwrite($handle, $line);
189                 }
190         }
191         fclose($handle);
192         chmod('../wp-config.php', 0666);
193         
194         display_header();
195 ?>
196 <p>All right sparky! You've made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to <a href="install.php">run the install!</a></p>
197 <?php
198         break;
199 }
200 ?>
201 <p id="footer"><a href="http://wordpress.org/">WordPress</a>, personal publishing platform.</p>
202 </body>
203 </html>