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