PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

title

Body

[close]

/wp-admin/ -> setup-config.php (source)

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


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt