WordPress.org

Make WordPress Core

Ticket #12094: network-step1.diff

File network-step1.diff, 23.4 KB (added by nacin, 8 years ago)
  • wp-admin/admin-footer.php

     
    2929<?php
    3030do_action('admin_footer', '');
    3131do_action('admin_print_footer_scripts');
    32 do_action("admin_footer-$hook_suffix");
     32do_action("admin_footer-" . $GLOBALS['hook_suffix']);
    3333
    3434// get_site_option() won't exist when auto upgrading from <= 2.7
    3535if ( function_exists('get_site_option') ) {
  • wp-admin/comment.php

     
    3535 * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
    3636 */
    3737function comment_footer_die( $msg ) {
    38         global $hook_suffix;
    3938        echo "<div class='wrap'><p>$msg</p></div>";
    4039        include('admin-footer.php');
    4140        die;
  • wp-admin/includes/network.php

     
     1<?php
     2/**
     3 * Network installation functions.
     4 *
     5 * @since 3.0.0
     6 *
     7 * @package WordPress
     8 * @subpackage Multisite
     9 */
     10
     11/**
     12 * Gets base domain of network.
     13 *
     14 * @since 3.0.0
     15 */
     16function get_clean_basedomain() {
     17        global $wpdb;
     18
     19        $existing_domain = network_domain_check();
     20        if ( $existing_domain )
     21                return $existing_domain;
     22
     23        $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
     24        if ( strpos( $domain, '/' ) )
     25                $domain = substr( $domain, 0, strpos( $domain, '/' ) );
     26        return $domain;
     27}
     28
     29/**
     30 * Checks for existing network data/tables.
     31 *
     32 * @since 3.0.0
     33 */
     34function network_domain_check() {
     35        global $wpdb;
     36
     37        if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
     38                return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
     39
     40        return false;
     41}
     42
     43/**
     44 * Prints summary of server statistics in preparation for setting up a network.
     45 *
     46 * @since 3.0.0
     47 */
     48function filestats( $err ) {
     49?>
     50        <h2><?php esc_html_e( 'Server Summary' ); ?></h2>
     51        <p><?php _e( 'If you post a message to the WordPress support forum at <a target="_blank" href="http://wordpress.org/support/">http://wordpress.org/support/</a> then copy and paste the following information into your message:' ); ?></p>
     52        <blockquote style="background: #eee; border: 1px solid #333; padding: 5px;">
     53        <br /><strong><?php printf( __( 'ERROR: %s' ), $err ); ?></strong><br />
     54<?php
     55        clearstatcache();
     56        $files = array( 'htaccess.dist', '.htaccess' );
     57
     58        $indent = '&nbsp;&nbsp;&nbsp;&nbsp;';
     59        foreach ( (array) $files as $val ) {
     60                $stats = @stat( $val );
     61                if ( $stats ) {
     62?>
     63                        <h2><?php echo esc_html( $val ); ?></h2>
     64                        <?php echo $indent . sprintf( __( 'uid/gid: %1$s/%2$s' ), $stats['uid'], $stats['gid'] ); ?><br />
     65                        <?php echo $indent . sprintf( __( 'size: %s' ), $stats['size'] ); ?><br/>
     66                        <?php echo $indent . sprintf( __( 'perms: %s' ), substr( sprintf( '%o', fileperms( $val ) ), -4 ) ); ?><br/>
     67                        <?php echo $indent . sprintf( __( 'readable: %s' ), is_readable( $val ) ? __( 'yes' ) : __( 'no' ) ); ?><br/>
     68                        <?php echo $indent . sprintf( __( 'writeable: %s' ), is_writeable( $val ) ? __( 'yes' ) : __( 'no' ) ); ?><br/>
     69<?php
     70                } elseif ( ! file_exists( $val ) ) {
     71?>
     72                        <h2><?php echo esc_html( $val ); ?></h2>
     73                        <?php echo $indent . sprintf( __( 'FILE NOT FOUND: %s' ), $val ); ?><br/>
     74<?php
     75                }
     76        }
     77        echo "</blockquote>";
     78}
     79 No newline at end of file
  • wp-admin/network.php

     
    11<?php
    22/**
    3  * Network settings administration panel.
     3 * Network installation administration panel.
    44 *
    55 * A multi-step process allowing the user to enable a network of WordPress sites.
    66 *
     
    1616if ( ! is_super_admin() )
    1717        wp_die( __( 'You do not have sufficient permissions to manage options for this blog.' ) );
    1818
     19include( ABSPATH . 'wp-admin/includes/network.php' );
     20
    1921// We need to create references to ms global tables to enable Network.
    2022foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table )
    2123        $wpdb->$table = $prefixed_table;
    2224
    23 $title = __( 'Network Settings' );
     25$title = __( 'Create a Network of WordPress Sites' );
    2426$parent_file = 'tools.php';
    2527
    2628add_contextual_help( $current_screen, __( '<a href="http://codex.wordpress.org/Settings_Network_SubPanel" target="_blank">Network Settings</a>') );
     
    3638<form method="post" action="network.php">
    3739<?php
    3840/**
    39  * Prints summary of server statistics in preparation for setting up a network.
     41 * Prints step 1 for Network installation process.
    4042 *
     43 * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network
     44 *      should not be a sudden "Welcome to a new install process! Fill this out and click here."
     45 *
    4146 * @since 3.0.0
    4247 */
    43 function filestats( $err ) {
    44 ?>
    45         <h2><?php esc_html_e( 'Server Summary' ); ?></h2>
    46         <p><?php _e( 'If you post a message to the WordPress support forum at <a target="_blank" href="http://wordpress.org/support/">http://wordpress.org/support/</a> then copy and paste the following information into your message:' ); ?></p>
    47         <blockquote style="background: #eee; border: 1px solid #333; padding: 5px;">
    48         <br /><strong><?php printf( __( 'ERROR: %s' ), $err ); ?></strong><br />
    49 <?php
    50         clearstatcache();
    51         $files = array( 'htaccess.dist', '.htaccess' );
     48function step1() {
    5249
    53         $indent = '&nbsp;&nbsp;&nbsp;&nbsp;';
    54         foreach ( (array) $files as $val ) {
    55                 $stats = @stat( $val );
    56                 if ( $stats ) {
    57 ?>
    58                         <h2><?php echo esc_html( $val ); ?></h2>
    59                         <?php echo $indent . sprintf( __( 'uid/gid: %1$s/%2$s' ), $stats['uid'], $stats['gid'] ); ?><br />
    60                         <?php echo $indent . sprintf( __( 'size: %s' ), $stats['size'] ); ?><br/>
    61                         <?php echo $indent . sprintf( __( 'perms: %s' ), substr( sprintf( '%o', fileperms( $val ) ), -4 ) ); ?><br/>
    62                         <?php echo $indent . sprintf( __( 'readable: %s' ), is_readable( $val ) ? __( 'yes' ) : __( 'no' ) ); ?><br/>
    63                         <?php echo $indent . sprintf( __( 'writeable: %s' ), is_writeable( $val ) ? __( 'yes' ) : __( 'no' ) ); ?><br/>
    64 <?php
    65                 } elseif ( ! file_exists( $val ) ) {
    66 ?>
    67                         <h2><?php echo esc_html( $val ); ?></h2>
    68                         <?php echo $indent . sprintf( __( 'FILE NOT FOUND: %s' ), $val ); ?><br/>
    69 <?php
    70                 }
     50        //@todo: give an informative screen instead
     51        //@todo: (alternate) don't show Tools > Network when is_multisite(), and wp_die() at the top of this file.
     52        if ( is_multisite() ) {
     53                _e( 'Network already enabled.' );
     54                include( './admin-footer.php' );
     55                die();
    7156        }
    72         echo "</blockquote>";
    73 }
    7457
    75 /**
    76  * Prints .htaccess component of step 2 for network settings.
    77  *
    78  * @since 3.0.0
    79  */
    80 function step2_htaccess() {
    81         global $base;
     58        $active_plugins = get_option( 'active_plugins' );
     59        if ( ! empty( $active_plugins ) ) {
     60                printf( '<p>' . __( 'Please <a href="%s">deactivate</a> your plugins before enabling WordPress Sites. Once WordPress Sites are enabled, you may reactivate your plugins.' ) . '</p>', admin_url( 'plugins.php' ) );
     61                include( './admin-footer.php' );
     62                die();
     63        }
    8264
    83         // remove ending slash from $base and $url
    84         $htaccess = '';
    85         if ( substr( $base, -1 ) == '/' )
    86                 $base = substr( $base, 0, -1 );
    87 
    88         $htaccess_sample = ABSPATH . 'wp-admin/includes/htaccess.ms';
    89         if ( ! file_exists( $htaccess_sample ) )
    90                 wp_die( sprintf( __( 'Sorry, I need a %s to work from. Please re-upload this file to your WordPress installation.' ), $htaccess_sample ) );
    91 
    92         $htaccess_file = file( $htaccess_sample );
    93         $fp = @fopen( $htaccess_sample, "r" );
    94         if ( $fp ) {
    95                 while ( ! feof( $fp ) ) {
    96                         $htaccess .= fgets( $fp, 4096 );
    97                 }
    98                 fclose( $fp );
    99                 $htaccess_file = str_replace( "BASE", $base, $htaccess );
    100         } else {
    101                 wp_die( sprintf( __( 'Sorry, I need to be able to read %s. Please check the permissions on this file.' ), $htaccess_sample ) );
     65        $hostname = get_clean_basedomain();
     66        if ( 'localhost' == $hostname || preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $hostname ) ) {
     67                echo '<p><strong>' . __('You cannot install a network of sites with your server address.' ) . '</strong></p>';
     68                echo '<p>' . __('You cannot use an IP address such as <code>127.0.0.1</code> or a single-word hostname like <code>localhost</code>.' ) . '</p>';
     69                if ( 'localhost' == $hostname )
     70                        echo '<p>' . __('Consider using <code>localhost.localdomain</code>.') . '</p>';
     71                include( './admin-footer.php' );
     72                die();
    10273        }
    103 ?>
    104                         <li><p><?php printf( __( 'Replace the contents of your <code>%s.htaccess</code> with the following:' ), ABSPATH ); ?></p>
    105                                 <textarea name="htaccess" cols="120" rows="20">
    106 <?php echo wp_htmledit_pre( $htaccess_file ); ?>
    107                                 </textarea>
    108                         </li>
    109 <?php
    110 }
    11174
    112 /**
    113  * Prints part of step 1 for network settings and checks for mod_rewrite.
    114  *
    115  * @since 3.0.0
    116  * @return bool Whether mod_rewrite is enabled.
    117  */
    118 function step1() {
    119         $rewrite_enabled = false;
    12075        ?>
    121         <h2><?php esc_html_e( 'Installing Network of WordPress Sites' ); ?></h2>
    122         <p><?php _e( 'I will help you enable the features for creating a network of sites by asking you a few questions so that you can create configuration files and make a directory to store all your uploaded files.' ); ?></p>
    123 
    124         <h2><?php esc_html_e( 'What do I need?' ); ?></h2>
    125         <ul>
    126                 <li><?php _e( 'Access to your server to change directory permissions. This can be done through ssh or ftp for example.' ); ?></li>
    127                 <li><?php _e( 'A valid email where your password and administrative emails will be sent.' ); ?></li>
    128                 <li><?php _e( "Wildcard dns records if you're going to use the virtual host (sub-domain) functionality. Check the <a href='http://trac.mu.wordpress.org/browser/trunk/README.txt'>README</a> for further details." ); ?></li>
    129         </ul>
     76        <p><?php _e( 'Welcome to the Network installation process!' ); ?></p>
     77        <p><?php _e( "Fill in the information below and you&#8217;ll be on your way to creating a network of WordPress sites. We'll create configuration files in the next step." ); ?></p>
    13078        <?php
    131         $mod_rewrite_msg = "\n<p>" . __( 'If the <code>mod_rewrite</code> module is disabled ask your administrator to enable that module, or look at the <a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">Apache documentation</a> or <a href="http://www.google.com/search?q=apache+mod_rewrite">elsewhere</a> for help setting it up.' ) . '</p>';
    13279
    133         if ( function_exists( 'apache_get_modules' ) ) {
    134                 $modules = apache_get_modules();
    135                 if ( ! in_array( 'mod_rewrite', $modules ) )
    136                         echo '<p>' . __( '<strong>Warning!</strong> It looks like mod_rewrite is not installed.' ) . '</p>' . $mod_rewrite_msg;
    137                 else
    138                         $rewrite_enabled = true;
     80        if ( apache_mod_loaded('mod_rewrite') ) { // assume nothing
     81                $rewrite_enabled = true;
    13982        } else {
    140                 echo '<p>' . __( 'Please make sure <code>mod_rewrite</code> is installed as it will be activated at the end of this install.' ) . '</p>' . $mod_rewrite_msg;
     83                $rewrite_enabled = false;
     84                if ( got_mod_rewrite() ) // dangerous assumptions
     85                        echo '<p>' . __( 'Please make sure the Apache <code>mod_rewrite</code> module is installed as it will be used at the end of this install.' ) . '</p>';
     86                else
     87                        echo '<p>' . __( '<strong>Warning!</strong> It looks like Apache <code>mod_rewrite</code> module is not installed.' ) . '</p>';
     88                echo '<p>' . __( 'If <code>mod_rewrite</code> is disabled ask your administrator to enable that module, or look at the <a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">Apache documentation</a> or <a href="http://www.google.com/search?q=apache+mod_rewrite">elsewhere</a> for help setting it up.' ) . '</p>';
    14189        }
    142         return $rewrite_enabled;
    143 }
    14490
    145 /**
    146  * Prints most of step 1 for network settings.
    147  *
    148  * @since 3.0.0
    149  * @param bool $rewrite_enabled Whether mod_rewrite is enabled. Default false.
    150  */
    151 function printstep1form( $rewrite_enabled = false ) {
    152         $weblog_title = sprintf( __( '%s Sites' ), ucfirst( get_option( 'blogname' ) ) );
    153         $email = get_option( 'admin_email' );
    154         $hostname = get_clean_basedomain();
    155         $invalid_host = false;
    156         if ( 'localhost' == $hostname || preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $hostname, $match ) )
    157                 $invalid_host = true;
    158         if ( substr( $hostname, 0, 4 ) == 'www.' )
    159                 $nowww = substr( $hostname, 4 );
    160 
    16191        wp_nonce_field( 'install-network-1' );
    16292        if ( network_domain_check() ) { ?>
    16393                <h2><?php esc_html_e( 'Existing Sites' ); ?></h2>
    16494                <p><?php _e( 'An existing WordPress Network was detected.' ); ?></p>
    16595                <p class="existing-network">
    166                         <label><input type='checkbox' name='existing_network' value='yes' /> <?php _e( 'Yes, keep the existing network of sites.' ); ?></label><br />
     96                        <label><input type='checkbox' name='existing_network' value='1' /> <?php _e( 'Yes, keep the existing network of sites.' ); ?></label><br />
    16797                </p>
    16898
    16999<?php   } else { ?>
    170                 <input type='hidden' name='existing_network' value='none' />
     100                <input type='hidden' name='existing_network' value='0' />
    171101<?php   } ?>
    172102                <input type='hidden' name='action' value='step2' />
    173                 <h2><?php esc_html_e( 'Site Addresses' ); ?></h2>
    174                 <p><?php _e( 'Please choose whether you would like sites in your WordPress install to use sub-domains or sub-directories. You cannot change this later.' ); ?></p>
     103                <h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
     104       
     105                <p><?php _e( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories. <strong>You cannot change this later.</strong>' ); ?></p>
     106                <p><?php _e( "You will need a wildcard DNS record if you're going to use the virtual host (sub-domain) functionality." ); ?></p>
     107                <?php /* @todo: Link to an MS readme? */ ?>
    175108                <?php if ( ! $rewrite_enabled ) { ?>
    176109                <p><?php _e( '<strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.' ); ?></p>
    177110                <?php } ?>
    178                 <p class="blog-address">
    179                         <label><input type='radio' name='vhost' value='yes'<?php if ( $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-domains (like <code>blog1.example.com</code>)' ); ?></label><br />
    180                         <label><input type='radio' name='vhost' value='no'<?php if ( ! $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-directories (like <code>example.com/blog1</code>)' ); ?></label>
    181                 </p>
     111                <table class="form-table">
     112                        <tr>
     113                                <th><label><input type='radio' name='vhost' value='yes'<?php checked( $rewrite_enabled ); ?> /> Sub-domains</label></th>
     114                                <td><?php _e('like <code>blog1.example.com</code> and <code>blog2.example.com</code>'); ?></td>
     115                        </tr>
     116                        <tr>
     117                                <th><label><input type='radio' name='vhost' value='no'<?php checked( ! $rewrite_enabled ); ?> /> Sub-directories</label></th>
     118                                <td><?php _e('like <code>example.com/blog1</code> and <code>example.com/blog2</code>'); ?></td>
     119                        </tr>
     120                </table>
    182121
    183                 <h2><?php esc_html_e( 'Server Address' ); ?></h2>
    184                 <?php if ( isset( $nowww ) ) { ?>
    185                 <h3><?php printf( __( 'We recommend you change your siteurl to <code>%1$s</code> before enabling the network feature. It will still be possible to visit your site using the "www" prefix with an address like <code>%2$s</code> but any links will not have the "www" prefix.' ), $nowww, $hostname ); ?></h3>
    186                 <?php } ?>
     122                <?php
     123                $is_www = ( substr( $hostname, 0, 4 ) == 'www.' );
     124                if ( $is_www ) :
     125                ?>
     126                <h3><?php esc_html_e( 'Server Address' ); ?></h3>
     127                <p><?php printf( __( 'We recommend you change your siteurl to <code>%1$s</code> before enabling the network feature. It will still be possible to visit your site using the "www" prefix with an address like <code>%2$s</code> but any links will not have the "www" prefix.' ), substr( $hostname, 4 ), $hostname ); ?></h3>
    187128                <table class="form-table">
    188129                        <tr>
    189130                                <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
    190131                                <td>
    191                 <?php if ( !$invalid_host ) { ?>
    192                                         <?php printf( __( 'This will be the Internet address of your site: <strong><em>%s</em></strong>.' ), $hostname ); ?>
     132                                        <?php printf( __( 'The Internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
    193133                                        <input type='hidden' name='basedomain' value='<?php echo esc_attr( $hostname ); ?>' />
    194                 <?php } else { ?>
    195                                         <?php _e( 'Do not use an IP address (like 127.0.0.1) or a single word hostname like <q>localhost</q> as your server address.' ); ?>
    196                 <?php } ?>
    197134                                </td>
    198135                        </tr>
    199136                </table>
     137                <?php endif; ?>
    200138
    201                 <h2><?php esc_html_e( 'Site Details' ); ?></h2>
     139                <h3><?php esc_html_e( 'Network Details' ); ?></h3>
    202140                <table class="form-table">
     141                <?php if ( ! $is_www ) : ?>
    203142                        <tr>
    204                                 <th scope='row'><?php esc_html_e( 'Site&nbsp;Title' ); ?></th>
     143                                <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
    205144                                <td>
    206                                         <input name='weblog_title' type='text' size='45' value='<?php echo esc_attr( $weblog_title ); ?>' />
    207                                         <br /><?php _e( 'What would you like to call your site?' ); ?>
     145                                        <?php printf( __( 'The Internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
    208146                                </td>
    209147                        </tr>
     148                <?php endif; ?>
    210149                        <tr>
    211                                 <th scope='row'><?php esc_html_e( 'Email' ); ?></th>
     150                                <th scope='row'><?php esc_html_e( 'Network Title' ); ?></th>
    212151                                <td>
    213                                         <input name='email' type='text' size='45' value='<?php echo esc_attr( $email ); ?>' />
     152                                        <input name='weblog_title' type='text' size='45' value='<?php echo esc_attr( sprintf( __('%s Sites'), get_option( 'blogname' ) ) ); ?>' />
     153                                        <br /><?php _e( 'What would you like to call your network?' ); ?>
     154                                </td>
     155                        </tr>
     156                        <tr>
     157                                <th scope='row'><?php esc_html_e( 'Admin E-mail Address' ); ?></th>
     158                                <td>
     159                                        <input name='email' type='text' size='45' value='<?php echo esc_attr( get_option( 'admin_email' ) ); ?>' />
    214160                                        <br /><?php _e( 'Your email address.' ); ?>
    215161                                </td>
    216162                        </tr>
    217163                </table>
    218                 <?php if ( !$invalid_host ) { ?>
    219                 <p class='submit'><input class="button" name='submit' type='submit' value='<?php esc_attr_e( 'Proceed' ); ?>' /></p>
    220                 <?php } ?>
    221         <?php
     164                <p class='submit'><input class="button-primary" name='submit' type='submit' value='<?php esc_attr_e( 'Install' ); ?>' /></p>
     165                <?php
    222166}
    223167
    224168/**
    225  * Checks for active plugins & displays a notice to deactivate them.
     169 * Prints step 2 for Network installation process.
    226170 *
    227171 * @since 3.0.0
    228172 */
    229 function step1_plugin_check() {
    230         $active_plugins = get_option( 'active_plugins' );
    231         if ( is_array( $active_plugins ) && !empty( $active_plugins ) ) {
    232 ?>
    233                 <h2><?php esc_html_e( 'Enabling WordPress Sites' ); ?></h2>
    234                 <p><?php printf( __( 'Please <a href="%s">deactivate</a> your plugins before enabling WordPress Sites. Once WordPress Sites are enabled, you may reactivate your plugins.' ), admin_url( 'plugins.php' ) ); ?></p>
    235 <?php
    236                 return false;
    237         }
    238         return true;
    239 }
    240 
    241 /**
    242  * Checks for existing network data/tables.
    243  *
    244  * @since 3.0.0
    245  */
    246 function network_domain_check() {
    247         global $wpdb;
    248 
    249         if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) == $wpdb->site )
    250                 return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
    251 
    252         return false;
    253 }
    254 
    255 /**
    256  * Prints step 2 for network settings.
    257  *
    258  * @since 3.0.0
    259  */
    260173function step2() {
     174        global $base, $wpdb;
    261175?>
    262                 <h2><?php esc_html_e( 'Enabling WordPress Sites' ); ?></h2>
     176                <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
    263177                <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites. <strong>Note:</strong> We recommend you make a backup copy of your existing <code>wp-config.php</code> and <code>.htaccess</code> files.' ); ?></p>
    264178                <ol>
    265179                        <li><?php printf( __( 'Create a <code>%s/blogs.dir</code> directory. This directory is used to stored uploaded media for your additional sites and must be writeable by the web server.' ), WP_CONTENT_DIR ); ?></li>
    266 <?php step2_config(); ?>
    267 <?php step2_htaccess(); ?>
    268                 </ol>
    269180<?php
    270 }
    271 
    272 /**
    273  * Prints configuration file component of step 2 for network settings.
    274  *
    275  * @since 3.0.0
    276  */
    277 function step2_config() {
    278         global $base, $wpdb, $vhost;
    279 
    280181        $vhost   = stripslashes( $_POST['vhost' ] );
    281182        $prefix  = $wpdb->base_prefix;
    282183
    283         $config_sample = ABSPATH . 'wp-admin/includes/wp-config.ms';
     184        $config_sample = ABSPATH . 'wp-admin/includes/ms-config-sample.php';
    284185        if ( ! file_exists( $config_sample ) )
    285186                wp_die( sprintf( __( 'Sorry, I need a <code>%s</code> to work from. Please re-upload this file to your WordPress installation.' ), $config_sample ) );
    286187
     
    341242                                </textarea>
    342243                        </li>
    343244<?php
    344 }
    345245
    346 /**
    347  * Gets base domain of network.
    348  *
    349  * @since 3.0.0
    350  */
    351 function get_clean_basedomain() {
    352         global $wpdb;
     246        // remove ending slash from $base and $url
     247        $htaccess = '';
     248        if ( substr( $base, -1 ) == '/' )
     249                $base = substr( $base, 0, -1 );
    353250
    354         $existing_domain = network_domain_check();
    355         if ( $existing_domain )
    356                 return $existing_domain;
     251        $htaccess_sample = ABSPATH . 'wp-admin/includes/htaccess.ms';
     252        if ( ! file_exists( $htaccess_sample ) )
     253                wp_die( sprintf( __( 'Sorry, I need a %s to work from. Please re-upload this file to your WordPress installation.' ), $htaccess_sample ) );
    357254
    358         $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
    359         if ( strpos( $domain, '/' ) )
    360                 $domain = substr( $domain, 0, strpos( $domain, '/' ) );
    361         return $domain;
     255        $htaccess_file = file( $htaccess_sample );
     256        $fp = @fopen( $htaccess_sample, "r" );
     257        if ( $fp ) {
     258                while ( ! feof( $fp ) ) {
     259                        $htaccess .= fgets( $fp, 4096 );
     260                }
     261                fclose( $fp );
     262                $htaccess_file = str_replace( "BASE", $base, $htaccess );
     263        } else {
     264                wp_die( sprintf( __( 'Sorry, I need to be able to read %s. Please check the permissions on this file.' ), $htaccess_sample ) );
     265        }
     266?>
     267                        <li><p><?php printf( __( 'Replace the contents of your <code>%s.htaccess</code> with the following:' ), ABSPATH ); ?></p>
     268                                <textarea name="htaccess" cols="120" rows="20">
     269<?php echo wp_htmledit_pre( $htaccess_file ); ?>
     270                                </textarea>
     271                        </li>
     272                </ol>
     273<?php
    362274}
    363275
    364 $action = isset( $_POST[ 'action' ] ) ? $_POST[ 'action' ] : null;
     276$action = isset( $_POST['action'] ) ? $_POST['action'] : null;
    365277
    366 switch( $action ) {
     278switch ( $action ) {
    367279        case 'step2':
    368280                check_admin_referer( 'install-network-1' );
    369281
    370                 if ( isset( $_POST[ 'existing_network' ] ) ) {
    371                         // Install!
    372                         $base = stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) );
    373                         if ( $base != '/' )
    374                                 $base .= '/';
     282                // Install!
     283                $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
    375284
    376                         require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    377                         // create network tables
    378                         $domain = get_clean_basedomain();
    379                         install_network();
    380                         if ( !network_domain_check() || $_POST[ 'existing_network' ] == 'none' )
    381                                 populate_network( 1, $domain, sanitize_email( $_POST['email'] ), $_POST['weblog_title'], $base, $_POST['vhost'] );
    382                         // create wp-config.php / htaccess
    383                         step2();
    384                         break;
    385                 }
     285                require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     286                // create network tables
     287                install_network();
     288                if ( !network_domain_check() || $_POST['existing_network'] == '0' )
     289                        populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), $_POST['weblog_title'], $base, $_POST['vhost'] );
     290                // create wp-config.php / htaccess
     291                step2();
     292                break;
     293
    386294        default:
    387                 //@todo: give an informative screen instead
    388                 if ( is_multisite() ) {
    389                         _e( 'Network already enabled.' );
    390                 } elseif ( step1_plugin_check() ) {
    391                         $rewrite_enabled = step1();
    392                         printstep1form( $rewrite_enabled );
    393                 }
    394         break;
     295                step1();
     296                break;
    395297}
    396298?>
    397299</form>