From dc49f24a6c5dc97d7f30656a6aaac4e9a9b94116 Mon Sep 17 00:00:00 2001
From: Andrew Nacin
Date: Tue, 11 Sep 2012 22:22:20 +0000
Subject: [PATCH] Remove ms-files.php rewriting from WordPress multisite. fixes
#19235.
Keep existing networks compatible with a ms_files_rewriting network option.
git-svn-id: http://core.svn.wordpress.org/trunk@21823 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
wp-admin/includes/ms-deprecated.php | 4 +-
wp-admin/includes/ms.php | 18 +++----
wp-admin/includes/schema.php | 6 +--
wp-admin/includes/upgrade.php | 4 ++
wp-admin/network.php | 70 ++++++++++++++++------------
wp-includes/functions.php | 36 +++++++-------
wp-includes/ms-default-constants.php | 15 ++++--
wp-includes/ms-default-filters.php | 3 ++
wp-includes/ms-functions.php | 36 +++++++-------
wp-includes/option.php | 2 +-
wp-includes/rewrite.php | 38 +++++++++------
wp-includes/version.php | 2 +-
12 files changed, 132 insertions(+), 102 deletions(-)
diff --git a/wp-admin/includes/ms-deprecated.php b/wp-admin/includes/ms-deprecated.php
index 7119018b1f..702e3e13cf 100644
--- a/wp-admin/includes/ms-deprecated.php
+++ b/wp-admin/includes/ms-deprecated.php
@@ -73,4 +73,6 @@ function get_site_allowed_themes() {
function wpmu_get_blog_allowedthemes( $blog_id = 0 ) {
_deprecated_function( __FUNCTION__, '3.4', 'WP_Theme::get_allowed_on_site()' );
return array_map( 'intval', WP_Theme::get_allowed_on_site( $blog_id ) );
-}
\ No newline at end of file
+}
+
+function ms_deprecated_blogs_file() {}
\ No newline at end of file
diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php
index c7d5faeb52..e407010ada 100644
--- a/wp-admin/includes/ms.php
+++ b/wp-admin/includes/ms.php
@@ -90,7 +90,8 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
$wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
- $dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
+ $uploads = wp_upload_dir();
+ $dir = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $blog_id );
$dir = rtrim( $dir, DIRECTORY_SEPARATOR );
$top_dir = $dir;
$stack = array($dir);
@@ -357,8 +358,10 @@ function upload_is_user_over_quota( $echo = true ) {
function get_space_used() {
// Allow for an alternative way of tracking storage space used
$space_used = apply_filters( 'pre_get_space_used', false );
- if ( false === $space_used )
- $space_used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;
+ if ( false === $space_used ) {
+ $upload_dir = wp_upload_dir();
+ $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024;
+ }
return $space_used;
}
@@ -682,15 +685,6 @@ function choose_primary_blog() {
' . sprintf( __( 'The %1$s
file is deprecated. Please remove it and update your server rewrite rules to use %2$s
instead.' ), 'wp-content/blogs.php', 'wp-includes/ms-files.php' ) . '';
-}
-add_action( 'network_admin_notices', 'ms_deprecated_blogs_file' );
-
/**
* Grants super admin privileges.
*
diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php
index 4926ed302b..0b9e6a4dcf 100644
--- a/wp-admin/includes/schema.php
+++ b/wp-admin/includes/schema.php
@@ -912,6 +912,7 @@ We hope you enjoy your new site. Thanks!
'upload_space_check_disabled' => '0',
'subdomain_install' => intval( $subdomain_install ),
'global_terms_enabled' => global_terms_enabled() ? '1' : '0',
+ 'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
'initial_db_version' => get_option( 'initial_db_version' ),
'active_sitewide_plugins' => array(),
);
@@ -940,11 +941,6 @@ We hope you enjoy your new site. Thanks!
$blog_id = $wpdb->insert_id;
update_user_meta( $site_user->ID, 'source_domain', $domain );
update_user_meta( $site_user->ID, 'primary_blog', $blog_id );
- if ( !$upload_path = get_option( 'upload_path' ) ) {
- $upload_path = substr( WP_CONTENT_DIR, strlen( ABSPATH ) ) . '/uploads';
- update_option( 'upload_path', $upload_path );
- }
- update_option( 'fileupload_url', get_option( 'siteurl' ) . '/' . $upload_path );
}
if ( $subdomain_install )
diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php
index 2369cd96b8..4b85017bfa 100644
--- a/wp-admin/includes/upgrade.php
+++ b/wp-admin/includes/upgrade.php
@@ -1271,6 +1271,10 @@ function upgrade_network() {
delete_site_option( 'allowed_themes' );
}
}
+
+ // 3.5
+ if ( $wp_current_db_version < 21823 )
+ update_site_option( 'ms_files_rewriting', '1' );
}
// The functions we use to actually do stuff
diff --git a/wp-admin/network.php b/wp-admin/network.php
index 2931cbbc82..af70da2704 100644
--- a/wp-admin/network.php
+++ b/wp-admin/network.php
@@ -106,7 +106,7 @@ if ( is_network_admin() ) {
$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 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 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).') . '
' .
+ '' . __('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:') . '
' .
@@ -190,9 +190,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' );
?>
@@ -235,6 +232,9 @@ function network_step1( $errors = false ) {
' . __('Warning!') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '
';
+
$is_www = ( 0 === strpos( $hostname, 'www.' ) );
if ( $is_www ) :
?>
@@ -360,11 +360,6 @@ function network_step2( $errors = false ) {
}
?>
- 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.' ) . '';
- ?>
wp-config.php file in %s
above the line reading /* That’s all, stop editing! Happy blogging. */
:' ), ABSPATH ); ?>
-
-
+ ';
+ if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
+ $web_config_file .= '
+
-
-
+ ';
+ }
+ $web_config_file .= '
+
@@ -428,7 +427,7 @@ define('BLOG_ID_CURRENT_SITE', 1);
-
+
@@ -446,16 +445,20 @@ define('BLOG_ID_CURRENT_SITE', 1);
-
+ ';
+ if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
+ $web_config_file .= '
+
+
+
+ ';
+ }
+ $web_config_file .= '
-
-
-
-
-
+
@@ -463,15 +466,15 @@ define('BLOG_ID_CURRENT_SITE', 1);
-
+
-
+
-
+
@@ -482,8 +485,11 @@ define('BLOG_ID_CURRENT_SITE', 1);
}
?>
web.config file in %s
, replacing other WordPress rules:' ), ABSPATH ); ?>
-
';
+ ?>
+
@@ -491,10 +497,12 @@ define('BLOG_ID_CURRENT_SITE', 1);
$htaccess_file = 'RewriteEngine On
RewriteBase ' . $base . '
-RewriteRule ^index\.php$ - [L]
+RewriteRule ^index\.php$ - [L]' . "\n";
-# uploaded files
-RewriteRule ^' . ( $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $subdomain_install ? 1 : 2 ) . ' [L]' . "\n";
+ if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
+ $htaccess_file .= "\n# uploaded files\nRewriteRule ^";
+ $htaccess_file .= ( $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $subdomain_install ? 1 : 2 ) . ' [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";
@@ -511,7 +519,11 @@ RewriteRule ^ - [L]';
?>
.htaccess file in %s
, replacing other WordPress rules:' ), ABSPATH ); ?>
-
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index 8f07d4f0dc..a39c4dbb71 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -1432,21 +1432,16 @@ function get_temp_dir() {
* @return array See above for description.
*/
function wp_upload_dir( $time = null ) {
- global $_wp_switched;
$siteurl = get_option( 'siteurl' );
- $upload_path = get_option( 'upload_path' );
- $upload_path = trim($upload_path);
- $main_override = is_multisite() && defined( 'MULTISITE' ) && is_main_site();
- if ( empty($upload_path) ) {
+ $upload_path = trim( get_option( 'upload_path' ) );
+
+ if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
$dir = WP_CONTENT_DIR . '/uploads';
+ } elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
+ // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
+ $dir = path_join( ABSPATH, $upload_path );
} else {
$dir = $upload_path;
- if ( 'wp-content/uploads' == $upload_path ) {
- $dir = WP_CONTENT_DIR . '/uploads';
- } elseif ( 0 !== strpos($dir, ABSPATH) ) {
- // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
- $dir = path_join( ABSPATH, $dir );
- }
}
if ( !$url = get_option( 'upload_url_path' ) ) {
@@ -1456,15 +1451,24 @@ function wp_upload_dir( $time = null ) {
$url = trailingslashit( $siteurl ) . $upload_path;
}
- if ( defined('UPLOADS') && ! $main_override && ! $_wp_switched ) {
+ if ( defined( 'UPLOADS' ) ) {
$dir = ABSPATH . UPLOADS;
$url = trailingslashit( $siteurl ) . UPLOADS;
}
- if ( is_multisite() && ! $main_override && ! $_wp_switched ) {
- if ( defined( 'BLOGUPLOADDIR' ) )
- $dir = untrailingslashit(BLOGUPLOADDIR);
- $url = str_replace( UPLOADS, 'files', $url );
+ // Multisite (if not the main site in a post-MU network)
+ if ( is_multisite() && ! ( is_main_site() && defined( 'MULTISITE' ) ) ) {
+ if ( ! get_site_option( 'ms_files_rewriting' ) ) {
+ // Append sites/%d if we're not on the main site (for post-MU networks).
+ $ms_dir = '/sites/' . get_current_blog_id();
+ $dir .= $ms_dir;
+ $url .= $ms_dir;
+ } elseif ( ! ms_is_switched() ) {
+ // Handle the old-form ms-files.php rewriting if the network still has that enabled.
+ if ( defined( 'BLOGUPLOADDIR' ) )
+ $dir = untrailingslashit( BLOGUPLOADDIR );
+ $url = str_replace( UPLOADS, 'files', $url );
+ }
}
$basedir = $dir;
diff --git a/wp-includes/ms-default-constants.php b/wp-includes/ms-default-constants.php
index cc341b140c..ed48318ccf 100644
--- a/wp-includes/ms-default-constants.php
+++ b/wp-includes/ms-default-constants.php
@@ -10,11 +10,17 @@
/**
* Defines Multisite upload constants.
*
+ * Exists for backward compatibility with legacy file-serving through
+ * wp-includes/ms-files.php (wp-content/blogs.php in MU).
+ *
* @since 3.0.0
*/
-function ms_upload_constants( ) {
+function ms_upload_constants() {
global $wpdb;
+ if ( ! get_site_option( 'ms_files_rewriting' ) )
+ return;
+
/** @since 3.0.0 */
// Base uploads dir relative to ABSPATH
if ( !defined( 'UPLOADBLOGSDIR' ) )
@@ -24,7 +30,7 @@ function ms_upload_constants( ) {
if ( !defined( 'UPLOADS' ) ) {
// Uploads dir relative to ABSPATH
define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" );
- if ( 'wp-content/blogs.dir' == UPLOADBLOGSDIR )
+ if ( 'wp-content/blogs.dir' == UPLOADBLOGSDIR && ! defined( 'BLOGUPLOADDIR' ) )
define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" );
}
}
@@ -74,9 +80,12 @@ function ms_cookie_constants( ) {
/**
* Defines Multisite file constants.
*
+ * Exists for backward compatibility with legacy file-serving through
+ * wp-includes/ms-files.php (wp-content/blogs.php in MU).
+ *
* @since 3.0.0
*/
-function ms_file_constants( ) {
+function ms_file_constants() {
/**
* Optional support for X-Sendfile header
* @since 3.0.0
diff --git a/wp-includes/ms-default-filters.php b/wp-includes/ms-default-filters.php
index 45410143d6..34dc151c44 100644
--- a/wp-includes/ms-default-filters.php
+++ b/wp-includes/ms-default-filters.php
@@ -61,3 +61,6 @@ add_filter( 'force_filtered_html_on_import', '__return_true' );
// WP_HOME and WP_SITEURL should not have any effect in MS
remove_filter( 'option_siteurl', '_config_wp_siteurl' );
remove_filter( 'option_home', '_config_wp_home' );
+
+// If the network upgrade hasn't run yet, assume ms-files.php rewriting is used.
+add_filter( 'default_site_option_ms_files_rewriting', '__return_true' );
\ No newline at end of file
diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php
index dd70f9f9d3..a87afa233f 100644
--- a/wp-includes/ms-functions.php
+++ b/wp-includes/ms-functions.php
@@ -1120,8 +1120,7 @@ function insert_blog($domain, $path, $site_id) {
* @param string $blog_title The title of the new site.
*/
function install_blog($blog_id, $blog_title = '') {
- global $wpdb, $table_prefix, $wp_roles;
- $wpdb->suppress_errors();
+ global $wpdb, $wp_roles, $current_site;
// Cast for security
$blog_id = (int) $blog_id;
@@ -1129,11 +1128,9 @@ function install_blog($blog_id, $blog_title = '') {
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
if ( $wpdb->get_results("SELECT ID FROM $wpdb->posts") )
- die(__('Already Installed
You appear to have already installed WordPress. To reinstall please clear your old database tables first.
') . '