install.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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 wp_admin_css( 'install', true ); ?>
  66. </head>
  67. <body class="wp-core-ui<?php echo $body_classes; ?>">
  68. <p id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>"><?php _e( 'WordPress' ); ?></a></p>
  69. <?php
  70. } // end display_header()
  71. /**
  72. * Display installer setup form.
  73. *
  74. * @since 2.8.0
  75. *
  76. * @global wpdb $wpdb WordPress database abstraction object.
  77. *
  78. * @param string|null $error
  79. */
  80. function display_setup_form( $error = null ) {
  81. global $wpdb;
  82. $sql = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->users ) );
  83. $user_table = ( $wpdb->get_var( $sql ) != null );
  84. // Ensure that Blogs appear in search engines by default.
  85. $blog_public = 1;
  86. if ( isset( $_POST['weblog_title'] ) ) {
  87. $blog_public = isset( $_POST['blog_public'] );
  88. }
  89. $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
  90. $user_name = isset( $_POST['user_name'] ) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
  91. $admin_email = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
  92. if ( ! is_null( $error ) ) {
  93. ?>
  94. <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
  95. <p class="message"><?php echo $error; ?></p>
  96. <?php } ?>
  97. <form id="setup" method="post" action="install.php?step=2" novalidate="novalidate">
  98. <table class="form-table" role="presentation">
  99. <tr>
  100. <th scope="row"><label for="weblog_title"><?php _e( 'Site Title' ); ?></label></th>
  101. <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo esc_attr( $weblog_title ); ?>" /></td>
  102. </tr>
  103. <tr>
  104. <th scope="row"><label for="user_login"><?php _e( 'Username' ); ?></label></th>
  105. <td>
  106. <?php
  107. if ( $user_table ) {
  108. _e( 'User(s) already exists.' );
  109. echo '<input name="user_name" type="hidden" value="admin" />';
  110. } else {
  111. ?>
  112. <input name="user_name" type="text" id="user_login" size="25" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" />
  113. <p><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods, and the @ symbol.' ); ?></p>
  114. <?php
  115. }
  116. ?>
  117. </td>
  118. </tr>
  119. <?php if ( ! $user_table ) : ?>
  120. <tr class="form-field form-required user-pass1-wrap">
  121. <th scope="row">
  122. <label for="pass1">
  123. <?php _e( 'Password' ); ?>
  124. </label>
  125. </th>
  126. <td>
  127. <div class="wp-pwd">
  128. <?php $initial_password = isset( $_POST['admin_password'] ) ? stripslashes( $_POST['admin_password'] ) : wp_generate_password( 18 ); ?>
  129. <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" />
  130. <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' ); ?>">
  131. <span class="dashicons dashicons-hidden"></span>
  132. <span class="text"><?php _e( 'Hide' ); ?></span>
  133. </button>
  134. <div id="pass-strength-result" aria-live="polite"></div>
  135. </div>
  136. <p><span class="description important hide-if-no-js">
  137. <strong><?php _e( 'Important:' ); ?></strong>
  138. <?php /* translators: The non-breaking space prevents 1Password from thinking the text "log in" should trigger a password save prompt. */ ?>
  139. <?php _e( 'You will need this password to log&nbsp;in. Please store it in a secure location.' ); ?></span></p>
  140. </td>
  141. </tr>
  142. <tr class="form-field form-required user-pass2-wrap hide-if-js">
  143. <th scope="row">
  144. <label for="pass2"><?php _e( 'Repeat Password' ); ?>
  145. <span class="description"><?php _e( '(required)' ); ?></span>
  146. </label>
  147. </th>
  148. <td>
  149. <input name="admin_password2" type="password" id="pass2" autocomplete="off" />
  150. </td>
  151. </tr>
  152. <tr class="pw-weak">
  153. <th scope="row"><?php _e( 'Confirm Password' ); ?></th>
  154. <td>
  155. <label>
  156. <input type="checkbox" name="pw_weak" class="pw-checkbox" />
  157. <?php _e( 'Confirm use of weak password' ); ?>
  158. </label>
  159. </td>
  160. </tr>
  161. <?php endif; ?>
  162. <tr>
  163. <th scope="row"><label for="admin_email"><?php _e( 'Your Email' ); ?></label></th>
  164. <td><input name="admin_email" type="email" id="admin_email" size="25" value="<?php echo esc_attr( $admin_email ); ?>" />
  165. <p><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
  166. </tr>
  167. <tr>
  168. <th scope="row"><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site Visibility' ) : _e( 'Search Engine Visibility' ); ?></th>
  169. <td>
  170. <fieldset>
  171. <legend class="screen-reader-text"><span><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site Visibility' ) : _e( 'Search Engine Visibility' ); ?> </span></legend>
  172. <?php
  173. if ( has_action( 'blog_privacy_selector' ) ) {
  174. ?>
  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. ?>
  185. <label for="blog_public"><input name="blog_public" type="checkbox" id="blog_public" value="0" <?php checked( 0, $blog_public ); ?> />
  186. <?php _e( 'Discourage search engines from indexing this site' ); ?></label>
  187. <p class="description"><?php _e( 'It is up to search engines to honor this request.' ); ?></p>
  188. <?php } ?>
  189. </fieldset>
  190. </td>
  191. </tr>
  192. </table>
  193. <p class="step"><?php submit_button( __( 'Install WordPress' ), 'large', 'Submit', false, array( 'id' => 'submit' ) ); ?></p>
  194. <input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" />
  195. </form>
  196. <?php
  197. } // end display_setup_form()
  198. // Let's check to make sure WP isn't already installed.
  199. if ( is_blog_installed() ) {
  200. display_header();
  201. die(
  202. '<h1>' . __( 'Already Installed' ) . '</h1>' .
  203. '<p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p>' .
  204. '<p class="step"><a href="' . esc_url( wp_login_url() ) . '" class="button button-large">' . __( 'Log In' ) . '</a></p>' .
  205. '</body></html>'
  206. );
  207. }
  208. /**
  209. * @global string $wp_version
  210. * @global string $required_php_version
  211. * @global string $required_mysql_version
  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. $version_url = sprintf(
  219. /* translators: %s: WordPress version. */
  220. esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
  221. sanitize_title( $wp_version )
  222. );
  223. /* translators: %s: URL to Update PHP page. */
  224. $php_update_message = '</p><p>' . sprintf( __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) );
  225. $annotation = wp_get_update_php_annotation();
  226. if ( $annotation ) {
  227. $php_update_message .= '</p><p><em>' . $annotation . '</em>';
  228. }
  229. if ( ! $mysql_compat && ! $php_compat ) {
  230. /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number. */
  231. $compat = sprintf( __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ), $version_url, $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version ) . $php_update_message;
  232. } elseif ( ! $php_compat ) {
  233. /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
  234. $compat = sprintf( __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ), $version_url, $wp_version, $required_php_version, $php_version ) . $php_update_message;
  235. } elseif ( ! $mysql_compat ) {
  236. /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
  237. $compat = sprintf( __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ), $version_url, $wp_version, $required_mysql_version, $mysql_version );
  238. }
  239. if ( ! $mysql_compat || ! $php_compat ) {
  240. display_header();
  241. die( '<h1>' . __( 'Requirements Not Met' ) . '</h1><p>' . $compat . '</p></body></html>' );
  242. }
  243. if ( ! is_string( $wpdb->base_prefix ) || '' === $wpdb->base_prefix ) {
  244. display_header();
  245. die(
  246. '<h1>' . __( 'Configuration Error' ) . '</h1>' .
  247. '<p>' . sprintf(
  248. /* translators: %s: wp-config.php */
  249. __( 'Your %s file has an empty database table prefix, which is not supported.' ),
  250. '<code>wp-config.php</code>'
  251. ) . '</p></body></html>'
  252. );
  253. }
  254. // Set error message if DO_NOT_UPGRADE_GLOBAL_TABLES isn't set as it will break install.
  255. if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
  256. display_header();
  257. die(
  258. '<h1>' . __( 'Configuration Error' ) . '</h1>' .
  259. '<p>' . sprintf(
  260. /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
  261. __( 'The constant %s cannot be defined when installing WordPress.' ),
  262. '<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
  263. ) . '</p></body></html>'
  264. );
  265. }
  266. /**
  267. * @global string $wp_local_package
  268. * @global WP_Locale $wp_locale WordPress date and time locale object.
  269. */
  270. $language = '';
  271. if ( ! empty( $_REQUEST['language'] ) ) {
  272. $language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] );
  273. } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
  274. $language = $GLOBALS['wp_local_package'];
  275. }
  276. $scripts_to_print = array( 'jquery' );
  277. switch ( $step ) {
  278. case 0: // Step 0
  279. if ( wp_can_install_language_pack() && empty( $language ) ) {
  280. $languages = wp_get_available_translations();
  281. if ( $languages ) {
  282. $scripts_to_print[] = 'language-chooser';
  283. display_header( 'language-chooser' );
  284. echo '<form id="setup" method="post" action="?step=1">';
  285. wp_install_language_form( $languages );
  286. echo '</form>';
  287. break;
  288. }
  289. }
  290. // Deliberately fall through if we can't reach the translations API.
  291. case 1: // Step 1, direct link or from language chooser.
  292. if ( ! empty( $language ) ) {
  293. $loaded_language = wp_download_language_pack( $language );
  294. if ( $loaded_language ) {
  295. load_default_textdomain( $loaded_language );
  296. $GLOBALS['wp_locale'] = new WP_Locale();
  297. }
  298. }
  299. $scripts_to_print[] = 'user-profile';
  300. display_header();
  301. ?>
  302. <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
  303. <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>
  304. <h2><?php _e( 'Information needed' ); ?></h2>
  305. <p><?php _e( 'Please provide the following information. Don&#8217;t worry, you can always change these settings later.' ); ?></p>
  306. <?php
  307. display_setup_form();
  308. break;
  309. case 2:
  310. if ( ! empty( $language ) && load_default_textdomain( $language ) ) {
  311. $loaded_language = $language;
  312. $GLOBALS['wp_locale'] = new WP_Locale();
  313. } else {
  314. $loaded_language = 'en_US';
  315. }
  316. if ( ! empty( $wpdb->error ) ) {
  317. wp_die( $wpdb->error->get_error_message() );
  318. }
  319. $scripts_to_print[] = 'user-profile';
  320. display_header();
  321. // Fill in the data we gathered
  322. $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
  323. $user_name = isset( $_POST['user_name'] ) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
  324. $admin_password = isset( $_POST['admin_password'] ) ? wp_unslash( $_POST['admin_password'] ) : '';
  325. $admin_password_check = isset( $_POST['admin_password2'] ) ? wp_unslash( $_POST['admin_password2'] ) : '';
  326. $admin_email = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
  327. $public = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 1;
  328. // Check email address.
  329. $error = false;
  330. if ( empty( $user_name ) ) {
  331. // TODO: poka-yoke
  332. display_setup_form( __( 'Please provide a valid username.' ) );
  333. $error = true;
  334. } elseif ( $user_name != sanitize_user( $user_name, true ) ) {
  335. display_setup_form( __( 'The username you provided has invalid characters.' ) );
  336. $error = true;
  337. } elseif ( $admin_password != $admin_password_check ) {
  338. // TODO: poka-yoke
  339. display_setup_form( __( 'Your passwords do not match. Please try again.' ) );
  340. $error = true;
  341. } elseif ( empty( $admin_email ) ) {
  342. // TODO: poka-yoke
  343. display_setup_form( __( 'You must provide an email address.' ) );
  344. $error = true;
  345. } elseif ( ! is_email( $admin_email ) ) {
  346. // TODO: poka-yoke
  347. display_setup_form( __( 'Sorry, that isn&#8217;t a valid email address. Email addresses look like <code>username@example.com</code>.' ) );
  348. $error = true;
  349. }
  350. if ( $error === false ) {
  351. $wpdb->show_errors();
  352. $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
  353. ?>
  354. <h1><?php _e( 'Success!' ); ?></h1>
  355. <p><?php _e( 'WordPress has been installed. Thank you, and enjoy!' ); ?></p>
  356. <table class="form-table install-success">
  357. <tr>
  358. <th><?php _e( 'Username' ); ?></th>
  359. <td><?php echo esc_html( sanitize_user( $user_name, true ) ); ?></td>
  360. </tr>
  361. <tr>
  362. <th><?php _e( 'Password' ); ?></th>
  363. <td>
  364. <?php
  365. if ( ! empty( $result['password'] ) && empty( $admin_password_check ) ) :
  366. ?>
  367. <code><?php echo esc_html( $result['password'] ); ?></code><br />
  368. <?php endif ?>
  369. <p><?php echo $result['password_message']; ?></p>
  370. </td>
  371. </tr>
  372. </table>
  373. <p class="step"><a href="<?php echo esc_url( wp_login_url() ); ?>" class="button button-large"><?php _e( 'Log In' ); ?></a></p>
  374. <?php
  375. }
  376. break;
  377. }
  378. if ( ! wp_is_mobile() ) {
  379. ?>
  380. <script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script>
  381. <?php
  382. }
  383. wp_print_scripts( $scripts_to_print );
  384. ?>
  385. <script type="text/javascript">
  386. jQuery( function( $ ) {
  387. $( '.hide-if-no-js' ).removeClass( 'hide-if-no-js' );
  388. } );
  389. </script>
  390. </body>
  391. </html>