More network.php refinements. Bring wp-config and htaccess inline. Rename BLOGID_CURRENT_SITE to BLOG_ID_CURRENT_SITE for consistency with SITE_ID_CURRENT_SITE. see #11816

git-svn-id: http://svn.automattic.com/wordpress/trunk@13611 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-03-06 20:01:32 +00:00
parent f210aed76d
commit a2aad1bb00
2 changed files with 39 additions and 91 deletions

View File

@ -89,7 +89,6 @@ function network_step1() {
<p class="existing-network"> <p class="existing-network">
<label><input type='checkbox' name='existing_network' value='1' /> <?php _e( 'Yes, keep the existing network of sites.' ); ?></label><br /> <label><input type='checkbox' name='existing_network' value='1' /> <?php _e( 'Yes, keep the existing network of sites.' ); ?></label><br />
</p> </p>
<?php } else { ?> <?php } else { ?>
<input type='hidden' name='existing_network' value='0' /> <input type='hidden' name='existing_network' value='0' />
<?php } ?> <?php } ?>
@ -105,11 +104,11 @@ function network_step1() {
<table class="form-table"> <table class="form-table">
<tr> <tr>
<th><label><input type='radio' name='vhost' value='yes'<?php checked( $rewrite_enabled ); ?> /> Sub-domains</label></th> <th><label><input type='radio' name='vhost' value='yes'<?php checked( $rewrite_enabled ); ?> /> Sub-domains</label></th>
<td><?php _e('like <code>blog1.example.com</code> and <code>blog2.example.com</code>'); ?></td> <td><?php _e('like <code>site1.example.com</code> and <code>site2.example.com</code>'); ?></td>
</tr> </tr>
<tr> <tr>
<th><label><input type='radio' name='vhost' value='no'<?php checked( ! $rewrite_enabled ); ?> /> Sub-directories</label></th> <th><label><input type='radio' name='vhost' value='no'<?php checked( ! $rewrite_enabled ); ?> /> Sub-directories</label></th>
<td><?php _e('like <code>example.com/blog1</code> and <code>example.com/blog2</code>'); ?></td> <td><?php _e('like <code>example.com/site1</code> and <code>example.com/site2</code>'); ?></td>
</tr> </tr>
</table> </table>
@ -168,101 +167,48 @@ function network_step2() {
global $base, $wpdb; global $base, $wpdb;
?> ?>
<h3><?php esc_html_e( 'Enabling the Network' ); ?></h3> <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. <strong>Note:</strong> We recommend you make a backup copy of your existing <code>wp-config.php</code> and <code>.htaccess</code> files.' ); ?></p> <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
<div class="updated inline"><p><?php _e( '<strong>Caution:</strong> We recommend you backup your existing <code>wp-config.php</code> and <code>.htaccess</code> files.' ); ?></p></div>
<ol> <ol>
<li><?php printf( __( 'Create a <code>%s/blogs.dir</code> directory. This directory is used to stored uploaded media for your additional sites and must be writeable by the web server.' ), WP_CONTENT_DIR ); ?></li> <li><p><?php printf( __( 'Create a <code>blogs.dir</code> directory in <code>%s</code>. This directory is used to stored uploaded media for your additional sites and must be writeable by the web server.' ), WP_CONTENT_DIR ); ?></p></li>
<?php <li><p><?php printf( __( 'Add the following to your <code>wp-config.php</code> file in <code>%s</code>:' ), ABSPATH ); ?></p>
$vhost = stripslashes( $_POST['vhost' ] ); <textarea class="code" readonly="readonly" cols="100" rows="7">
$prefix = $wpdb->base_prefix; define( 'MULTISITE', true );
define( 'VHOST', '<?php echo 'yes' == stripslashes( $_POST['vhost'] ) ? 'yes' : 'no'; ?>' );
$config_sample = ABSPATH . 'wp-admin/includes/wp-config.ms'; $base = '<?php echo $base; ?>';
if ( ! file_exists( $config_sample ) ) define( 'DOMAIN_CURRENT_SITE', '<?php echo get_clean_basedomain(); ?>' );
wp_die( sprintf( __( 'Sorry, I need a <code>%s</code> to work from. Please re-upload this file to your WordPress installation.' ), $config_sample ) ); define( 'PATH_CURRENT_SITE', '<?php echo $base; ?>' );
define( 'SITE_ID_CURRENT_SITE', 1 );
$wp_config_file = file( $config_sample ); define( 'BLOG_ID_CURRENT_SITE', 1 );</textarea></li>
?>
<li><p><?php printf( __( 'Replace the contents of <code>%swp-config.php</code> with the following:' ), ABSPATH ); ?></p>
<textarea name="wp-config" cols="120" rows="20">
<?php
foreach ( $wp_config_file as $line ) {
switch ( trim( substr( $line, 0, 16 ) ) ) {
case "define('DB_NAME'":
$output = str_replace( "wordpress", DB_NAME, $line );
break;
case "define('DB_USER'":
$output = str_replace( "username", DB_USER, $line );
break;
case "define('DB_PASSW":
$output = str_replace( "password", DB_PASSWORD, $line );
break;
case "define('DB_HOST'":
$output = str_replace( "localhost", DB_HOST, $line );
break;
case "define('VHOST',":
$output = str_replace( "VHOSTSETTING", $vhost, $line );
break;
case '$table_prefix =':
$output = str_replace( 'wp_', $prefix, $line );
break;
case '$base = \'BASE\';':
$output = str_replace( 'BASE', $base, $line );
break;
case "define('DOMAIN_C":
$domain = get_clean_basedomain();
$output = str_replace( "current_site_domain", $domain, $line );
break;
case "define('PATH_CUR":
$output = str_replace( "current_site_path", $base, $line );
break;
case "define('AUTH_KEY":
case "define('AUTH_SAL":
case "define('LOGGED_I":
case "define('SECURE_A":
case "define('NONCE_KE":
$constant = substr( $line, 8, strpos( $line, "'", 9 ) - 8 );
if ( defined( $constant ) )
$hash = constant( $constant );
else
$hash = md5( mt_rand() ) . md5( mt_rand() );
$output = str_replace( 'put your unique phrase here', $hash, $line );
break;
default:
$output = $line;
break;
}
echo $output;
}
?>
</textarea>
</li>
<?php <?php
// remove ending slash from $base and $url // remove ending slash from $base and $url
$htaccess = ''; $htaccess = '';
if ( substr( $base, -1 ) == '/' ) $base = rtrim( $base, '/' );
$base = substr( $base, 0, -1 );
$htaccess_sample = ABSPATH . 'wp-admin/includes/htaccess.ms'; $htaccess_file = 'RewriteEngine On
if ( ! file_exists( $htaccess_sample ) ) RewriteBase ' . $base . '/
wp_die( sprintf( __( 'Sorry, I need a %s to work from. Please re-upload this file to your WordPress installation.' ), $htaccess_sample ) );
$htaccess_file = file( $htaccess_sample ); #uploaded files
$fp = @fopen( $htaccess_sample, "r" ); RewriteRule ^(.*/)?files/$ index.php [L]
if ( $fp ) { RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
while ( ! feof( $fp ) ) { RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]
$htaccess .= fgets( $fp, 4096 );
} # add a trailing slash to /wp-admin
fclose( $fp ); RewriteCond %{REQUEST_URI} ^.*/wp-admin$
$htaccess_file = str_replace( "BASE", $base, $htaccess ); RewriteRule ^(.+)$ $1/ [R=301,L]
} else {
wp_die( sprintf( __( 'Sorry, I need to be able to read %s. Please check the permissions on this file.' ), $htaccess_sample ) ); RewriteCond %{REQUEST_FILENAME} -f [OR]
} RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]';
?> ?>
<li><p><?php printf( __( 'Replace the contents of your <code>%s.htaccess</code> with the following:' ), ABSPATH ); ?></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 name="htaccess" cols="120" rows="20"> <textarea class="code" readonly="readonly" cols="100" rows="18">
<?php echo wp_htmledit_pre( $htaccess_file ); ?> <?php echo wp_htmledit_pre( $htaccess_file ); ?>
</textarea> </textarea></li>
</li>
</ol> </ol>
<?php <?php
} }
@ -279,7 +225,7 @@ switch ( $action ) {
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
// create network tables // create network tables
install_network(); install_network();
if ( !network_domain_check() || $_POST['existing_network'] == '0' ) if ( !network_domain_check() || isset( $_POST['existing_network'] ) && $_POST['existing_network'] == '0' )
populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), $_POST['weblog_title'], $base, $_POST['vhost'] ); populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), $_POST['weblog_title'], $base, $_POST['vhost'] );
// create wp-config.php / htaccess // create wp-config.php / htaccess
network_step2(); network_step2();

View File

@ -101,7 +101,9 @@ function wpmu_current_site() {
$current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1; $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
$current_site->domain = DOMAIN_CURRENT_SITE; $current_site->domain = DOMAIN_CURRENT_SITE;
$current_site->path = $path = PATH_CURRENT_SITE; $current_site->path = $path = PATH_CURRENT_SITE;
if ( defined( 'BLOGID_CURRENT_SITE' ) ) if ( defined( 'BLOG_ID_CURRENT_SITE' ) )
$current_site->blog_id = BLOG_ID_CURRENT_SITE;
elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.
$current_site->blog_id = BLOGID_CURRENT_SITE; $current_site->blog_id = BLOGID_CURRENT_SITE;
if ( DOMAIN_CURRENT_SITE == $domain ) if ( DOMAIN_CURRENT_SITE == $domain )
$current_site->cookie_domain = $cookie_domain; $current_site->cookie_domain = $cookie_domain;