PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress/wp-admin/setup-config.php

http://suziwen.googlecode.com/
PHP | 194 lines | 138 code | 20 blank | 36 comment | 9 complexity | a0274d5e92f73d086cdd6a2cb85110b1 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-3.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Retrieves and creates the wp-config.php file.
  4. *
  5. * The permissions for the base directory must allow for writing files in order
  6. * for the wp-config.php to be created using this page.
  7. *
  8. * @package WordPress
  9. * @subpackage Administration
  10. */
  11. /**
  12. * We are installing.
  13. *
  14. * @package WordPress
  15. */
  16. define('WP_INSTALLING', true);
  17. /**#@+
  18. * These three defines are required to allow us to use require_wp_db() to load
  19. * the database class while being wp-content/db.php aware.
  20. * @ignore
  21. */
  22. define('ABSPATH', dirname(dirname(__FILE__)).'/');
  23. define('WPINC', 'wp-includes');
  24. define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
  25. /**#@-*/
  26. require_once('../wp-includes/compat.php');
  27. require_once('../wp-includes/functions.php');
  28. require_once('../wp-includes/classes.php');
  29. if (!file_exists('../wp-config-sample.php'))
  30. wp_die('???????? wp-config-sample.php ????????????????????');
  31. $configFile = file('../wp-config-sample.php');
  32. if ( !is_writable('../'))
  33. wp_die("??????????????????????wp-config.php?");
  34. // Check if wp-config.php has been created
  35. if (file_exists('../wp-config.php'))
  36. wp_die("<p>'wp-config.php'???????????? wp-config.php ?????????????????????wp-config.php?<a href='install.php'>??</a>?</p>");
  37. // Check if wp-config.php exists above the root directory
  38. if (file_exists('../../wp-config.php') && ! file_exists('../../wp-load.php'))
  39. wp_die("<p>'wp-config.php'??????????????????? wp-config.php ?????????????????????wp-config.php?<a href='install.php'>??</a>?</p>");
  40. if (isset($_GET['step']))
  41. $step = $_GET['step'];
  42. else
  43. $step = 0;
  44. /**
  45. * Display setup wp-config.php file header.
  46. *
  47. * @ignore
  48. * @since 2.3.0
  49. * @package WordPress
  50. * @subpackage Installer_WP_Config
  51. */
  52. function display_header() {
  53. header( 'Content-Type: text/html; charset=utf-8' );
  54. ?>
  55. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  56. <html xmlns="http://www.w3.org/1999/xhtml">
  57. <head>
  58. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  59. <title>WordPress &rsaquo; ????</title>
  60. <link rel="stylesheet" href="css/install.css" type="text/css" />
  61. </head>
  62. <body>
  63. <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
  64. <?php
  65. }//end function display_header();
  66. switch($step) {
  67. case 0:
  68. display_header();
  69. ?>
  70. <p>???? WordPress ???????????????????????????????????????</p>
  71. <ol>
  72. <li>?????</li>
  73. <li>??????</li>
  74. <li>?????</li>
  75. <li>???????</li>
  76. <li>?????????????????????? WordPress ???</li>
  77. </ol>
  78. <p><strong>???????????????????????? Wordpress ?????????????????????? <code>wp-config-sample.php</code>??????????????????????? <code>wp-config.php</code>?</strong></p>
  79. <p>??????????????????????????????????????????????????? &hellip;</p>
  80. <p class="step"><a href="setup-config.php?step=1" class="button">???????</a></p>
  81. <?php
  82. break;
  83. case 1:
  84. display_header();
  85. ?>
  86. <form method="post" action="setup-config.php?step=2">
  87. <p>????????????????????????????????????????</p>
  88. <table class="form-table">
  89. <tr>
  90. <th scope="row"><label for="dbname">?????</label></th>
  91. <td><input name="dbname" id="dbname" type="text" size="25" value="wordpress" /></td>
  92. <td>???? WordPress ?????????</td>
  93. </tr>
  94. <tr>
  95. <th scope="row"><label for="uname">??????</label></th>
  96. <td><input name="uname" id="uname" type="text" size="25" value="username" /></td>
  97. <td>?? MySQL ???</td>
  98. </tr>
  99. <tr>
  100. <th scope="row"><label for="pwd">?????</label></th>
  101. <td><input name="pwd" id="pwd" type="text" size="25" value="password" /></td>
  102. <td>...?? MySQL ??</td>
  103. </tr>
  104. <tr>
  105. <th scope="row"><label for="dbhost">?????</label></th>
  106. <td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
  107. <td>??????????</td>
  108. </tr>
  109. <tr>
  110. <th scope="row"><label for="prefix">?????</label></th>
  111. <td><input name="prefix" id="prefix" type="text" id="prefix" value="wp_" size="25" /></td>
  112. <td>?????????????? WordPress ?????????</td>
  113. </tr>
  114. </table>
  115. <p class="step"><input name="submit" type="submit" value="???" class="button" /></p>
  116. </form>
  117. <?php
  118. break;
  119. case 2:
  120. $dbname = trim($_POST['dbname']);
  121. $uname = trim($_POST['uname']);
  122. $passwrd = trim($_POST['pwd']);
  123. $dbhost = trim($_POST['dbhost']);
  124. $prefix = trim($_POST['prefix']);
  125. if (empty($prefix)) $prefix = 'wp_';
  126. // Test the db connection.
  127. /**#@+
  128. * @ignore
  129. */
  130. define('DB_NAME', $dbname);
  131. define('DB_USER', $uname);
  132. define('DB_PASSWORD', $passwrd);
  133. define('DB_HOST', $dbhost);
  134. /**#@-*/
  135. // We'll fail here if the values are no good.
  136. require_wp_db();
  137. if ( !empty($wpdb->error) )
  138. wp_die($wpdb->error->get_error_message());
  139. $handle = fopen('../wp-config.php', 'w');
  140. foreach ($configFile as $line_num => $line) {
  141. switch (substr($line,0,16)) {
  142. case "define('DB_NAME'":
  143. fwrite($handle, str_replace("putyourdbnamehere", $dbname, $line));
  144. break;
  145. case "define('DB_USER'":
  146. fwrite($handle, str_replace("'usernamehere'", "'$uname'", $line));
  147. break;
  148. case "define('DB_PASSW":
  149. fwrite($handle, str_replace("'yourpasswordhere'", "'$passwrd'", $line));
  150. break;
  151. case "define('DB_HOST'":
  152. fwrite($handle, str_replace("localhost", $dbhost, $line));
  153. break;
  154. case '$table_prefix =':
  155. fwrite($handle, str_replace('wp_', $prefix, $line));
  156. break;
  157. default:
  158. fwrite($handle, $line);
  159. }
  160. }
  161. fclose($handle);
  162. chmod('../wp-config.php', 0666);
  163. display_header();
  164. ?>
  165. <p>???WordPress????????????????? ?? &hellip;</p>
  166. <p class="step"><a href="install.php" class="button">???</a></p>
  167. <?php
  168. break;
  169. }
  170. ?>
  171. </body>
  172. </html>