install.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <?php
  2. /**
  3. * WordPress Installer
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. // Sanity check.
  9. if ( false ) {
  10. ?>
  11. <!DOCTYPE html>
  12. <html xmlns="http://www.w3.org/1999/xhtml">
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  15. <title>Error: PHP is not running</title>
  16. </head>
  17. <body class="wp-core-ui">
  18. <p id="logo"><a href="https://wordpress.org/">WordPress</a></p>
  19. <h1>Error: PHP is not running</h1>
  20. <p>WordPress requires that your web server is running PHP. Your server does not have PHP installed, or PHP is turned off.</p>
  21. </body>
  22. </html>
  23. <?php
  24. }
  25. /**
  26. * We are installing WordPress.
  27. *
  28. * @since 1.5.1
  29. * @var bool
  30. */
  31. define( 'WP_INSTALLING', true );
  32. /** Load WordPress Bootstrap */
  33. require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
  34. /** Load WordPress Administration Upgrade API */
  35. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  36. /** Load WordPress Translation Install API */
  37. require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
  38. /** Load wpdb */
  39. require_once( ABSPATH . WPINC . '/wp-db.php' );
  40. nocache_headers();
  41. $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0;
  42. /**
  43. * Display installation header.
  44. *
  45. * @since 2.5.0
  46. *
  47. * @param string $body_classes
  48. */
  49. function display_header( $body_classes = '' ) {
  50. header( 'Content-Type: text/html; charset=utf-8' );
  51. if ( is_rtl() ) {
  52. $body_classes .= 'rtl';
  53. }
  54. if ( $body_classes ) {
  55. $body_classes = ' ' . $body_classes;
  56. }
  57. ?>
  58. <!DOCTYPE html>
  59. <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
  60. <head>
  61. <meta name="viewport" content="width=device-width" />
  62. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  63. <meta name="robots" content="noindex,nofollow" />
  64. <title><?php _e( 'WordPress &rsaquo; Installation' ); ?></title>
  65. <?php
  66. wp_admin_css( 'install', true );
  67. wp_admin_css( 'dashicons', true );
  68. ?>
  69. </head>
  70. <body class="wp-core-ui<?php echo $body_classes ?>">
  71. <p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>" tabindex="-1"><?php _e( 'WordPress' ); ?></a></p>
  72. <?php
  73. } // end display_header()
  74. /**
  75. * Display installer setup form.
  76. *
  77. * @since 2.8.0
  78. *
  79. * @global wpdb $wpdb WordPress database abstraction object.
  80. *
  81. * @param string|null $error
  82. */
  83. function display_setup_form( $error = null ) {
  84. global $wpdb;
  85. $sql = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->users ) );
  86. $user_table = ( $wpdb->get_var( $sql ) != null );
  87. // Ensure that Blogs appear in search engines by default.
  88. $blog_public = 1;
  89. if ( isset( $_POST['weblog_title'] ) ) {
  90. $blog_public = isset( $_POST['blog_public'] );
  91. }
  92. $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
  93. $user_name = isset($_POST['user_name']) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
  94. $admin_email = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
  95. if ( ! is_null( $error ) ) {
  96. ?>
  97. <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
  98. <p class="message"><?php echo $error; ?></p>
  99. <?php } ?>
  100. <form id="setup" method="post" action="install.php?step=2" novalidate="novalidate">
  101. <table class="form-table">
  102. <tr>
  103. <th scope="row"><label for="weblog_title"><?php _e( 'Site Title' ); ?></label></th>
  104. <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo esc_attr( $weblog_title ); ?>" /></td>
  105. </tr>
  106. <tr>
  107. <th scope="row"><label for="user_login"><?php _e('Username'); ?></label></th>
  108. <td>
  109. <?php
  110. if ( $user_table ) {
  111. _e('User(s) already exists.');
  112. echo '<input name="user_name" type="hidden" value="admin" />';
  113. } else {
  114. ?><input name="user_name" type="text" id="user_login" size="25" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" />
  115. <p><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods, and the @ symbol.' ); ?></p>
  116. <?php
  117. } ?>
  118. </td>
  119. </tr>
  120. <?php if ( ! $user_table ) : ?>
  121. <tr class="form-field form-required user-pass1-wrap">
  122. <th scope="row">
  123. <label for="pass1">
  124. <?php _e( 'Password' ); ?>
  125. </label>
  126. </th>
  127. <td>
  128. <div class="">
  129. <?php $initial_password = isset( $_POST['admin_password'] ) ? stripslashes( $_POST['admin_password'] ) : wp_generate_password( 18 ); ?>
  130. <input type="password" name="admin_password" id="pass1" class="regular-text" autocomplete="off" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" />
  131. <button type="button" class="button wp-hide-pw hide-if-no-js" data-start-masked="<?php echo (int) isset( $_POST['admin_password'] ); ?>" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
  132. <span class="dashicons dashicons-hidden"></span>
  133. <span class="text"><?php _e( 'Hide' ); ?></span>
  134. </button>
  135. <div id="pass-strength-result" aria-live="polite"></div>
  136. </div>
  137. <p><span class="description important hide-if-no-js">
  138. <strong><?php _e( 'Important:' ); ?></strong>
  139. <?php /* translators: The non-breaking space prevents 1Password from thinking the text "log in" should trigger a password save prompt. */ ?>
  140. <?php _e( 'You will need this password to log&nbsp;in. Please store it in a secure location.' ); ?></span></p>
  141. </td>
  142. </tr>
  143. <tr class="form-field form-required user-pass2-wrap hide-if-js">
  144. <th scope="row">
  145. <label for="pass2"><?php _e( 'Repeat Password' ); ?>
  146. <span class="description"><?php _e( '(required)' ); ?></span>
  147. </label>
  148. </th>
  149. <td>
  150. <input name="admin_password2" type="password" id="pass2" autocomplete="off" />
  151. </td>
  152. </tr>
  153. <tr class="pw-weak">
  154. <th scope="row"><?php _e( 'Confirm Password' ); ?></th>
  155. <td>
  156. <label>
  157. <input type="checkbox" name="pw_weak" class="pw-checkbox" />
  158. <?php _e( 'Confirm use of weak password' ); ?>
  159. </label>
  160. </td>
  161. </tr>
  162. <?php endif; ?>
  163. <tr>
  164. <th scope="row"><label for="admin_email"><?php _e( 'Your Email' ); ?></label></th>
  165. <td><input name="admin_email" type="email" id="admin_email" size="25" value="<?php echo esc_attr( $admin_email ); ?>" />
  166. <p><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
  167. </tr>
  168. <tr>
  169. <th scope="row"><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site Visibility' ) : _e( 'Search Engine Visibility' ); ?></th>
  170. <td>
  171. <fieldset>
  172. <legend class="screen-reader-text"><span><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site Visibility' ) : _e( 'Search Engine Visibility' ); ?> </span></legend>
  173. <?php
  174. if ( has_action( 'blog_privacy_selector' ) ) { ?>
  175. <input id="blog-public" type="radio" name="blog_public" value="1" <?php checked( 1, $blog_public ); ?> />
  176. <label for="blog-public"><?php _e( 'Allow search engines to index this site' );?></label><br/>
  177. <input id="blog-norobots" type="radio" name="blog_public" value="0" <?php checked( 0, $blog_public ); ?> />
  178. <label for="blog-norobots"><?php _e( 'Discourage search engines from indexing this site' ); ?></label>
  179. <p class="description"><?php _e( 'Note: Neither of these options blocks access to your site &mdash; it is up to search engines to honor your request.' ); ?></p>
  180. <?php
  181. /** This action is documented in wp-admin/options-reading.php */
  182. do_action( 'blog_privacy_selector' );
  183. } else { ?>
  184. <label for="blog_public"><input name="blog_public" type="checkbox" id="blog_public" value="0" <?php checked( 0, $blog_public ); ?> />
  185. <?php _e( 'Discourage search engines from indexing this site' ); ?></label>
  186. <p class="description"><?php _e( 'It is up to search engines to honor this request.' ); ?></p>
  187. <?php } ?>
  188. </fieldset>
  189. </td>
  190. </tr>
  191. </table>
  192. <p class="step"><?php submit_button( __( 'Install WordPress' ), 'large', 'Submit', false, array( 'id' => 'submit' ) ); ?></p>
  193. <input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" />
  194. </form>
  195. <?php
  196. } // end display_setup_form()
  197. // Let's check to make sure WP isn't already installed.
  198. if ( is_blog_installed() ) {
  199. display_header();
  200. die(
  201. '<h1>' . __( 'Already Installed' ) . '</h1>' .
  202. '<p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p>' .
  203. '<p class="step"><a href="' . esc_url( wp_login_url() ) . '" class="button button-large">' . __( 'Log In' ) . '</a></p>' .
  204. '</body></html>'
  205. );
  206. }
  207. /**
  208. * @global string $wp_version
  209. * @global string $required_php_version
  210. * @global string $required_mysql_version
  211. * @global wpdb $wpdb
  212. */
  213. global $wp_version, $required_php_version, $required_mysql_version;
  214. $php_version = phpversion();
  215. $mysql_version = $wpdb->db_version();
  216. $php_compat = version_compare( $php_version, $required_php_version, '>=' );
  217. $mysql_compat = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' );
  218. if ( !$mysql_compat && !$php_compat ) {
  219. /* translators: 1: WordPress version number, 2: Minimum required PHP version number, 3: Minimum required MySQL version number, 4: Current PHP version number, 5: Current MySQL version number */
  220. $compat = sprintf( __( 'You cannot install because <a href="https://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.' ), $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version );
  221. } elseif ( !$php_compat ) {
  222. /* translators: 1: WordPress version number, 2: Minimum required PHP version number, 3: Current PHP version number */
  223. $compat = sprintf( __( 'You cannot install because <a href="https://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher. You are running version %3$s.' ), $wp_version, $required_php_version, $php_version );
  224. } elseif ( !$mysql_compat ) {
  225. /* translators: 1: WordPress version number, 2: Minimum required MySQL version number, 3: Current MySQL version number */
  226. $compat = sprintf( __( 'You cannot install because <a href="https://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires MySQL version %2$s or higher. You are running version %3$s.' ), $wp_version, $required_mysql_version, $mysql_version );
  227. }
  228. if ( !$mysql_compat || !$php_compat ) {
  229. display_header();
  230. die( '<h1>' . __( 'Insufficient Requirements' ) . '</h1><p>' . $compat . '</p></body></html>' );
  231. }
  232. if ( ! is_string( $wpdb->base_prefix ) || '' === $wpdb->base_prefix ) {
  233. display_header();
  234. die(
  235. '<h1>' . __( 'Configuration Error' ) . '</h1>' .
  236. '<p>' . sprintf(
  237. /* translators: %s: wp-config.php */
  238. __( 'Your %s file has an empty database table prefix, which is not supported.' ),
  239. '<code>wp-config.php</code>'
  240. ) . '</p></body></html>'
  241. );
  242. }
  243. // Set error message if DO_NOT_UPGRADE_GLOBAL_TABLES isn't set as it will break install.
  244. if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
  245. display_header();
  246. die(
  247. '<h1>' . __( 'Configuration Error' ) . '</h1>' .
  248. '<p>' . sprintf(
  249. /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
  250. __( 'The constant %s cannot be defined when installing WordPress.' ),
  251. '<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
  252. ) . '</p></body></html>'
  253. );
  254. }
  255. /**
  256. * @global string $wp_local_package
  257. * @global WP_Locale $wp_locale
  258. */
  259. $language = '';
  260. if ( ! empty( $_REQUEST['language'] ) ) {
  261. $language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] );
  262. } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
  263. $language = $GLOBALS['wp_local_package'];
  264. }
  265. $scripts_to_print = array( 'jquery' );
  266. switch($step) {
  267. case 0: // Step 0
  268. if ( wp_can_install_language_pack() && empty( $language ) && ( $languages = wp_get_available_translations() ) ) {
  269. $scripts_to_print[] = 'language-chooser';
  270. display_header( 'language-chooser' );
  271. echo '<form id="setup" method="post" action="?step=1">';
  272. wp_install_language_form( $languages );
  273. echo '</form>';
  274. break;
  275. }
  276. // Deliberately fall through if we can't reach the translations API.
  277. case 1: // Step 1, direct link or from language chooser.
  278. if ( ! empty( $language ) ) {
  279. $loaded_language = wp_download_language_pack( $language );
  280. if ( $loaded_language ) {
  281. load_default_textdomain( $loaded_language );
  282. $GLOBALS['wp_locale'] = new WP_Locale();
  283. }
  284. }
  285. $scripts_to_print[] = 'user-profile';
  286. display_header();
  287. ?>
  288. <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
  289. <p><?php _e( 'Welcome to the famous five-minute WordPress installation process! Just fill in the information below and you&#8217;ll be on your way to using the most extendable and powerful personal publishing platform in the world.' ); ?></p>
  290. <h2><?php _e( 'Information needed' ); ?></h2>
  291. <p><?php _e( 'Please provide the following information. Don&#8217;t worry, you can always change these settings later.' ); ?></p>
  292. <?php
  293. display_setup_form();
  294. break;
  295. case 2:
  296. if ( ! empty( $language ) && load_default_textdomain( $language ) ) {
  297. $loaded_language = $language;
  298. $GLOBALS['wp_locale'] = new WP_Locale();
  299. } else {
  300. $loaded_language = 'en_US';
  301. }
  302. if ( ! empty( $wpdb->error ) )
  303. wp_die( $wpdb->error->get_error_message() );
  304. $scripts_to_print[] = 'user-profile';
  305. display_header();
  306. // Fill in the data we gathered
  307. $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
  308. $user_name = isset($_POST['user_name']) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
  309. $admin_password = isset($_POST['admin_password']) ? wp_unslash( $_POST['admin_password'] ) : '';
  310. $admin_password_check = isset($_POST['admin_password2']) ? wp_unslash( $_POST['admin_password2'] ) : '';
  311. $admin_email = isset( $_POST['admin_email'] ) ?trim( wp_unslash( $_POST['admin_email'] ) ) : '';
  312. $public = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 1;
  313. // Check email address.
  314. $error = false;
  315. if ( empty( $user_name ) ) {
  316. // TODO: poka-yoke
  317. display_setup_form( __( 'Please provide a valid username.' ) );
  318. $error = true;
  319. } elseif ( $user_name != sanitize_user( $user_name, true ) ) {
  320. display_setup_form( __( 'The username you provided has invalid characters.' ) );
  321. $error = true;
  322. } elseif ( $admin_password != $admin_password_check ) {
  323. // TODO: poka-yoke
  324. display_setup_form( __( 'Your passwords do not match. Please try again.' ) );
  325. $error = true;
  326. } elseif ( empty( $admin_email ) ) {
  327. // TODO: poka-yoke
  328. display_setup_form( __( 'You must provide an email address.' ) );
  329. $error = true;
  330. } elseif ( ! is_email( $admin_email ) ) {
  331. // TODO: poka-yoke
  332. display_setup_form( __( 'Sorry, that isn&#8217;t a valid email address. Email addresses look like <code>username@example.com</code>.' ) );
  333. $error = true;
  334. }
  335. if ( $error === false ) {
  336. $wpdb->show_errors();
  337. $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
  338. ?>
  339. <h1><?php _e( 'Success!' ); ?></h1>
  340. <p><?php _e( 'WordPress has been installed. Thank you, and enjoy!' ); ?></p>
  341. <table class="form-table install-success">
  342. <tr>
  343. <th><?php _e( 'Username' ); ?></th>
  344. <td><?php echo esc_html( sanitize_user( $user_name, true ) ); ?></td>
  345. </tr>
  346. <tr>
  347. <th><?php _e( 'Password' ); ?></th>
  348. <td><?php
  349. if ( ! empty( $result['password'] ) && empty( $admin_password_check ) ): ?>
  350. <code><?php echo esc_html( $result['password'] ) ?></code><br />
  351. <?php endif ?>
  352. <p><?php echo $result['password_message'] ?></p>
  353. </td>
  354. </tr>
  355. </table>
  356. <p class="step"><a href="<?php echo esc_url( wp_login_url() ); ?>" class="button button-large"><?php _e( 'Log In' ); ?></a></p>
  357. <?php
  358. }
  359. break;
  360. }
  361. if ( ! wp_is_mobile() ) {
  362. ?>
  363. <script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script>
  364. <?php
  365. }
  366. wp_print_scripts( $scripts_to_print );
  367. ?>
  368. <script type="text/javascript">
  369. jQuery( function( $ ) {
  370. $( '.hide-if-no-js' ).removeClass( 'hide-if-no-js' );
  371. } );
  372. </script>
  373. </body>
  374. </html>