merge in multisite login, wp-includes, See #11644

git-svn-id: http://svn.automattic.com/wordpress/trunk@12697 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
wpmuguru 2010-01-11 21:49:40 +00:00
parent fd5266e0a9
commit 7b64248bc8
8 changed files with 166 additions and 50 deletions

View File

@ -269,7 +269,21 @@ function wp_list_authors($args = '') {
$return = ''; $return = '';
/** @todo Move select to get_authors(). */ /** @todo Move select to get_authors(). */
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name"); if( is_multisite() ) {
$users = get_users_of_blog();
$author_ids = array();
foreach ( (array) $users as $user ) {
$author_ids[] = $user->user_id;
}
if ( count($author_ids) > 0 ) {
$author_ids=implode(',', $author_ids );
$authors = $wpdb->get_results( "SELECT ID, user_nicename from $wpdb->users WHERE ID IN($author_ids) " . ($exclude_admin ? "AND user_login <> 'admin' " : '') . "ORDER BY display_name" );
} else {
$authors = array();
}
} else {
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
}
$author_count = array(); $author_count = array();
foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row) { foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row) {

View File

@ -987,6 +987,9 @@ function map_meta_cap( $cap, $user_id ) {
function current_user_can( $capability ) { function current_user_can( $capability ) {
$current_user = wp_get_current_user(); $current_user = wp_get_current_user();
if( is_multisite() && is_super_admin() )
return true;
if ( empty( $current_user ) ) if ( empty( $current_user ) )
return false; return false;

View File

@ -327,9 +327,13 @@ function get_option( $setting, $default = false ) {
return $pre; return $pre;
// prevent non-existent options from triggering multiple queries // prevent non-existent options from triggering multiple queries
$notoptions = wp_cache_get( 'notoptions', 'options' ); if ( defined( 'WP_INSTALLING' ) && is_multisite() ) {
if ( isset( $notoptions[$setting] ) ) $notoptions = array();
return $default; } else {
$notoptions = wp_cache_get( 'notoptions', 'options' );
if ( isset( $notoptions[$setting] ) )
return $default;
}
$alloptions = wp_load_alloptions(); $alloptions = wp_load_alloptions();
@ -411,7 +415,8 @@ function form_option( $option ) {
function wp_load_alloptions() { function wp_load_alloptions() {
global $wpdb; global $wpdb;
$alloptions = wp_cache_get( 'alloptions', 'options' ); if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( !$alloptions ) { if ( !$alloptions ) {
$suppress = $wpdb->suppress_errors(); $suppress = $wpdb->suppress_errors();
@ -421,7 +426,8 @@ function wp_load_alloptions() {
$alloptions = array(); $alloptions = array();
foreach ( (array) $alloptions_db as $o ) foreach ( (array) $alloptions_db as $o )
$alloptions[$o->option_name] = $o->option_value; $alloptions[$o->option_name] = $o->option_value;
wp_cache_add( 'alloptions', $alloptions, 'options' ); if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
wp_cache_add( 'alloptions', $alloptions, 'options' );
} }
return $alloptions; return $alloptions;
} }
@ -623,6 +629,9 @@ function delete_option( $name ) {
function delete_transient($transient) { function delete_transient($transient) {
global $_wp_using_ext_object_cache, $wpdb; global $_wp_using_ext_object_cache, $wpdb;
if( is_multisite() )
do_action( 'delete_transient_' . $transient );
if ( $_wp_using_ext_object_cache ) { if ( $_wp_using_ext_object_cache ) {
return wp_cache_delete($transient, 'transient'); return wp_cache_delete($transient, 'transient');
} else { } else {
@ -690,6 +699,9 @@ function get_transient($transient) {
function set_transient($transient, $value, $expiration = 0) { function set_transient($transient, $value, $expiration = 0) {
global $_wp_using_ext_object_cache, $wpdb; global $_wp_using_ext_object_cache, $wpdb;
if( is_multisite() )
$value = apply_filters( 'pre_set_transient_' . $transient, $value );
if ( $_wp_using_ext_object_cache ) { if ( $_wp_using_ext_object_cache ) {
return wp_cache_set($transient, $value, 'transient', $expiration); return wp_cache_set($transient, $value, 'transient', $expiration);
} else { } else {
@ -2174,6 +2186,15 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
if ( $upload['error'] !== false ) if ( $upload['error'] !== false )
return $upload; return $upload;
if( is_multisite() ) {
/* WPMU check file before writing it */
$upload_bits_error = apply_filters( 'wp_upload_bits', array( 'name' => $name, 'bits' => $bits, 'time' => $time ) );
if( is_array( $upload_bits_error ) == false ) {
$upload[ 'error' ] = $upload_bits_error;
return $upload;
}
}
$filename = wp_unique_filename( $upload['path'], $name ); $filename = wp_unique_filename( $upload['path'], $name );
$new_file = $upload['path'] . "/$filename"; $new_file = $upload['path'] . "/$filename";

View File

@ -3076,10 +3076,12 @@ function wp_get_attachment_url( $post_id = 0 ) {
if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory
if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location
$url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location
elseif ( false !== strpos($file, 'wp-content/uploads') ) elseif ( !is_multisite() ) {
$url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 ); if ( false !== strpos($file, 'wp-content/uploads') )
else $url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 );
$url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir. else
$url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir.
}
} }
} }

View File

@ -1725,31 +1725,76 @@ class WP_Rewrite {
return ''; return '';
} }
$rules = ''; if( !is_multisite() ) {
$extra_indent = ''; $rules = '';
if ( $add_parent_tags ) { $extra_indent = '';
$rules .= "<configuration>".$end_of_line; if ( $add_parent_tags ) {
$rules .= $indent."<system.webServer>".$end_of_line; $rules .= "<configuration>".$end_of_line;
$rules .= $indent.$indent."<rewrite>".$end_of_line; $rules .= $indent."<system.webServer>".$end_of_line;
$rules .= $indent.$indent.$indent."<rules>".$end_of_line; $rules .= $indent.$indent."<rewrite>".$end_of_line;
$extra_indent = $indent.$indent.$indent.$indent; $rules .= $indent.$indent.$indent."<rules>".$end_of_line;
} $extra_indent = $indent.$indent.$indent.$indent;
}
$rules .= $extra_indent."<rule name=\"wordpress\" patternSyntax=\"Wildcard\">".$end_of_line; $rules .= $extra_indent."<rule name=\"wordpress\" patternSyntax=\"Wildcard\">".$end_of_line;
$rules .= $extra_indent.$indent."<match url=\"*\" />".$end_of_line; $rules .= $extra_indent.$indent."<match url=\"*\" />".$end_of_line;
$rules .= $extra_indent.$indent.$indent."<conditions>".$end_of_line; $rules .= $extra_indent.$indent.$indent."<conditions>".$end_of_line;
$rules .= $extra_indent.$indent.$indent.$indent."<add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" negate=\"true\" />".$end_of_line; $rules .= $extra_indent.$indent.$indent.$indent."<add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" negate=\"true\" />".$end_of_line;
$rules .= $extra_indent.$indent.$indent.$indent."<add input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" negate=\"true\" />".$end_of_line; $rules .= $extra_indent.$indent.$indent.$indent."<add input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" negate=\"true\" />".$end_of_line;
$rules .= $extra_indent.$indent.$indent."</conditions>".$end_of_line; $rules .= $extra_indent.$indent.$indent."</conditions>".$end_of_line;
$rules .= $extra_indent.$indent."<action type=\"Rewrite\" url=\"index.php\" />".$end_of_line; $rules .= $extra_indent.$indent."<action type=\"Rewrite\" url=\"index.php\" />".$end_of_line;
$rules .= $extra_indent."</rule>"; $rules .= $extra_indent."</rule>";
if ( $add_parent_tags ) { if ( $add_parent_tags ) {
$rules .= $end_of_line.$indent.$indent.$indent."</rules>".$end_of_line; $rules .= $end_of_line.$indent.$indent.$indent."</rules>".$end_of_line;
$rules .= $indent.$indent."</rewrite>".$end_of_line; $rules .= $indent.$indent."</rewrite>".$end_of_line;
$rules .= $indent."</system.webServer>".$end_of_line; $rules .= $indent."</system.webServer>".$end_of_line;
$rules .= "</configuration>"; $rules .= "</configuration>";
} }
} else {
$rules = '<rule name="wordpress - strip index.php" stopProcessing="false">
<match url="^index.php/(.*)$" />
<action type="Rewrite" url="{R:1}" />
</rule>
<rule name="wordpress - 1" stopProcessing="true">
<match url="^(.*/)?files/$" />
<action type="Rewrite" url="index.php" />
</rule>
<rule name="wordpress - 2" stopProcessing="true">
<match url="^(.*/)?files/(.*)" />
<conditions>
<add input="{REQUEST_URI}" negate="true" pattern=".*wp-content/plugins.*"/>
</conditions>
<action type="Rewrite" url="wp-content/blogs.php?file={R:2}" appendQueryString="false" />
</rule>
<rule name="wordpress - 3" stopProcessing="true">
<match url="^(.+)$" />
<conditions>
<add input="{REQUEST_URI}" pattern="^.*/wp-admin$" />
</conditions>
<action type="Redirect" url="{R:1}/" redirectType="Permanent" />
</rule>
<rule name="wordpress - 4" stopProcessing="true">
<match url="."/>
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" pattern="" />
</conditions>
<action type="None" />
</rule>
<rule name="wordpress - 5" stopProcessing="true">
<match url="^([_0-9a-zA-Z-]+/)?(wp-.*)" />
<action type="Rewrite" url="{R:2}" />
</rule>
<rule name="wordpress - 6" stopProcessing="true">
<match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" />
<action type="Rewrite" url="{R:2}" />
</rule>
<rule name="wordpress - 7" stopProcessing="true">
<match url="." />
<action type="Rewrite" url="index.php" />
</rule>';
}
$rules = apply_filters('iis7_url_rewrite_rules', $rules); $rules = apply_filters('iis7_url_rewrite_rules', $rules);

View File

@ -1417,16 +1417,30 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
} }
if ( ! $term_id = is_term($slug) ) { if ( ! $term_id = is_term($slug) ) {
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) if ( !is_multisite() ) {
return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
$term_id = (int) $wpdb->insert_id; return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
$term_id = (int) $wpdb->insert_id;
} else {
$maxterm = $wpdb->get_var( "SELECT max(term_id) FROM {$wpdb->terms}" );
$term_id = mt_rand( $maxterm+100, $maxterm+4000 );
if ( false === $wpdb->insert( $wpdb->terms, compact( 'term_id', 'name', 'slug', 'term_group' ) ) )
return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
}
} else if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) { } else if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) {
// If the taxonomy supports hierarchy and the term has a parent, make the slug unique // If the taxonomy supports hierarchy and the term has a parent, make the slug unique
// by incorporating parent slugs. // by incorporating parent slugs.
$slug = wp_unique_term_slug($slug, (object) $args); $slug = wp_unique_term_slug($slug, (object) $args);
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) if( !is_multisite() ) {
return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
$term_id = (int) $wpdb->insert_id; return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
$term_id = (int) $wpdb->insert_id;
} else {
$maxterm = $wpdb->get_var( "SELECT max(term_id) FROM {$wpdb->terms}" );
$term_id = mt_rand( $maxterm+100, $maxterm+4000 );
if ( false === $wpdb->insert( $wpdb->terms, compact( 'term_id','name', 'slug', 'term_group' ) ) )
return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
}
} }
if ( empty($slug) ) { if ( empty($slug) ) {

View File

@ -279,7 +279,8 @@ function get_users_of_blog( $id = '' ) {
global $wpdb, $blog_id; global $wpdb, $blog_id;
if ( empty($id) ) if ( empty($id) )
$id = (int) $blog_id; $id = (int) $blog_id;
$users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$wpdb->prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" ); $blog_prefix = $wpdb->get_blog_prefix($id);
$users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" );
return $users; return $users;
} }

View File

@ -39,7 +39,7 @@ if ( force_ssl_admin() && !is_ssl() ) {
* @param WP_Error $wp_error Optional. WordPress Error Object * @param WP_Error $wp_error Optional. WordPress Error Object
*/ */
function login_header($title = 'Log In', $message = '', $wp_error = '') { function login_header($title = 'Log In', $message = '', $wp_error = '') {
global $error, $is_iphone, $interim_login; global $error, $is_iphone, $interim_login, $current_site;
// Don't index any of these forms // Don't index any of these forms
add_filter( 'pre_option_blog_public', create_function( '$a', 'return 0;' ) ); add_filter( 'pre_option_blog_public', create_function( '$a', 'return 0;' ) );
@ -74,9 +74,12 @@ function login_header($title = 'Log In', $message = '', $wp_error = '') {
do_action('login_head'); ?> do_action('login_head'); ?>
</head> </head>
<body class="login"> <body class="login">
<?php if( !is_multisite() ) { ?>
<div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', 'http://wordpress.org/'); ?>" title="<?php echo apply_filters('login_headertitle', __('Powered by WordPress')); ?>"><?php bloginfo('name'); ?></a></h1> <div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', 'http://wordpress.org/'); ?>" title="<?php echo apply_filters('login_headertitle', __('Powered by WordPress')); ?>"><?php bloginfo('name'); ?></a></h1>
<?php <?php } else { ?>
<div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', 'http://' . $current_site->domain . $current_site->path ); ?>" title="<?php echo apply_filters('login_headertitle', $current_site->site_name ); ?>"><span class="hide"><?php bloginfo('name'); ?></span></a></h1>
<?php }
$message = apply_filters('login_message', $message); $message = apply_filters('login_message', $message);
if ( !empty( $message ) ) echo $message . "\n"; if ( !empty( $message ) ) echo $message . "\n";
@ -113,7 +116,7 @@ function login_header($title = 'Log In', $message = '', $wp_error = '') {
* @return bool|WP_Error True: when finish. WP_Error on error * @return bool|WP_Error True: when finish. WP_Error on error
*/ */
function retrieve_password() { function retrieve_password() {
global $wpdb; global $wpdb, $current_site;
$errors = new WP_Error(); $errors = new WP_Error();
@ -162,10 +165,18 @@ function retrieve_password() {
$wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login)); $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
} }
$message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n"; $message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n";
$message .= get_option('siteurl') . "\r\n\r\n"; if( !is_multisite() ) {
$message .= get_option('siteurl') . "\r\n\r\n";
} else {
$message .= 'http://' . trailingslashit( $current_site->domain . $current_site->path ) . "\r\n\r\n";
}
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.') . "\r\n\r\n"; $message .= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.') . "\r\n\r\n";
$message .= site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . "\r\n"; if( !is_multisite() ) {
$message .= site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . "\r\n";
} else {
$message .= 'http://' . trailingslashit( $current_site->domain . $current_site->path ) . "wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login) . "\r\n";
}
// The blogname option is escaped with esc_html on the way into the database in sanitize_option // The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails. // we want to reverse this for the plain text arena of emails.
@ -398,6 +409,11 @@ case 'rp' :
break; break;
case 'register' : case 'register' :
if( is_multisite() ) {
// WPMU doesn't use this
wp_redirect( apply_filters( 'wp_signup_location', get_bloginfo('wpurl') . '/wp-signup.php' ) );
exit;
}
if ( !get_option('users_can_register') ) { if ( !get_option('users_can_register') ) {
wp_redirect('wp-login.php?registration=disabled'); wp_redirect('wp-login.php?registration=disabled');
exit(); exit();