Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

430 linhas
16 KiB

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