WordPress.org

Make WordPress Core

Ticket #11093: install.php

File install.php, 6.4 KB (added by thomask, 5 years ago)

new install.php file - replacement for /wp-admin/install.php (previous one miss global $wpdb by mistake))

Line 
1<?php
2/**
3 * WordPress Installer
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
8
9/**
10 * We are installing WordPress.
11 *
12 * @since unknown
13 * @var bool
14 */
15define('WP_INSTALLING', true);
16
17/** Load WordPress Bootstrap */
18require_once(dirname(dirname(__FILE__)) . '/wp-load.php');
19
20/** Load WordPress Administration Upgrade API */
21require_once(dirname(__FILE__) . '/includes/upgrade.php');
22
23if (isset($_GET['step']))
24        $step = $_GET['step'];
25else
26        $step = 0;
27
28
29if ( !function_exists('display_header') ) :
30/**
31 * Display install header.
32 *
33 * @since unknown
34 * @package WordPress
35 * @subpackage Installer
36 */
37function display_header() {
38header( 'Content-Type: text/html; charset=utf-8' );
39?>
40<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
41<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
42<head>
43        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
44        <title><?php _e('WordPress &rsaquo; Installation'); ?></title>
45        <?php wp_admin_css( 'install', true ); ?>
46</head>
47<body>
48<h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
49
50<?php
51}//end function display_header();
52endif;
53
54if ( !function_exists('display_setup_form') ) :
55function display_setup_form( $error = null ) {
56        // Ensure that Blogs appear in search engines by default
57        $blog_public = 1;
58        if ( isset($_POST) && !empty($_POST) ) {
59                $blog_public = isset($_POST['blog_public']);
60        }
61
62        if ( ! is_null( $error ) ) {
63?>
64<p><?php printf( __('<strong>ERROR</strong>: %s'), $error); ?></p>
65<?php } ?>
66<form id="setup" method="post" action="install.php?step=2">
67        <table class="form-table">
68                <tr>
69                        <th scope="row"><label for="weblog_title"><?php _e('Blog Title'); ?></label></th>
70                        <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo ( isset($_POST['weblog_title']) ? esc_attr($_POST['weblog_title']) : '' ); ?>" /></td>
71                </tr>
72                <tr>
73                        <th scope="row"><label for="admin_email"><?php _e('Your E-mail'); ?></label></th>
74                        <td><input name="admin_email" type="text" id="admin_email" size="25" value="<?php echo ( isset($_POST['admin_email']) ? esc_attr($_POST['admin_email']) : '' ); ?>" /><br />
75                        <?php _e('Double-check your email address before continuing.'); ?>
76                </tr>
77                <tr>
78                        <td colspan="2"><label><input type="checkbox" name="blog_public" value="1" <?php checked($blog_public); ?> /> <?php _e('Allow my blog to appear in search engines like Google and Technorati.'); ?></label></td>
79                </tr>
80        </table>
81        <p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e('Install WordPress'); ?>" class="button" /></p>
82</form>
83<?php
84}//end function display_setup_form();
85endif;
86
87if ( !function_exists('check_blog_installed') ) :
88/**
89 * Initial check if blog is installed
90 *
91 * @package WordPress
92 * @subpackage Installer
93 */
94function check_blog_installed() {
95// Let's check to make sure WP isn't already installed.
96if ( is_blog_installed() ) {display_header(); die('<h1>'.__('Already Installed').'</h1><p>'.__('You appear to have already installed WordPress. To reinstall please clear your old database tables first.').'</p></body></html>');}
97}//end function check_blog_installed();
98endif;
99check_blog_installed();
100
101if ( !function_exists('step_0') ) :
102/**
103 * Function for step 0
104 *
105 * @package WordPress
106 * @subpackage Installer
107 */
108function step_0() {
109step_1();
110}//end function step_0();
111endif;
112
113if ( !function_exists('step_1') ) :
114/**
115 * Function for step 1
116 *
117 * @package WordPress
118 * @subpackage Installer
119 */
120function step_1() {
121
122          display_header();
123?>
124<h1><?php _e('Welcome'); ?></h1>
125<p><?php printf(__('Welcome to the famous five minute WordPress installation process! You may want to browse the <a href="%s">ReadMe documentation</a> at your leisure.  Otherwise, 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.'), '../readme.html'); ?></p>
126<!--<h2 class="step"><a href="install.php?step=1"><?php _e('First Step'); ?></a></h2>-->
127
128<h1><?php _e('Information needed'); ?></h1>
129<p><?php _e('Please provide the following information.  Don&#8217;t worry, you can always change these settings later.'); ?></p>
130
131<?php
132                display_setup_form();
133                break;
134}//end function step_1();
135endif;
136
137if ( !function_exists('step_2') ) :
138/**
139 * Function for step 2
140 *
141 * @package WordPress
142 * @subpackage Installer
143 */
144function step_2() {
145global $wpdb;
146                if ( !empty($wpdb->error) )
147                        wp_die($wpdb->error->get_error_message());
148
149                display_header();
150                // Fill in the data we gathered
151                $weblog_title = isset($_POST['weblog_title']) ? stripslashes($_POST['weblog_title']) : '';
152                $admin_email = isset($_POST['admin_email']) ? stripslashes($_POST['admin_email']) : '';
153                $public = isset($_POST['blog_public']) ? (int) $_POST['blog_public'] : 0;
154                // check e-mail address
155                $error = false;
156                if (empty($admin_email)) {
157                        // TODO: poka-yoke
158                        display_setup_form( __('you must provide an e-mail address.') );
159                        $error = true;
160                } else if (!is_email($admin_email)) {
161                        // TODO: poka-yoke
162                        display_setup_form( __('that isn&#8217;t a valid e-mail address.  E-mail addresses look like: <code>username@example.com</code>') );
163                        $error = true;
164                }
165
166                if ( $error === false ) {
167                        $wpdb->show_errors();
168                        $result = wp_install($weblog_title, 'admin', $admin_email, $public);
169                        extract($result, EXTR_SKIP);
170?>
171
172<h1><?php _e('Success!'); ?></h1>
173
174<p><?php printf(__('WordPress has been installed. Were you expecting more steps? Sorry to disappoint.'), ''); ?></p>
175
176<table class="form-table">
177        <tr>
178                <th><?php _e('Username'); ?></th>
179                <td><code>admin</code></td>
180        </tr>
181        <tr>
182                <th><?php _e('Password'); ?></th>
183                <td><?php if ( !empty( $password ) ) {
184                                                echo '<code>'. $password .'</code><br />';
185                                        }
186                                        echo '<p>'. $password_message .'</p>'; ?></td>
187        </tr>
188</table>
189
190<p class="step"><a href="../wp-login.php" class="button"><?php _e('Log In'); ?></a></p>
191
192<?php
193                }
194                break;
195}//end function step_2();
196endif;
197
198
199switch($step) {
200        case 0:
201    step_0();
202        case 1: // in case people are directly linking to this
203    step_1();
204        case 2:
205    step_2();
206}
207
208
209if ( !function_exists('display_footer') ) :
210/**
211 * Display install footer.
212 *
213 * @package WordPress
214 * @subpackage Installer
215 */
216
217function display_footer() {
218?>
219  <script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script>
220  </body>
221  </html>
222<?php }//end function display_footer();
223endif;
224
225display_footer();
226?>