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