Make WordPress Core

Ticket #27025: network.php

File network.php, 25.5 KB (added by VarunAgw, 10 years ago)

Fix of the bug

Line 
1<?php
2/**
3 * Network installation administration panel.
4 *
5 * A multi-step process allowing the user to enable a network of WordPress sites.
6 *
7 * @since 3.0.0
8 *
9 * @package WordPress
10 * @subpackage Administration
11 */
12
13define( 'WP_INSTALLING_NETWORK', true );
14
15/** WordPress Administration Bootstrap */
16require_once( dirname( __FILE__ ) . '/admin.php' );
17
18if ( ! is_super_admin() )
19        wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
20
21if ( is_multisite() ) {
22        if ( ! is_network_admin() ) {
23                wp_redirect( network_admin_url( 'setup.php' ) );
24                exit;
25        }
26        if ( ! defined( 'MULTISITE' ) )
27                wp_die( __( 'The Network creation panel is not for WordPress MU networks.' ) );
28}
29
30// We need to create references to ms global tables to enable Network.
31foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table )
32        $wpdb->$table = $prefixed_table;
33
34/**
35 * Check for an existing network.
36 *
37 * @since 3.0.0
38 * @return Whether a network exists.
39 */
40function network_domain_check() {
41        global $wpdb;
42        if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
43                return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
44        return false;
45}
46
47/**
48 * Allow subdomain install
49 *
50 * @since 3.0.0
51 * @return bool Whether subdomain install is allowed
52 */
53function allow_subdomain_install() {
54        $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
55        if( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) )
56                return false;
57
58        return true;
59}
60/**
61 * Allow subdirectory install.
62 *
63 * @since 3.0.0
64 * @return bool Whether subdirectory install is allowed
65 */
66function allow_subdirectory_install() {
67        global $wpdb;
68        /**
69         * Filter whether to enable the subdirectory install feature in Multisite.
70         *
71         * @since 3.0.0
72         *
73         * @param bool true Whether to enable the subdirectory install feature in Multisite. Default is false.
74         */
75        if ( apply_filters( 'allow_subdirectory_install', false ) )
76                return true;
77
78        if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL )
79                return true;
80
81        $post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" );
82        if ( empty( $post ) )
83                return true;
84
85        return false;
86}
87/**
88 * Get base domain of network.
89 *
90 * @since 3.0.0
91 * @return string Base domain.
92 */
93function get_clean_basedomain() {
94        if ( $existing_domain = network_domain_check() )
95                return $existing_domain;
96        $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
97        if ( $slash = strpos( $domain, '/' ) )
98                $domain = substr( $domain, 0, $slash );
99        return $domain;
100}
101
102if ( ! network_domain_check() && ( ! defined( 'WP_ALLOW_MULTISITE' ) || ! WP_ALLOW_MULTISITE ) )
103        wp_die( __( 'You must define the <code>WP_ALLOW_MULTISITE</code> constant as true in your wp-config.php file to allow creation of a Network.' ) );
104
105if ( is_network_admin() ) {
106        $title = __( 'Network Setup' );
107        $parent_file = 'settings.php';
108} else {
109        $title = __( 'Create a Network of WordPress Sites' );
110        $parent_file = 'tools.php';
111}
112
113$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>' .
114        '<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>' .
115        '<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>' .
116        '<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>' .
117        '<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>' .
118        '<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>' .
119        '<p><strong>' . __('For more information:') . '</strong></p>' .
120        '<p>' . __('<a href="http://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>') . '</p>' .
121        '<p>' . __('<a href="http://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>') . '</p>';
122
123get_current_screen()->add_help_tab( array(
124        'id'      => 'network',
125        'title'   => __('Network'),
126        'content' => $network_help,
127) );
128
129get_current_screen()->set_help_sidebar(
130        '<p><strong>' . __('For more information:') . '</strong></p>' .
131        '<p>' . __('<a href="http://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>') . '</p>' .
132        '<p>' . __('<a href="http://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>') . '</p>' .
133        '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
134);
135
136include( ABSPATH . 'wp-admin/admin-header.php' );
137?>
138<div class="wrap">
139<h2><?php echo esc_html( $title ); ?></h2>
140
141<?php
142/**
143 * Prints step 1 for Network installation process.
144 *
145 * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network
146 *      should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo.
147 *
148 * @since 3.0.0
149 */
150function network_step1( $errors = false ) {
151        global $is_apache;
152
153        if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
154                echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>';
155                echo '</div>';
156                include ( ABSPATH . 'wp-admin/admin-footer.php' );
157                die();
158        }
159
160        $active_plugins = get_option( 'active_plugins' );
161        if ( ! empty( $active_plugins ) ) {
162                echo '<div class="updated"><p><strong>' . __('Warning:') . '</strong> ' . sprintf( __( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ), admin_url( 'plugins.php?plugin_status=active' ) ) . '</p></div><p>' . __( 'Once the network is created, you may reactivate your plugins.' ) . '</p>';
163                echo '</div>';
164                include( ABSPATH . 'wp-admin/admin-footer.php' );
165                die();
166        }
167
168        $hostname = get_clean_basedomain();
169        $has_ports = strstr( $hostname, ':' );
170        if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
171                echo '<div class="error"><p><strong>' . __( 'ERROR:') . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
172                echo '<p>' . sprintf( __( 'You cannot use port numbers such as <code>%s</code>.' ), $has_ports ) . '</p>';
173                echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>';
174                echo '</div>';
175                include( ABSPATH . 'wp-admin/admin-footer.php' );
176                die();
177        }
178
179        echo '<form method="post" action="">';
180
181        wp_nonce_field( 'install-network-1' );
182
183        $error_codes = array();
184        if ( is_wp_error( $errors ) ) {
185                echo '<div class="error"><p><strong>' . __( 'ERROR: The network could not be created.' ) . '</strong></p>';
186                foreach ( $errors->get_error_messages() as $error )
187                        echo "<p>$error</p>";
188                echo '</div>';
189                $error_codes = $errors->get_error_codes();
190        }
191
192        $site_name = ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) ? $_POST['sitename'] : sprintf( _x('%s Sites', 'Default network name' ), get_option( 'blogname' ) );
193        $admin_email = ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) ? $_POST['email'] : get_option( 'admin_email' );
194        ?>
195        <p><?php _e( 'Welcome to the Network installation process!' ); ?></p>
196        <p><?php _e( 'Fill in the information below and you&#8217;ll be on your way to creating a network of WordPress sites. We will create configuration files in the next step.' ); ?></p>
197        <?php
198
199        if ( isset( $_POST['subdomain_install'] ) ) {
200                $subdomain_install = (bool) $_POST['subdomain_install'];
201        } elseif ( apache_mod_loaded('mod_rewrite') ) { // assume nothing
202                $subdomain_install = true;
203        } elseif ( !allow_subdirectory_install() ) {
204                $subdomain_install = true;
205        } else {
206                $subdomain_install = false;
207                if ( $got_mod_rewrite = got_mod_rewrite() ) // dangerous assumptions
208                        echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ' . __( 'Please make sure the Apache <code>mod_rewrite</code> module is installed as it will be used at the end of this installation.' ) . '</p>';
209                elseif ( $is_apache )
210                        echo '<div class="error inline"><p><strong>' . __( 'Warning!' ) . '</strong> ' . __( 'It looks like the Apache <code>mod_rewrite</code> module is not installed.' ) . '</p>';
211                if ( $got_mod_rewrite || $is_apache ) // Protect against mod_rewrite mimicry (but ! Apache)
212                        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></div>';
213        }
214
215        if ( allow_subdomain_install() && allow_subdirectory_install() ) : ?>
216                <h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
217                <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>
218                <p><?php _e( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?></p>
219                <?php // @todo: Link to an MS readme? ?>
220                <table class="form-table">
221                        <tr>
222                                <th><label><input type='radio' name='subdomain_install' value='1'<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
223                                <td><?php printf( _x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ), $hostname ); ?></td>
224                        </tr>
225                        <tr>
226                                <th><label><input type='radio' name='subdomain_install' value='0'<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
227                                <td><?php printf( _x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ), $hostname ); ?></td>
228                        </tr>
229                </table>
230
231<?php
232        endif;
233
234                if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) )
235                        echo '<div class="error inline"><p><strong>' . __('Warning!') . '</strong> ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
236
237                $is_www = ( 0 === strpos( $hostname, 'www.' ) );
238                if ( $is_www ) :
239                ?>
240                <h3><?php esc_html_e( 'Server Address' ); ?></h3>
241                <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>
242                <table class="form-table">
243                        <tr>
244                                <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
245                                <td>
246                                        <?php printf( __( 'The internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
247                                </td>
248                        </tr>
249                </table>
250                <?php endif; ?>
251
252                <h3><?php esc_html_e( 'Network Details' ); ?></h3>
253                <table class="form-table">
254                <?php if ( 'localhost' == $hostname ) : ?>
255                        <tr>
256                                <th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th>
257                                <td><?php
258                                        _e( 'Because you are using <code>localhost</code>, the sites in your WordPress network must use sub-directories. Consider using <code>localhost.localdomain</code> if you wish to use sub-domains.' );
259                                        // Uh oh:
260                                        if ( !allow_subdirectory_install() )
261                                                echo ' <strong>' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
262                                ?></td>
263                        </tr>
264                <?php elseif ( !allow_subdomain_install() ) : ?>
265                        <tr>
266                                <th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th>
267                                <td><?php
268                                        _e( 'Because your install is in a directory, the sites in your WordPress network must use sub-directories.' );
269                                        // Uh oh:
270                                        if ( !allow_subdirectory_install() )
271                                                echo ' <strong>' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
272                                ?></td>
273                        </tr>
274                <?php elseif ( !allow_subdirectory_install() ) : ?>
275                        <tr>
276                                <th scope="row"><?php esc_html_e( 'Sub-domain Install' ); ?></th>
277                                <td><?php _e( 'Because your install is not new, the sites in your WordPress network must use sub-domains.' );
278                                        echo ' <strong>' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
279                                ?></td>
280                        </tr>
281                <?php endif; ?>
282                <?php if ( ! $is_www ) : ?>
283                        <tr>
284                                <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
285                                <td>
286                                        <?php printf( __( 'The internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
287                                </td>
288                        </tr>
289                <?php endif; ?>
290                        <tr>
291                                <th scope='row'><?php esc_html_e( 'Network Title' ); ?></th>
292                                <td>
293                                        <input name='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' />
294                                        <p class="description">
295                                                <?php _e( 'What would you like to call your network?' ); ?>
296                                        </p>
297                                </td>
298                        </tr>
299                        <tr>
300                                <th scope='row'><?php esc_html_e( 'Network Admin Email' ); ?></th>
301                                <td>
302                                        <input name='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' />
303                                        <p class="description">
304                                                <?php _e( 'Your email address.' ); ?>
305                                        </p>
306                                </td>
307                        </tr>
308                </table>
309                <?php submit_button( __( 'Install' ), 'primary', 'submit' ); ?>
310        </form>
311        <?php
312}
313
314/**
315 * Prints step 2 for Network installation process.
316 *
317 * @since 3.0.0
318 */
319function network_step2( $errors = false ) {
320        global $wpdb;
321
322        $hostname          = get_clean_basedomain();
323        $slashed_home      = trailingslashit( get_option( 'home' ) );
324        $base              = parse_url( $slashed_home, PHP_URL_PATH );
325        $document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
326        $abspath_fix       = str_replace( '\\', '/', ABSPATH );
327        $home_path         = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
328        $wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
329        $rewrite_base      = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
330
331
332        $location_of_wp_config = $abspath_fix;
333        if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) )
334                $location_of_wp_config = trailingslashit( dirname( ABSPATH ) );
335
336        // Wildcard DNS message.
337        if ( is_wp_error( $errors ) )
338                echo '<div class="error">' . $errors->get_error_message() . '</div>';
339
340        if ( $_POST ) {
341                if ( allow_subdomain_install() )
342                        $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
343                else
344                        $subdomain_install = false;
345        } else {
346                if ( is_multisite() ) {
347                        $subdomain_install = is_subdomain_install();
348?>
349        <p><?php _e( 'The original configuration steps are shown here for reference.' ); ?></p>
350<?php
351                } else {
352                        $subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
353?>
354        <div class="error"><p><strong><?php _e('Warning:'); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
355        <p><?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p>
356<?php
357                }
358        }
359
360        $subdir_match          = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
361        $subdir_replacement_01 = $subdomain_install ? '' : '$1';
362        $subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
363
364        if ( $_POST || ! is_multisite() ) {
365?>
366                <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
367                <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
368                <div class="updated inline"><p><?php
369                        if ( file_exists( $home_path . '.htaccess' ) )
370                                printf( __( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), '.htaccess' );
371                        elseif ( file_exists( $home_path . 'web.config' ) )
372                                printf( __( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), 'web.config' );
373                        else
374                                _e( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> file.' );
375                ?></p></div>
376<?php
377        }
378?>
379                <ol>
380                        <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>
381                                <textarea class="code" readonly="readonly" cols="100" rows="6">
382define('MULTISITE', true);
383define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
384define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
385define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
386define('SITE_ID_CURRENT_SITE', 1);
387define('BLOG_ID_CURRENT_SITE', 1);</textarea>
388<?php
389        $keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
390        foreach ( $keys_salts as $c => $v ) {
391                if ( defined( $c ) )
392                        unset( $keys_salts[ $c ] );
393        }
394
395        if ( ! empty( $keys_salts ) ) {
396                $keys_salts_str = '';
397                $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
398                if ( is_wp_error( $from_api ) ) {
399                        foreach ( $keys_salts as $c => $v ) {
400                                $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
401                        }
402                } else {
403                        $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
404                        foreach ( $keys_salts as $c => $v ) {
405                                $keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
406                        }
407                }
408                $num_keys_salts = count( $keys_salts );
409?>
410        <p><?php
411                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>
412        <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
413<?php
414        }
415?>
416</li>
417<?php
418        if ( iis7_supports_permalinks() ) :
419                // IIS doesn't support RewriteBase, all your RewriteBase are belong to us
420                $iis_subdir_match = ltrim( $base, '/' ) . $subdir_match;
421                $iis_rewrite_base = ltrim( $base, '/' ) . $rewrite_base;
422                $iis_subdir_replacement = $subdomain_install ? '' : '{R:1}';
423
424                $web_config_file = '<?xml version="1.0" encoding="UTF-8"?>
425<configuration>
426    <system.webServer>
427        <rewrite>
428            <rules>
429                <rule name="WordPress Rule 1" stopProcessing="true">
430                    <match url="^index\.php$" ignoreCase="false" />
431                    <action type="None" />
432                </rule>';
433                                if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
434                                        $web_config_file .= '
435                <rule name="WordPress Rule for Files" stopProcessing="true">
436                    <match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" />
437                    <action type="Rewrite" url="' . $iis_rewrite_base . 'wp-includes/ms-files.php?file={R:1}" appendQueryString="false" />
438                </rule>';
439                }
440                $web_config_file .= '
441                <rule name="WordPress Rule 2" stopProcessing="true">
442                    <match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" />
443                    <action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" />
444                </rule>
445                <rule name="WordPress Rule 3" stopProcessing="true">
446                    <match url="^" ignoreCase="false" />
447                    <conditions logicalGrouping="MatchAny">
448                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
449                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
450                    </conditions>
451                    <action type="None" />
452                </rule>
453                <rule name="WordPress Rule 4" stopProcessing="true">
454                    <match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" />
455                    <action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" />
456                </rule>
457                <rule name="WordPress Rule 5" stopProcessing="true">
458                    <match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
459                    <action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" />
460                </rule>
461                <rule name="WordPress Rule 6" stopProcessing="true">
462                    <match url="." ignoreCase="false" />
463                    <action type="Rewrite" url="index.php" />
464                </rule>
465            </rules>
466        </rewrite>
467    </system.webServer>
468</configuration>';
469
470        ?>
471                <li><p><?php printf( __( 'Add the following to your <code>web.config</code> file in <code>%s</code>, replacing other WordPress rules:' ), $home_path ); ?></p>
472                <?php
473                if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
474                        echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
475                ?>
476                <textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea( $web_config_file ); ?>
477                </textarea></li>
478                </ol>
479
480        <?php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
481
482                $ms_files_rewriting = '';
483                if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
484                        $ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
485                        $ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}wp-includes/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
486                }
487
488                $htaccess_file = <<<EOF
489RewriteEngine On
490RewriteBase {$base}
491RewriteRule ^index\.php$ - [L]
492{$ms_files_rewriting}
493# add a trailing slash to /wp-admin
494RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L]
495
496RewriteCond %{REQUEST_FILENAME} -f [OR]
497RewriteCond %{REQUEST_FILENAME} -d
498RewriteRule ^ - [L]
499RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
500RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L]
501RewriteRule . index.php [L]
502EOF;
503
504                ?>
505                <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), $home_path ); ?></p>
506                <?php
507                if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
508                        echo '<p><strong>' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>';
509                ?>
510                <textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count( $htaccess_file, "\n" ) + 1; ?>">
511<?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
512                </ol>
513
514        <?php endif; // end IIS/Apache code branches.
515
516        if ( !is_multisite() ) { ?>
517                <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>
518<?php
519        }
520}
521
522if ( $_POST ) {
523
524        check_admin_referer( 'install-network-1' );
525
526        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
527        // create network tables
528        install_network();
529        $base              = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
530        $subdomain_install = allow_subdomain_install() ? !empty( $_POST['subdomain_install'] ) : false;
531        if ( ! network_domain_check() ) {
532                $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), wp_unslash( $_POST['sitename'] ), $base, $subdomain_install );
533                if ( is_wp_error( $result ) ) {
534                        if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() )
535                                network_step2( $result );
536                        else
537                                network_step1( $result );
538                } else {
539                        network_step2();
540                }
541        } else {
542                network_step2();
543        }
544} elseif ( is_multisite() || network_domain_check() ) {
545        network_step2();
546} else {
547        network_step1();
548}
549?>
550</div>
551
552<?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>