X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/fef8173b8c3bad08f495551e43cfdeac1cae6021..ac7339a398e6df50f722bc9616291ce5447d8e5e:/wp-admin/network.php diff --git a/wp-admin/network.php b/wp-admin/network.php index 6a9aca33..fdc0a51b 100644 --- a/wp-admin/network.php +++ b/wp-admin/network.php @@ -10,10 +10,10 @@ * @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,23 +113,32 @@ if ( is_network_admin() ) { $parent_file = 'tools.php'; } -add_contextual_help($current_screen, - '

' . __('This screen allows you to configure a network as having subdomains (site1.example.com) or subdirectories (example.com/site1). Subdomains require wildcard subdomains to be enabled in Apache and DNS records, if your host allows it.') . '

' . +$network_help = '

' . __('This screen allows you to configure a network as having subdomains (site1.example.com) or subdirectories (example.com/site1). Subdomains require wildcard subdomains to be enabled in Apache and DNS records, if your host allows it.') . '

' . '

' . __('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).') . '

' . - '

' . __('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.') . '

' . - '

' . __('Add a blogs.dir directory under /wp-content and add the designated lines of code to wp-config.php (just before /*...stop editing...*/) and .htaccess (replacing the existing WordPress rules).') . '

' . - '

' . __('Refreshing your browser will take you to a screen with an archive of those added lines of code. A set of six links under Super Admin will appear at the top of the main left navigation menu. The multisite network is now enabled.') . '

' . - '

' . __('The choice of subdirectory sites is disabled if this setup is more than a month old because of permalink problems with “/blog/” from the main site. This disabling will be addressed soon in a future version.') . '

' . + '

' . __('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.') . '

' . + '

' . __('Add the designated lines of code to wp-config.php (just before /*...stop editing...*/) and .htaccess (replacing the existing WordPress rules).') . '

' . + '

' . __('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.') . '

' . + '

' . __('The choice of subdirectory sites is disabled if this setup is more than a month old because of permalink problems with “/blog/” from the main site. This disabling will be addressed in a future version.') . '

' . + '

' . __('For more information:') . '

' . + '

' . __('Documentation on Creating a Network') . '

' . + '

' . __('Documentation on the Network Screen') . '

'; + +get_current_screen()->add_help_tab( array( + 'id' => 'network', + 'title' => __('Network'), + 'content' => $network_help, +) ); + +get_current_screen()->set_help_sidebar( '

' . __('For more information:') . '

' . - '

' . __('Documentation on Creating a Network') . '

' . - '

' . __('Documentation on the Network Screen') . '

' . - '

' . __('Support Forums') . '

' + '

' . __('Documentation on Creating a Network') . '

' . + '

' . __('Documentation on the Network Screen') . '

' . + '

' . __('Support Forums') . '

' ); include( ABSPATH . 'wp-admin/admin-header.php' ); ?>
-

' . __('Error:') . ' ' . sprintf( __( 'Your WordPress address must match your Site address before creating a Network. See General Settings.' ), esc_url( admin_url( 'options-general.php' ) ) ) . '

'; - echo ''; - include ( ABSPATH . 'wp-admin/admin-footer.php' ); - die(); - } - if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) { - echo '

' . __('Error:') . ' ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '

'; + echo '

' . __('ERROR:') . ' ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '

'; echo ''; - include ( ABSPATH . 'wp-admin/admin-footer.php' ); + include( ABSPATH . 'wp-admin/admin-footer.php' ); die(); } @@ -159,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 '

' . __( 'Error:') . ' ' . __( 'You cannot install a network of sites with your server address.' ) . '

'; + echo '

' . __( 'ERROR:') . ' ' . __( 'You cannot install a network of sites with your server address.' ) . '

'; echo '

' . sprintf( __( 'You cannot use port numbers such as %s.' ), $has_ports ) . '

'; echo '' . __( 'Return to Dashboard' ) . ''; echo ''; @@ -167,7 +179,7 @@ function network_step1( $errors = false ) { die(); } - echo '
'; + echo ''; wp_nonce_field( 'install-network-1' ); @@ -180,9 +192,6 @@ function network_step1( $errors = false ) { $error_codes = $errors->get_error_codes(); } - if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' ) - echo '

' . __('Warning!') . ' ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '

'; - $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' ); ?> @@ -213,23 +222,34 @@ function network_step1( $errors = false ) { - - + + - - + +
site1.%1$s and site2.%1$s', 'subdomain examples' ), $hostname ); ?>site1.%1$s and site2.%1$s', 'subdomain examples' ), + $hostname + ); ?>
%1$s/site1 and %1$s/site2', 'subdirectory examples' ), $hostname ); ?>%1$s/site1 and %1$s/site2', 'subdirectory examples' ), + $hostname + ); ?>

' . __('Warning!') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

'; + $is_www = ( 0 === strpos( $hostname, 'www.' ) ); if ( $is_www ) : ?>

-

%1$s before enabling the network feature. It will still be possible to visit your site using the www prefix with an address like %2$s but any links will not have the www prefix.' ), substr( $hostname, 4 ), $hostname ); ?> +

%1$s before enabling the network feature. It will still be possible to visit your site using the www prefix with an address like %2$s but any links will not have the www prefix.' ), substr( $hostname, 4 ), $hostname ); ?>

@@ -282,14 +302,18 @@ function network_step1( $errors = false ) { - +
-
+

+ +

-
+

+ +

@@ -304,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 ) ) @@ -334,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() ) { ?>

Caution: We recommend you back up your existing wp-config.php and %s files.' ), '.htaccess' ); - elseif ( file_exists( ABSPATH . 'web.config' ) ) + elseif ( file_exists( $home_path . 'web.config' ) ) printf( __( 'Caution: We recommend you back up your existing wp-config.php and %s files.' ), 'web.config' ); else _e( 'Caution: We recommend you back up your existing wp-config.php file.' ); @@ -350,26 +390,22 @@ function network_step2( $errors = false ) { } ?>

    -
  1. blogs.dir directory at %s/blogs.dir. 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 ' ' . __('Warning:') . ' ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '

  2. -
  3. wp-config.php file in %s above the line reading /* That’s all, stop editing! Happy blogging. */:' ), ABSPATH ); ?>

    +
  4. wp-config.php file in %s above the line reading /* That’s all, stop editing! Happy blogging. */:' ), $location_of_wp_config ); ?>

    +define('MULTISITE', true); +define('SUBDOMAIN_INSTALL', ); +define('DOMAIN_CURRENT_SITE', ''); +define('PATH_CURRENT_SITE', ''); +define('SITE_ID_CURRENT_SITE', 1); +define('BLOG_ID_CURRENT_SITE', 1); + '', '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/' ); @@ -385,8 +421,16 @@ define( 'BLOG_ID_CURRENT_SITE', 1 ); } $num_keys_salts = count( $keys_salts ); ?> -

    wp-config.php file.', 'These unique authentication keys are also missing from your wp-config.php file.', $num_keys_salts ); ?>

    +

    + wp-config.php file.' ); + } else { + _e( 'These unique authentication keys are also missing from your wp-config.php file.' ); + } + ?> + +

  5. + $web_config_file = ' @@ -405,10 +451,18 @@ define( 'BLOG_ID_CURRENT_SITE', 1 ); - + '; + if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) { + $web_config_file .= ' + + + + '; + } + $web_config_file .= ' - - + + @@ -419,113 +473,91 @@ define( 'BLOG_ID_CURRENT_SITE', 1 ); - - - - - - -'; - } else { - $web_config_file = -' - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - -'; - } - ?> -
  6. web.config file in %s, replacing other WordPress rules:' ), ABSPATH ); ?>

    -

'; + /* translators: 1: a filename like .htaccess. 2: a file path. */ + printf( __( 'Add the following to your %1$s file in %2$s, replacing other WordPress rules:' ), + '.htaccess', '' . $home_path . '' ); + echo '

'; + if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) + echo '

' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

'; ?> -
  • .htaccess file in %s, replacing other WordPress rules:' ), ABSPATH ); ?>

    -
  • -

    +

    get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() ) network_step2( $result );