]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/network.php
WordPress 4.2.5-scripts
[autoinstalls/wordpress.git] / wp-admin / network.php
index 6ff266bd685b588b5447ddb938dff74cdecf5b91..fdc0a51b52084926434960ded7f75b6766ea4988 100644 (file)
  * @subpackage Administration
  */
 
-define( 'WP_NETWORK_ADMIN_PAGE', true );
+define( 'WP_INSTALLING_NETWORK', true );
 
 /** WordPress Administration Bootstrap */
-require_once( './admin.php' );
+require_once( dirname( __FILE__ ) . '/admin.php' );
 
 if ( ! is_super_admin() )
        wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
@@ -39,8 +39,11 @@ foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table )
  */
 function network_domain_check() {
        global $wpdb;
-       if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
+
+       $sql = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) );
+       if ( $wpdb->get_var( $sql ) ) {
                return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
+       }
        return false;
 }
 
@@ -51,20 +54,27 @@ function network_domain_check() {
  * @return bool Whether subdomain install is allowed
  */
 function allow_subdomain_install() {
-       $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'siteurl' ) );
-       if( false !== strpos( $domain, '/' ) || 'localhost' == $domain || preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $domain ) )
+       $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
+       if( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) )
                return false;
 
        return true;
 }
 /**
- * Allow subdirectory install
+ * Allow subdirectory install.
  *
  * @since 3.0.0
  * @return bool Whether subdirectory install is allowed
  */
 function allow_subdirectory_install() {
        global $wpdb;
+        /**
+         * Filter whether to enable the subdirectory install feature in Multisite.
+         *
+         * @since 3.0.0
+         *
+         * @param bool true Whether to enable the subdirectory install feature in Multisite. Default is false.
+         */
        if ( apply_filters( 'allow_subdirectory_install', false ) )
                return true;
 
@@ -103,22 +113,32 @@ if ( is_network_admin() ) {
        $parent_file = 'tools.php';
 }
 
-add_contextual_help($current_screen,
-       '<p>' . __('This screen allows you to configure a network as having subdomains (<code>site1.example.com</code>) or subdirectories (<code>example.com/site1</code>). Subdomains require wildcard subdomains to be enabled in Apache and DNS records, if your host allows it.') . '</p>' .
+$network_help = '<p>' . __('This screen allows you to configure a network as having subdomains (<code>site1.example.com</code>) or subdirectories (<code>example.com/site1</code>). Subdomains require wildcard subdomains to be enabled in Apache and DNS records, if your host allows it.') . '</p>' .
        '<p>' . __('Choose subdomains or subdirectories; this can only be switched afterwards by reconfiguring your install. Fill out the network details, and click install. If this does not work, you may have to add a wildcard DNS record (for subdomains) or change to another setting in Permalinks (for subdirectories).') . '</p>' .
-       '<p>' . __('The next screen for Network will give you individually-generated lines of code to add to your wp-config.php and .htaccess files. Make sure the settings of your FTP client make files starting with a dot visible, so that you can find .htaccess; you may have to create this file if it really is not there. Make backup copies of those two files.') . '</p>' .
-       '<p>' . __('Add a <code>blogs.dir</code> directory under <code>/wp-content</code> and add the designated lines of code to wp-config.php (just before <code>/*...stop editing...*/</code>) and <code>.htaccess</code> (replacing the existing WordPress rules).') . '</p>' .
-       '<p>' . __('The choice of subdirectory sites is disabled if this setup is more than a month old because of permalink problems with &#8220;/blog/&#8221; from the main site. This disabling will be addressed soon in a future version.') . '</p>' .
+       '<p>' . __('The next screen for Network Setup will give you individually-generated lines of code to add to your wp-config.php and .htaccess files. Make sure the settings of your FTP client make files starting with a dot visible, so that you can find .htaccess; you may have to create this file if it really is not there. Make backup copies of those two files.') . '</p>' .
+       '<p>' . __('Add the designated lines of code to wp-config.php (just before <code>/*...stop editing...*/</code>) and <code>.htaccess</code> (replacing the existing WordPress rules).') . '</p>' .
+       '<p>' . __('Once you add this code and refresh your browser, multisite should be enabled. This screen, now in the Network Admin navigation menu, will keep an archive of the added code. You can toggle between Network Admin and Site Admin by clicking on the Network Admin or an individual site name under the My Sites dropdown in the Toolbar.') . '</p>' .
+       '<p>' . __('The choice of subdirectory sites is disabled if this setup is more than a month old because of permalink problems with &#8220;/blog/&#8221; from the main site. This disabling will be addressed in a future version.') . '</p>' .
+       '<p><strong>' . __('For more information:') . '</strong></p>' .
+       '<p>' . __('<a href="https://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>') . '</p>' .
+       '<p>' . __('<a href="https://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>') . '</p>';
+
+get_current_screen()->add_help_tab( array(
+       'id'      => 'network',
+       'title'   => __('Network'),
+       'content' => $network_help,
+) );
+
+get_current_screen()->set_help_sidebar(
        '<p><strong>' . __('For more information:') . '</strong></p>' .
-       '<p>' . __('<a href="http://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>') . '</p>' .
-       '<p>' . __('<a href="http://codex.wordpress.org/Tools_Network_SubPanel" target="_blank">Documentation on the Network Screen</a>') . '</p>' .
-       '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
+       '<p>' . __('<a href="https://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>') . '</p>' .
+       '<p>' . __('<a href="https://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>') . '</p>' .
+       '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
 );
 
 include( ABSPATH . 'wp-admin/admin-header.php' );
 ?>
 <div class="wrap">
-<?php screen_icon('tools'); ?>
 <h2><?php echo esc_html( $title ); ?></h2>
 
 <?php
@@ -133,17 +153,10 @@ include( ABSPATH . 'wp-admin/admin-header.php' );
 function network_step1( $errors = false ) {
        global $is_apache;
 
-       if ( get_option( 'siteurl' ) != get_option( 'home' ) ) {
-               echo '<div class="error"><p><strong>' . __('Error:') . '</strong> ' . sprintf( __( 'Your <strong>WordPress address</strong> must match your <strong>Site address</strong> before creating a Network. See <a href="%s">General Settings</a>.' ), esc_url( admin_url( 'options-general.php' ) ) ) . '</p></div>';
-               echo '</div>';
-               include ( ABSPATH . 'wp-admin/admin-footer.php' );
-               die();
-       }
-
        if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
-               echo '<div class="error"><p><strong>' . __('Error:') . '</strong> ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>';
+               echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>';
                echo '</div>';
-               include ( ABSPATH . 'wp-admin/admin-footer.php' );
+               include( ABSPATH . 'wp-admin/admin-footer.php' );
                die();
        }
 
@@ -158,7 +171,7 @@ function network_step1( $errors = false ) {
        $hostname = get_clean_basedomain();
        $has_ports = strstr( $hostname, ':' );
        if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
-               echo '<div class="error"><p><strong>' . __( 'Error:') . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
+               echo '<div class="error"><p><strong>' . __( 'ERROR:') . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
                echo '<p>' . sprintf( __( 'You cannot use port numbers such as <code>%s</code>.' ), $has_ports ) . '</p>';
                echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>';
                echo '</div>';
@@ -166,7 +179,7 @@ function network_step1( $errors = false ) {
                die();
        }
 
-       echo '<form method="post" action="">';
+       echo '<form method="post">';
 
        wp_nonce_field( 'install-network-1' );
 
@@ -179,9 +192,6 @@ function network_step1( $errors = false ) {
                $error_codes = $errors->get_error_codes();
        }
 
-       if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' )
-               echo '<div class="error"><p><strong>' . __('Warning!') . '</strong> ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
-
        $site_name = ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) ? $_POST['sitename'] : sprintf( _x('%s Sites', 'Default network name' ), get_option( 'blogname' ) );
        $admin_email = ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) ? $_POST['email'] : get_option( 'admin_email' );
        ?>
@@ -212,23 +222,34 @@ function network_step1( $errors = false ) {
                <?php // @todo: Link to an MS readme? ?>
                <table class="form-table">
                        <tr>
-                               <th><label><input type='radio' name='subdomain_install' value='1'<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
-                               <td><?php printf( _x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ), $hostname ); ?></td>
+                               <th><label><input type="radio" name="subdomain_install" value="1"<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
+                               <td><?php printf(
+                                       /* translators: 1: hostname */
+                                       _x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ),
+                                       $hostname
+                               ); ?></td>
                        </tr>
                        <tr>
-                               <th><label><input type='radio' name='subdomain_install' value='0'<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
-                               <td><?php printf( _x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ), $hostname ); ?></td>
+                               <th><label><input type="radio" name="subdomain_install" value="0"<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
+                               <td><?php printf(
+                                       /* translators: 1: hostname */
+                                       _x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ),
+                                       $hostname
+                               ); ?></td>
                        </tr>
                </table>
 
 <?php
        endif;
 
+               if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) )
+                       echo '<div class="error inline"><p><strong>' . __('Warning!') . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
+
                $is_www = ( 0 === strpos( $hostname, 'www.' ) );
                if ( $is_www ) :
                ?>
                <h3><?php esc_html_e( 'Server Address' ); ?></h3>
-               <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 <code>www</code> prefix with an address like <code>%2$s</code> but any links will not have the <code>www</code> prefix.' ), substr( $hostname, 4 ), $hostname ); ?></h3>
+               <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 <code>www</code> prefix with an address like <code>%2$s</code> but any links will not have the <code>www</code> prefix.' ), substr( $hostname, 4 ), $hostname ); ?></p>
                <table class="form-table">
                        <tr>
                                <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
@@ -281,14 +302,18 @@ function network_step1( $errors = false ) {
                                <th scope='row'><?php esc_html_e( 'Network Title' ); ?></th>
                                <td>
                                        <input name='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' />
-                                       <br /><?php _e( 'What would you like to call your network?' ); ?>
+                                       <p class="description">
+                                               <?php _e( 'What would you like to call your network?' ); ?>
+                                       </p>
                                </td>
                        </tr>
                        <tr>
-                               <th scope='row'><?php esc_html_e( 'Admin E-mail Address' ); ?></th>
+                               <th scope='row'><?php esc_html_e( 'Network Admin Email' ); ?></th>
                                <td>
                                        <input name='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' />
-                                       <br /><?php _e( 'Your email address.' ); ?>
+                                       <p class="description">
+                                               <?php _e( 'Your email address.' ); ?>
+                                       </p>
                                </td>
                        </tr>
                </table>
@@ -303,11 +328,23 @@ function network_step1( $errors = false ) {
  * @since 3.0.0
  */
 function network_step2( $errors = false ) {
-       global $base, $wpdb;
-       $hostname = get_clean_basedomain();
+       global $wpdb;
 
-       if ( ! isset( $base ) )
-               $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
+       $hostname          = get_clean_basedomain();
+       $slashed_home      = trailingslashit( get_option( 'home' ) );
+       $base              = parse_url( $slashed_home, PHP_URL_PATH );
+       $document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
+       $abspath_fix       = str_replace( '\\', '/', ABSPATH );
+       $home_path         = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
+       $wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
+       $rewrite_base      = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
+
+
+       $location_of_wp_config = $abspath_fix;
+       if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) {
+               $location_of_wp_config = dirname( $abspath_fix );
+       }
+       $location_of_wp_config = trailingslashit( $location_of_wp_config );
 
        // Wildcard DNS message.
        if ( is_wp_error( $errors ) )
@@ -333,14 +370,18 @@ function network_step2( $errors = false ) {
                }
        }
 
+       $subdir_match          = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
+       $subdir_replacement_01 = $subdomain_install ? '' : '$1';
+       $subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
+
        if ( $_POST || ! is_multisite() ) {
 ?>
                <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
                <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
                <div class="updated inline"><p><?php
-                       if ( file_exists( ABSPATH . '.htaccess' ) )
+                       if ( file_exists( $home_path . '.htaccess' ) )
                                printf( __( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), '.htaccess' );
-                       elseif ( file_exists( ABSPATH . 'web.config' ) )
+                       elseif ( file_exists( $home_path . 'web.config' ) )
                                printf( __( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), 'web.config' );
                        else
                                _e( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> file.' );
@@ -349,26 +390,22 @@ function network_step2( $errors = false ) {
        }
 ?>
                <ol>
-                       <li><p><?php
-                               printf( __( 'Create a <code>blogs.dir</code> directory at <code>%s/blogs.dir</code>. This directory is used to store uploaded media for your additional sites and must be writeable by the web server.' ), WP_CONTENT_DIR );
-                               if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' )
-                                       echo ' <strong>' . __('Warning:') . ' ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '</strong';
-                       ?></p></li>
-                       <li><p><?php printf( __( 'Add the following to your <code>wp-config.php</code> file in <code>%s</code> <strong>above</strong> the line reading <code>/* That&#8217;s all, stop editing! Happy blogging. */</code>:' ), ABSPATH ); ?></p>
+                       <li><p><?php printf( __( 'Add the following to your <code>wp-config.php</code> file in <code>%s</code> <strong>above</strong> the line reading <code>/* That&#8217;s all, stop editing! Happy blogging. */</code>:' ), $location_of_wp_config ); ?></p>
                                <textarea class="code" readonly="readonly" cols="100" rows="7">
-define( 'MULTISITE', true );
-define( 'SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> );
-$base = '<?php echo $base; ?>';
-define( 'DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>' );
-define( 'PATH_CURRENT_SITE', '<?php echo $base; ?>' );
-define( 'SITE_ID_CURRENT_SITE', 1 );
-define( 'BLOG_ID_CURRENT_SITE', 1 );</textarea>
+define('MULTISITE', true);
+define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
+define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
+define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
+define('SITE_ID_CURRENT_SITE', 1);
+define('BLOG_ID_CURRENT_SITE', 1);
+</textarea>
 <?php
        $keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
        foreach ( $keys_salts as $c => $v ) {
                if ( defined( $c ) )
                        unset( $keys_salts[ $c ] );
        }
+
        if ( ! empty( $keys_salts ) ) {
                $keys_salts_str = '';
                $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
@@ -384,8 +421,16 @@ define( 'BLOG_ID_CURRENT_SITE', 1 );</textarea>
                }
                $num_keys_salts = count( $keys_salts );
 ?>
-       <p><?php
-               echo _n( 'This unique authentication key is also missing from your <code>wp-config.php</code> file.', 'These unique authentication keys are also missing from your <code>wp-config.php</code> file.', $num_keys_salts ); ?> <?php _e( 'To make your installation more secure, you should also add:' ) ?></p>
+       <p>
+               <?php
+                       if ( 1 == $num_keys_salts ) {
+                               _e( 'This unique authentication key is also missing from your <code>wp-config.php</code> file.' );
+                       } else {
+                               _e( 'These unique authentication keys are also missing from your <code>wp-config.php</code> file.' );
+                       }
+               ?>
+               <?php _e( 'To make your installation more secure, you should also add:' ); ?>
+       </p>
        <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
 <?php
        }
@@ -393,10 +438,12 @@ define( 'BLOG_ID_CURRENT_SITE', 1 );</textarea>
 </li>
 <?php
        if ( iis7_supports_permalinks() ) :
+               // IIS doesn't support RewriteBase, all your RewriteBase are belong to us
+               $iis_subdir_match = ltrim( $base, '/' ) . $subdir_match;
+               $iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base;
+               $iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
 
-                       if ( $subdomain_install ) {
-                               $web_config_file =
-'<?xml version="1.0" encoding="UTF-8"?>
+               $web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
 <configuration>
     <system.webServer>
         <rewrite>
@@ -404,10 +451,18 @@ define( 'BLOG_ID_CURRENT_SITE', 1 );</textarea>
                 <rule name="WordPress Rule 1" stopProcessing="true">
                     <match url="^index\.php$" ignoreCase="false" />
                     <action type="None" />
-                </rule>
+                </rule>';
+                               if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
+                                       $web_config_file .= '
+                <rule name="WordPress Rule for Files" stopProcessing="true">
+                    <match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" />
+                    <action type="Rewrite" url="' . $iis_rewrite_base . WPINC . '/ms-files.php?file={R:1}" appendQueryString="false" />
+                </rule>';
+                }
+                $web_config_file .= '
                 <rule name="WordPress Rule 2" stopProcessing="true">
-                    <match url="^files/(.+)" ignoreCase="false" />
-                    <action type="Rewrite" url="wp-includes/ms-files.php?file={R:1}" appendQueryString="false" />
+                    <match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" />
+                    <action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" />
                 </rule>
                 <rule name="WordPress Rule 3" stopProcessing="true">
                     <match url="^" ignoreCase="false" />
@@ -418,113 +473,91 @@ define( 'BLOG_ID_CURRENT_SITE', 1 );</textarea>
                     <action type="None" />
                 </rule>
                 <rule name="WordPress Rule 4" stopProcessing="true">
-                    <match url="." ignoreCase="false" />
-                    <action type="Rewrite" url="index.php" />
-                </rule>
-            </rules>
-        </rewrite>
-    </system.webServer>
-</configuration>';
-                       } else {
-                               $web_config_file =
-'<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
-    <system.webServer>
-        <rewrite>
-            <rules>
-                <rule name="WordPress Rule 1" stopProcessing="true">
-                    <match url="^index\.php$" ignoreCase="false" />
-                    <action type="None" />
-                </rule>
-                <rule name="WordPress Rule 2" stopProcessing="true">
-                    <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" />
-                    <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" />
-                </rule>
-                <rule name="WordPress Rule 3" stopProcessing="true">
-                    <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
-                    <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
-                </rule>
-                <rule name="WordPress Rule 4" stopProcessing="true">
-                    <match url="^" ignoreCase="false" />
-                    <conditions logicalGrouping="MatchAny">
-                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
-                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
-                    </conditions>
-                    <action type="None" />
+                    <match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" />
+                    <action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" />
                 </rule>
                 <rule name="WordPress Rule 5" stopProcessing="true">
-                    <match url="^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*)" ignoreCase="false" />
-                    <action type="Rewrite" url="{R:2}" />
+                    <match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
+                    <action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" />
                 </rule>
                 <rule name="WordPress Rule 6" stopProcessing="true">
-                    <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
-                    <action type="Rewrite" url="{R:2}" />
-                </rule>
-                <rule name="WordPress Rule 7" stopProcessing="true">
                     <match url="." ignoreCase="false" />
                     <action type="Rewrite" url="index.php" />
                 </rule>
             </rules>
         </rewrite>
     </system.webServer>
-</configuration>';
-                       }
-       ?>
-               <li><p><?php printf( __( 'Add the following to your <code>web.config</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
-               <textarea class="code" readonly="readonly" cols="100" rows="20">
-               <?php echo esc_textarea( $web_config_file ); ?>
+</configuration>
+';
+
+               echo '<li><p>';
+               /* translators: 1: a filename like .htaccess. 2: a file path. */
+               printf( __( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
+                       '<code>web.config</code>', '<code>' . $home_path . '</code>' );
+               echo '</p>';
+               if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
+                       echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
+               ?>
+               <textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?>
                </textarea></li>
                </ol>
 
        <?php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
 
-               $htaccess_file = 'RewriteEngine On
-RewriteBase ' . $base . '
-RewriteRule ^index\.php$ - [L]
-
-# uploaded files
-RewriteRule ^' . ( $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $subdomain_install ? 1 : 2 ) . ' [L]' . "\n";
+               $ms_files_rewriting = '';
+               if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
+                       $ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
+                       $ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
+               }
 
-               if ( ! $subdomain_install )
-                       $htaccess_file .= "\n# add a trailing slash to /wp-admin\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]' . "\n";
+               $htaccess_file = <<<EOF
+RewriteEngine On
+RewriteBase {$base}
+RewriteRule ^index\.php$ - [L]
+{$ms_files_rewriting}
+# add a trailing slash to /wp-admin
+RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L]
 
-               $htaccess_file .= "\n" . 'RewriteCond %{REQUEST_FILENAME} -f [OR]
+RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -d
-RewriteRule ^ - [L]';
-
-               // @todo custom content dir.
-               if ( ! $subdomain_install )
-                       $htaccess_file .= "\nRewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]\nRewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]";
-
-               $htaccess_file .= "\nRewriteRule . index.php [L]";
-
+RewriteRule ^ - [L]
+RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
+RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L]
+RewriteRule . index.php [L]
+
+EOF;
+
+               echo '<li><p>';
+               /* translators: 1: a filename like .htaccess. 2: a file path. */
+               printf( __( 'Add the following to your %1$s file in %2$s, <strong>replacing</strong> other WordPress rules:' ),
+                       '<code>.htaccess</code>', '<code>' . $home_path . '</code>' );
+               echo '</p>';
+               if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
+                       echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
                ?>
-               <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
-               <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $subdomain_install ? 11 : 16; ?>">
+               <textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>">
 <?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
                </ol>
 
        <?php endif; // end IIS/Apache code branches.
 
        if ( !is_multisite() ) { ?>
-               <p><?php printf( __( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.') ); ?> <a href="<?php echo esc_url( site_url( 'wp-login.php' ) ); ?>"><?php _e( 'Log In' ); ?></a></p>
+               <p><?php _e( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.' ); ?> <a href="<?php echo esc_url( site_url( 'wp-login.php' ) ); ?>"><?php _e( 'Log In' ); ?></a></p>
 <?php
        }
 }
 
 if ( $_POST ) {
 
-       $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
-
        check_admin_referer( 'install-network-1' );
 
        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
-       // create network tables
+       // Create network tables.
        install_network();
-       $hostname = get_clean_basedomain();
-       $subdomain_install = !allow_subdomain_install() ? false : (bool) $_POST['subdomain_install'];
+       $base              = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
+       $subdomain_install = allow_subdomain_install() ? !empty( $_POST['subdomain_install'] ) : false;
        if ( ! network_domain_check() ) {
-               $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), stripslashes( $_POST['sitename'] ), $base, $subdomain_install );
+               $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), wp_unslash( $_POST['sitename'] ), $base, $subdomain_install );
                if ( is_wp_error( $result ) ) {
                        if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() )
                                network_step2( $result );