Wordpress 2.5.1-scripts
[autoinstalls/wordpress.git] / wp-admin / setup-config.php
1 <?php
2 define('WP_INSTALLING', true);
3 //These two defines are required to allow us to use require_wp_db() to load the database class while being wp-content/wp-db.php aware
4 define('ABSPATH', dirname(dirname(__FILE__)).'/');
5 define('WPINC', 'wp-includes');
6
7 require_once('../wp-includes/compat.php');
8 require_once('../wp-includes/functions.php');
9 require_once('../wp-includes/classes.php');
10
11 if (!file_exists('../wp-config-sample.php'))
12         wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.');
13
14 $configFile = file('../wp-config-sample.php');
15
16 if ( !is_writable('../'))
17         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.");
18
19 // Check if wp-config.php has been created
20 if (file_exists('../wp-config.php'))
21         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>");
22
23 if (isset($_GET['step']))
24         $step = $_GET['step'];
25 else
26         $step = 0;
27
28 function display_header(){
29         header( 'Content-Type: text/html; charset=utf-8' );
30 ?>
31 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32 <html xmlns="http://www.w3.org/1999/xhtml">
33 <head>
34 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
35 <title>WordPress &rsaquo; Setup Configuration File</title>
36 <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install.css" type="text/css" />
37
38 </head>
39 <body>
40 <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
41 <?php
42 }//end function display_header();
43
44 switch($step) {
45         case 0:
46                 display_header();
47 ?>
48
49 <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>
50 <ol>
51         <li>Database name</li>
52         <li>Database username</li>
53         <li>Database password</li>
54         <li>Database host</li>
55         <li>Table prefix (if you want to run more than one WordPress in a single database) </li>
56 </ol>
57 <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>
58 <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&hellip;</p>
59
60 <p><a href="setup-config.php?step=1" class="button">Let&#8217;s go!</a></p>
61 <?php
62         break;
63
64         case 1:
65                 display_header();
66         ?>
67 <form method="post" action="setup-config.php?step=2">
68         <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
69         <table class="form-table">
70                 <tr>
71                         <th scope="row">Database Name</th>
72                         <td><input name="dbname" type="text" size="25" value="wordpress" /></td>
73                         <td>The name of the database you want to run WP in. </td>
74                 </tr>
75                 <tr>
76                         <th scope="row">User Name</th>
77                         <td><input name="uname" type="text" size="25" value="username" /></td>
78                         <td>Your MySQL username</td>
79                 </tr>
80                 <tr>
81                         <th scope="row">Password</th>
82                         <td><input name="pwd" type="text" size="25" value="password" /></td>
83                         <td>...and MySQL password.</td>
84                 </tr>
85                 <tr>
86                         <th scope="row">Database Host</th>
87                         <td><input name="dbhost" type="text" size="25" value="localhost" /></td>
88                         <td>99% chance you won't need to change this value.</td>
89                 </tr>
90                 <tr>
91                         <th scope="row">Table Prefix</th>
92                         <td><input name="prefix" type="text" id="prefix" value="wp_" size="25" /></td>
93                         <td>If you want to run multiple WordPress installations in a single database, change this.</td>
94                 </tr>
95         </table>
96         <h2 class="step">
97         <input name="submit" type="submit" value="Submit" class="button" />
98         </h2>
99 </form>
100 <?php
101         break;
102
103         case 2:
104         $dbname  = trim($_POST['dbname']);
105         $uname   = trim($_POST['uname']);
106         $passwrd = trim($_POST['pwd']);
107         $dbhost  = trim($_POST['dbhost']);
108         $prefix  = trim($_POST['prefix']);
109         if (empty($prefix)) $prefix = 'wp_';
110
111         // Test the db connection.
112         define('DB_NAME', $dbname);
113         define('DB_USER', $uname);
114         define('DB_PASSWORD', $passwrd);
115         define('DB_HOST', $dbhost);
116
117         // We'll fail here if the values are no good.
118         require_wp_db();
119         if ( !empty($wpdb->error) )
120                 wp_die($wpdb->error->get_error_message());
121
122         $handle = fopen('../wp-config.php', 'w');
123
124         foreach ($configFile as $line_num => $line) {
125                 switch (substr($line,0,16)) {
126                         case "define('DB_NAME'":
127                                 fwrite($handle, str_replace("putyourdbnamehere", $dbname, $line));
128                                 break;
129                         case "define('DB_USER'":
130                                 fwrite($handle, str_replace("'usernamehere'", "'$uname'", $line));
131                                 break;
132                         case "define('DB_PASSW":
133                                 fwrite($handle, str_replace("'yourpasswordhere'", "'$passwrd'", $line));
134                                 break;
135                         case "define('DB_HOST'":
136                                 fwrite($handle, str_replace("localhost", $dbhost, $line));
137                                 break;
138                         case '$table_prefix  =':
139                                 fwrite($handle, str_replace('wp_', $prefix, $line));
140                                 break;
141                         default:
142                                 fwrite($handle, $line);
143                 }
144         }
145         fclose($handle);
146         chmod('../wp-config.php', 0666);
147
148         display_header();
149 ?>
150 <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&hellip;</p>
151
152 <p><a href="install.php" class="button">Run the install</a></p>
153 <?php
154         break;
155 }
156 ?>
157 </body>
158 </html>