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