~canonical-sysadmins/wordpress/4.7.2

« back to all changes in this revision

Viewing changes to wp-admin/install.php

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
function display_header( $body_classes = '' ) {
 
57
        header( 'Content-Type: text/html; charset=utf-8' );
 
58
        if ( is_rtl() ) {
 
59
                $body_classes .= 'rtl';
 
60
        }
 
61
        if ( $body_classes ) {
 
62
                $body_classes = ' ' . $body_classes;
 
63
        }
 
64
?>
 
65
<!DOCTYPE html>
 
66
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
 
67
<head>
 
68
        <meta name="viewport" content="width=device-width" />
 
69
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
70
        <title><?php _e( 'WordPress &rsaquo; Installation' ); ?></title>
 
71
        <?php
 
72
        wp_admin_css( 'install', true );
 
73
        ?>
 
74
</head>
 
75
<body class="wp-core-ui<?php echo $body_classes ?>">
 
76
<h1 id="logo"><a href="<?php echo esc_url( __( 'https://wordpress.org/' ) ); ?>" tabindex="-1"><?php _e( 'WordPress' ); ?></a></h1>
 
77
 
 
78
<?php
 
79
} // end display_header()
 
80
 
 
81
/**
 
82
 * Display installer setup form.
 
83
 *
 
84
 * @since 2.8.0
 
85
 */
 
86
function display_setup_form( $error = null ) {
 
87
        global $wpdb;
 
88
 
 
89
        $sql = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->users ) );
 
90
        $user_table = ( $wpdb->get_var( $sql ) != null );
 
91
 
 
92
        // Ensure that Blogs appear in search engines by default.
 
93
        $blog_public = 1;
 
94
        if ( isset( $_POST['weblog_title'] ) ) {
 
95
                $blog_public = isset( $_POST['blog_public'] );
 
96
        }
 
97
 
 
98
        $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
 
99
        $user_name = isset($_POST['user_name']) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
 
100
        $admin_email  = isset( $_POST['admin_email']  ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
 
101
 
 
102
        if ( ! is_null( $error ) ) {
 
103
?>
 
104
<p class="message"><?php echo $error; ?></p>
 
105
<?php } ?>
 
106
<form id="setup" method="post" action="install.php?step=2" novalidate="novalidate">
 
107
        <table class="form-table">
 
108
                <tr>
 
109
                        <th scope="row"><label for="weblog_title"><?php _e( 'Site Title' ); ?></label></th>
 
110
                        <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo esc_attr( $weblog_title ); ?>" /></td>
 
111
                </tr>
 
112
                <tr>
 
113
                        <th scope="row"><label for="user_login"><?php _e('Username'); ?></label></th>
 
114
                        <td>
 
115
                        <?php
 
116
                        if ( $user_table ) {
 
117
                                _e('User(s) already exists.');
 
118
                                echo '<input name="user_name" type="hidden" value="admin" />';
 
119
                        } else {
 
120
                                ?><input name="user_name" type="text" id="user_login" size="25" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" />
 
121
                                <p><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods and the @ symbol.' ); ?></p>
 
122
                        <?php
 
123
                        } ?>
 
124
                        </td>
 
125
                </tr>
 
126
                <?php if ( ! $user_table ) : ?>
 
127
                <tr>
 
128
                        <th scope="row">
 
129
                                <label for="pass1"><?php _e('Password, twice'); ?></label>
 
130
                                <p><?php _e('A password will be automatically generated for you if you leave this blank.'); ?></p>
 
131
                        </th>
 
132
                        <td>
 
133
                                <input name="admin_password" type="password" id="pass1" size="25" value="" />
 
134
                                <p><input name="admin_password2" type="password" id="pass2" size="25" value="" /></p>
 
135
                                <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
 
136
                                <p><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
 
137
                        </td>
 
138
                </tr>
 
139
                <?php endif; ?>
 
140
                <tr>
 
141
                        <th scope="row"><label for="admin_email"><?php _e( 'Your E-mail' ); ?></label></th>
 
142
                        <td><input name="admin_email" type="email" id="admin_email" size="25" value="<?php echo esc_attr( $admin_email ); ?>" />
 
143
                        <p><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
 
144
                </tr>
 
145
                <tr>
 
146
                        <th scope="row"><label for="blog_public"><?php _e( 'Privacy' ); ?></label></th>
 
147
                        <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>
 
148
                </tr>
 
149
        </table>
 
150
        <p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Install WordPress' ); ?>" class="button button-large" /></p>
 
151
        <input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" />
 
152
</form>
 
153
<?php
 
154
} // end display_setup_form()
 
155
 
 
156
// Let's check to make sure WP isn't already installed.
 
157
if ( is_blog_installed() ) {
 
158
        display_header();
 
159
        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>' );
 
160
}
 
161
 
 
162
$php_version    = phpversion();
 
163
$mysql_version  = $wpdb->db_version();
 
164
$php_compat     = version_compare( $php_version, $required_php_version, '>=' );
 
165
$mysql_compat   = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' );
 
166
 
 
167
if ( !$mysql_compat && !$php_compat )
 
168
        $compat = sprintf( __( 'You cannot install because <a href="http://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 );
 
169
elseif ( !$php_compat )
 
170
        $compat = sprintf( __( 'You cannot install because <a href="http://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 );
 
171
elseif ( !$mysql_compat )
 
172
        $compat = sprintf( __( 'You cannot install because <a href="http://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 );
 
173
 
 
174
if ( !$mysql_compat || !$php_compat ) {
 
175
        display_header();
 
176
        die( '<h1>' . __( 'Insufficient Requirements' ) . '</h1><p>' . $compat . '</p></body></html>' );
 
177
}
 
178
 
 
179
if ( ! is_string( $wpdb->base_prefix ) || '' === $wpdb->base_prefix ) {
 
180
        display_header();
 
181
        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>' );
 
182
}
 
183
 
 
184
$language = '';
 
185
if ( ! empty( $_REQUEST['language'] ) ) {
 
186
        $language = preg_replace( '/[^a-zA-Z_]/', '', $_REQUEST['language'] );
 
187
} elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
 
188
        $language = $GLOBALS['wp_local_package'];
 
189
}
 
190
 
 
191
switch($step) {
 
192
        case 0: // Step 0
 
193
 
 
194
                if ( wp_can_install_language_pack() && empty( $language ) && ( $languages = wp_get_available_translations() ) ) {
 
195
                        display_header( 'language-chooser' );
 
196
                        echo '<form id="setup" method="post" action="?step=1">';
 
197
                        wp_install_language_form( $languages );
 
198
                        echo '</form>';
 
199
                        break;
 
200
                }
 
201
 
 
202
                // Deliberately fall through if we can't reach the translations API.
 
203
 
 
204
        case 1: // Step 1, direct link or from language chooser.
 
205
                if ( ! empty( $language ) ) {
 
206
                        $loaded_language = wp_download_language_pack( $language );
 
207
                        if ( $loaded_language ) {
 
208
                                load_default_textdomain( $loaded_language );
 
209
                                $GLOBALS['wp_locale'] = new WP_Locale();
 
210
                        }
 
211
                }
 
212
 
 
213
                display_header();
 
214
?>
 
215
<h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
 
216
<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>
 
217
 
 
218
<h1><?php _e( 'Information needed' ); ?></h1>
 
219
<p><?php _e( 'Please provide the following information. Don&#8217;t worry, you can always change these settings later.' ); ?></p>
 
220
 
 
221
<?php
 
222
                display_setup_form();
 
223
                break;
 
224
        case 2:
 
225
                if ( ! empty( $language ) && load_default_textdomain( $language ) ) {
 
226
                        $loaded_language = $language;
 
227
                        $GLOBALS['wp_locale'] = new WP_Locale();
 
228
                } else {
 
229
                        $loaded_language = 'en_US';
 
230
                }
 
231
 
 
232
                if ( ! empty( $wpdb->error ) )
 
233
                        wp_die( $wpdb->error->get_error_message() );
 
234
 
 
235
                display_header();
 
236
                // Fill in the data we gathered
 
237
                $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
 
238
                $user_name = isset($_POST['user_name']) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
 
239
                $admin_password = isset($_POST['admin_password']) ? wp_unslash( $_POST['admin_password'] ) : '';
 
240
                $admin_password_check = isset($_POST['admin_password2']) ? wp_unslash( $_POST['admin_password2'] ) : '';
 
241
                $admin_email  = isset( $_POST['admin_email'] ) ?trim( wp_unslash( $_POST['admin_email'] ) ) : '';
 
242
                $public       = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 0;
 
243
 
 
244
                // Check e-mail address.
 
245
                $error = false;
 
246
                if ( empty( $user_name ) ) {
 
247
                        // TODO: poka-yoke
 
248
                        display_setup_form( __( 'Please provide a valid username.' ) );
 
249
                        $error = true;
 
250
                } elseif ( $user_name != sanitize_user( $user_name, true ) ) {
 
251
                        display_setup_form( __( 'The username you provided has invalid characters.' ) );
 
252
                        $error = true;
 
253
                } elseif ( $admin_password != $admin_password_check ) {
 
254
                        // TODO: poka-yoke
 
255
                        display_setup_form( __( 'Your passwords do not match. Please try again.' ) );
 
256
                        $error = true;
 
257
                } else if ( empty( $admin_email ) ) {
 
258
                        // TODO: poka-yoke
 
259
                        display_setup_form( __( 'You must provide an email address.' ) );
 
260
                        $error = true;
 
261
                } elseif ( ! is_email( $admin_email ) ) {
 
262
                        // TODO: poka-yoke
 
263
                        display_setup_form( __( 'Sorry, that isn&#8217;t a valid email address. Email addresses look like <code>username@example.com</code>.' ) );
 
264
                        $error = true;
 
265
                }
 
266
 
 
267
                if ( $error === false ) {
 
268
                        $wpdb->show_errors();
 
269
                        $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
 
270
?>
 
271
 
 
272
<h1><?php _e( 'Success!' ); ?></h1>
 
273
 
 
274
<p><?php _e( 'WordPress has been installed. Were you expecting more steps? Sorry to disappoint.' ); ?></p>
 
275
 
 
276
<table class="form-table install-success">
 
277
        <tr>
 
278
                <th><?php _e( 'Username' ); ?></th>
 
279
                <td><?php echo esc_html( sanitize_user( $user_name, true ) ); ?></td>
 
280
        </tr>
 
281
        <tr>
 
282
                <th><?php _e( 'Password' ); ?></th>
 
283
                <td><?php
 
284
                if ( ! empty( $result['password'] ) && empty( $admin_password_check ) ): ?>
 
285
                        <code><?php echo esc_html( $result['password'] ) ?></code><br />
 
286
                <?php endif ?>
 
287
                        <p><?php echo $result['password_message'] ?></p>
 
288
                </td>
 
289
        </tr>
 
290
</table>
 
291
 
 
292
<p class="step"><a href="../wp-login.php" class="button button-large"><?php _e( 'Log In' ); ?></a></p>
 
293
 
 
294
<?php
 
295
                }
 
296
                break;
 
297
}
 
298
if ( !wp_is_mobile() ) {
 
299
?>
 
300
<script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script>
 
301
<?php } ?>
 
302
<?php wp_print_scripts( 'user-profile' ); ?>
 
303
<?php wp_print_scripts( 'language-chooser' ); ?>
 
304
</body>
 
305
</html>