WordPress.org

Make WordPress Core

Ticket #11093: 11093.patch

File 11093.patch, 10.3 KB (added by sorich87, 5 years ago)

Here is a new patch

  • wp-admin/install.php

     
    4343 
    4444$step = isset( $_GET['step'] ) ? $_GET['step'] : 0; 
    4545 
     46if ( !function_exists('display_header') ) : 
    4647/** 
    4748 * Display install header. 
    4849 * 
     
    6162        <?php wp_admin_css( 'install', true ); ?> 
    6263</head> 
    6364<body> 
    64 <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1> 
     65        <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1> 
    6566 
    6667<?php 
    6768} // end display_header() 
     69endif; 
    6870 
     71if ( !function_exists('check_requirements') ) : 
    6972/** 
     73 * Initial check if blog is installed and other requirements 
     74 * 
     75 * @since 3.1.0 
     76 * @package WordPress 
     77 * @subpackage Installer 
     78 */ 
     79function check_requirements() { 
     80        global $wpdb; 
     81         
     82        // Let's check to make sure WP isn't already installed. 
     83        if ( is_blog_installed() ) { 
     84                display_header(); 
     85                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">' . __('Log In') . '</a></p></body></html>' ); 
     86        } 
     87 
     88        $php_version    = phpversion(); 
     89        $mysql_version  = $wpdb->db_version(); 
     90        $php_compat     = version_compare( $php_version, $required_php_version, '>=' ); 
     91        $mysql_compat   = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' ); 
     92 
     93        if ( !$mysql_compat && !$php_compat ) 
     94                $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 ); 
     95        elseif ( !$php_compat ) 
     96                $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 ); 
     97        elseif ( !$mysql_compat ) 
     98                $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 ); 
     99 
     100        if ( !$mysql_compat || !$php_compat ) { 
     101                display_header(); 
     102                die('<h1>' . __('Insufficient Requirements') . '</h1><p>' . $compat . '</p></body></html>'); 
     103        } 
     104} // end check_requirements() 
     105endif; 
     106 
     107if ( !function_exists('display_setup_form') ) : 
     108/** 
    70109 * Display installer setup form. 
    71110 * 
    72111 * @since 2.8.0 
     
    137176</form> 
    138177<?php 
    139178} // end display_setup_form() 
     179endif; 
    140180 
    141 // Let's check to make sure WP isn't already installed. 
    142 if ( is_blog_installed() ) { 
    143         display_header(); 
    144         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">' . __('Log In') . '</a></p></body></html>' ); 
    145 } 
     181if ( !function_exists('step_0') ) : 
     182/** 
     183 * Process install step 0 
     184 * 
     185 * @since 3.1.0 
     186 * @package WordPress 
     187 * @subpackage Installer 
     188*/ 
     189function step_0() { 
     190        step_1(); 
     191}//end function step_0(); 
     192endif; 
    146193 
    147 $php_version    = phpversion(); 
    148 $mysql_version  = $wpdb->db_version(); 
    149 $php_compat     = version_compare( $php_version, $required_php_version, '>=' ); 
    150 $mysql_compat   = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' ); 
    151  
    152 if ( !$mysql_compat && !$php_compat ) 
    153         $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 ); 
    154 elseif ( !$php_compat ) 
    155         $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 ); 
    156 elseif ( !$mysql_compat ) 
    157         $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 ); 
    158  
    159 if ( !$mysql_compat || !$php_compat ) { 
     194if ( !function_exists('step_1') ) : 
     195/** 
     196 * Process install step 1 
     197 * 
     198 * @since 3.1.0 
     199 * @package WordPress 
     200 * @subpackage Installer 
     201*/ 
     202function step_1() { 
    160203        display_header(); 
    161         die('<h1>' . __('Insufficient Requirements') . '</h1><p>' . $compat . '</p></body></html>'); 
    162 } 
    163  
    164 switch($step) { 
    165         case 0: // Step 1 
    166         case 1: // Step 1, direct link. 
    167           display_header(); 
    168204?> 
    169205<h1><?php _e( 'Welcome' ); ?></h1> 
    170206<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> 
     
    173209<p><?php _e( 'Please provide the following information. Don&#8217;t worry, you can always change these settings later.' ); ?></p> 
    174210 
    175211<?php 
    176                 display_setup_form(); 
    177                 break; 
    178         case 2: 
    179                 if ( ! empty( $wpdb->error ) ) 
    180                         wp_die( $wpdb->error->get_error_message() ); 
     212        display_setup_form(); 
     213} // end step_1() 
     214endif; 
    181215 
    182                 display_header(); 
    183                 // Fill in the data we gathered 
    184                 $weblog_title = isset( $_POST['weblog_title'] ) ? trim( stripslashes( $_POST['weblog_title'] ) ) : ''; 
    185                 $user_name = isset($_POST['user_name']) ? trim( stripslashes( $_POST['user_name'] ) ) : 'admin'; 
    186                 $admin_password = isset($_POST['admin_password']) ? $_POST['admin_password'] : ''; 
    187                 $admin_password_check = isset($_POST['admin_password2']) ? $_POST['admin_password2'] : ''; 
    188                 $admin_email  = isset( $_POST['admin_email']  ) ?trim( stripslashes( $_POST['admin_email'] ) ) : ''; 
    189                 $public       = isset( $_POST['blog_public']  ) ? (int) $_POST['blog_public'] : 0; 
    190                 // check e-mail address 
    191                 $error = false; 
    192                 if ( empty( $user_name ) ) { 
    193                         // TODO: poka-yoke 
    194                         display_setup_form( __('you must provide a valid username.') ); 
    195                         $error = true; 
    196                 } elseif ( $user_name != sanitize_user( $user_name, true ) ) { 
    197                         display_setup_form( __('the username you provided has invalid characters.') ); 
    198                         $error = true; 
    199                 } elseif ( $admin_password != $admin_password_check ) { 
    200                         // TODO: poka-yoke 
    201                         display_setup_form( __( 'your passwords do not match. Please try again' ) ); 
    202                         $error = true; 
    203                 } else if ( empty( $admin_email ) ) { 
    204                         // TODO: poka-yoke 
    205                         display_setup_form( __( 'you must provide an e-mail address.' ) ); 
    206                         $error = true; 
    207                 } elseif ( ! is_email( $admin_email ) ) { 
    208                         // TODO: poka-yoke 
    209                         display_setup_form( __( 'that isn&#8217;t a valid e-mail address.  E-mail addresses look like: <code>username@example.com</code>' ) ); 
    210                         $error = true; 
    211                 } 
     216if ( !function_exists('step_2') ) : 
     217/** 
     218 * Process install step 2 
     219 * 
     220 * @since 3.1.0 
     221 * @package WordPress 
     222 * @subpackage Installer 
     223*/ 
     224function step_2() { 
     225        global $wpdb; 
     226         
     227        if ( ! empty( $wpdb->error ) ) 
     228                wp_die( $wpdb->error->get_error_message() ); 
    212229 
    213                 if ( $error === false ) { 
    214                         $wpdb->show_errors(); 
    215                         $result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password); 
    216                         extract( $result, EXTR_SKIP ); 
     230        display_header(); 
     231        // Fill in the data we gathered 
     232        $weblog_title = isset( $_POST['weblog_title'] ) ? trim( stripslashes( $_POST['weblog_title'] ) ) : ''; 
     233        $user_name = isset($_POST['user_name']) ? trim( stripslashes( $_POST['user_name'] ) ) : 'admin'; 
     234        $admin_password = isset($_POST['admin_password']) ? $_POST['admin_password'] : ''; 
     235        $admin_password_check = isset($_POST['admin_password2']) ? $_POST['admin_password2'] : ''; 
     236        $admin_email  = isset( $_POST['admin_email']  ) ?trim( stripslashes( $_POST['admin_email'] ) ) : ''; 
     237        $public       = isset( $_POST['blog_public']  ) ? (int) $_POST['blog_public'] : 0; 
     238        // check e-mail address 
     239        $error = false; 
     240        if ( empty( $user_name ) ) { 
     241                // TODO: poka-yoke 
     242                display_setup_form( __('you must provide a valid username.') ); 
     243                $error = true; 
     244        } elseif ( $user_name != sanitize_user( $user_name, true ) ) { 
     245                display_setup_form( __('the username you provided has invalid characters.') ); 
     246                $error = true; 
     247        } elseif ( $admin_password != $admin_password_check ) { 
     248                // TODO: poka-yoke 
     249                display_setup_form( __( 'your passwords do not match. Please try again' ) ); 
     250                $error = true; 
     251        } else if ( empty( $admin_email ) ) { 
     252                // TODO: poka-yoke 
     253                display_setup_form( __( 'you must provide an e-mail address.' ) ); 
     254                $error = true; 
     255        } elseif ( ! is_email( $admin_email ) ) { 
     256                // TODO: poka-yoke 
     257                display_setup_form( __( 'that isn&#8217;t a valid e-mail address.  E-mail addresses look like: <code>username@example.com</code>' ) ); 
     258                $error = true; 
     259        } 
     260 
     261        if ( $error === false ) { 
     262                $wpdb->show_errors(); 
     263                $result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password); 
     264                extract( $result, EXTR_SKIP ); 
    217265?> 
    218266 
    219267<h1><?php _e( 'Success!' ); ?></h1> 
     
    238286<p class="step"><a href="../wp-login.php" class="button"><?php _e( 'Log In' ); ?></a></p> 
    239287 
    240288<?php 
    241                 } 
    242                 break; 
    243 } 
     289        } 
     290} // end step_2() 
     291endif; 
     292 
     293if ( !function_exists('display_footer') ) : 
     294/** 
     295 * Display install footer. 
     296 * 
     297 * @since 3.1.0 
     298 * @package WordPress 
     299 * @subpackage Installer 
     300 */ 
     301function display_footer() { 
    244302?> 
    245303<script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script> 
    246304<script type="text/javascript" src="../wp-includes/js/jquery/jquery.js"></script> 
     
    262320</script> 
    263321</body> 
    264322</html> 
     323<?php 
     324}//end function display_footer(); 
     325endif; 
     326 
     327check_requirements(); 
     328 
     329switch($step) { 
     330        case 0: // Step 1 
     331                step_0(); 
     332                break; 
     333        case 1: // Step 1, direct link. 
     334                step_1(); 
     335                break; 
     336        case 2: 
     337                step_2(); 
     338                break; 
     339} 
     340 
     341display_footer(); 
     342?> 
     343 No newline at end of file