]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/ms.php
Wordpress 3.5
[autoinstalls/wordpress.git] / wp-admin / includes / ms.php
index ae23b7f80bb529e30df0d8c312895da0287933d8..b62e1d0b2d86cbefe9dacaf908f779e0dde7e5f6 100644 (file)
@@ -25,9 +25,8 @@ function check_upload_size( $file ) {
        if ( defined( 'WP_IMPORTING' ) )
                return $file;
 
-       $space_allowed = 1048576 * get_space_allowed();
-       $space_used = get_dirsize( BLOGUPLOADDIR );
-       $space_left = $space_allowed - $space_used;
+       $space_left = get_upload_space_available();
+
        $file_size = filesize( $file['tmp_name'] );
        if ( $space_left < $file_size )
                $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );
@@ -49,46 +48,48 @@ add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
  * @since 3.0.0
  *
  * @param int $blog_id Blog ID
- * @param bool $drop True if blog's table should be dropped.  Default is false.
+ * @param bool $drop True if blog's table should be dropped. Default is false.
  * @return void
  */
 function wpmu_delete_blog( $blog_id, $drop = false ) {
-       global $wpdb;
+       global $wpdb, $current_site;
 
        $switch = false;
-       if ( $blog_id != $wpdb->blogid ) {
+       if ( get_current_blog_id() != $blog_id ) {
                $switch = true;
                switch_to_blog( $blog_id );
        }
 
-       $blog_prefix = $wpdb->get_blog_prefix( $blog_id );
+       $blog = get_blog_details( $blog_id );
 
        do_action( 'delete_blog', $blog_id, $drop );
 
-       $users = get_users_of_blog( $blog_id );
+       $users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );
 
        // Remove users from this blog.
        if ( ! empty( $users ) ) {
-               foreach ( $users as $user ) {
-                       remove_user_from_blog( $user->user_id, $blog_id) ;
+               foreach ( $users as $user_id ) {
+                       remove_user_from_blog( $user_id, $blog_id );
                }
        }
 
        update_blog_status( $blog_id, 'deleted', 1 );
 
-       if ( $drop ) {
-               if ( substr( $blog_prefix, -1 ) == '_' )
-                       $blog_prefix =  substr( $blog_prefix, 0, -1 ) . '\_';
+       // Don't destroy the initial, main, or root blog.
+       if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
+               $drop = false;
 
-               $drop_tables = $wpdb->get_results( "SHOW TABLES LIKE '{$blog_prefix}%'", ARRAY_A );
-               $drop_tables = apply_filters( 'wpmu_drop_tables', $drop_tables );
+       if ( $drop ) {
+               $drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) );
 
-               reset( $drop_tables );
-               foreach ( (array) $drop_tables as $drop_table) {
-                       $wpdb->query( "DROP TABLE IF EXISTS ". current( $drop_table ) ."" );
+               foreach ( (array) $drop_tables as $table ) {
+                       $wpdb->query( "DROP TABLE IF EXISTS `$table`" );
                }
-               $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );
-               $dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
+
+               $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $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);
@@ -109,28 +110,21 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
                                        else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) )
                                                @unlink( $dir . DIRECTORY_SEPARATOR . $file );
                                }
+                               @closedir( $dh );
                        }
                        $index++;
                }
 
-               $stack = array_reverse( $stack );  // Last added dirs are deepest
+               $stack = array_reverse( $stack ); // Last added dirs are deepest
                foreach( (array) $stack as $dir ) {
                        if ( $dir != $top_dir)
                        @rmdir( $dir );
                }
-       }
 
-       $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$blog_prefix}autosave_draft_ids'" );
-       $blogs = get_site_option( 'blog_list' );
-       if ( is_array( $blogs ) ) {
-               foreach ( $blogs as $n => $blog ) {
-                       if ( $blog['blog_id'] == $blog_id )
-                               unset( $blogs[$n] );
-               }
-               update_site_option( 'blog_list', $blogs );
+               clean_blog_cache( $blog );
        }
 
-       if ( $switch === true )
+       if ( $switch )
                restore_current_blog();
 }
 
@@ -139,6 +133,7 @@ function wpmu_delete_user( $id ) {
        global $wpdb;
 
        $id = (int) $id;
+       $user = new WP_User( $id );
 
        do_action( 'wpmu_delete_user', $id );
 
@@ -166,10 +161,13 @@ function wpmu_delete_user( $id ) {
                }
        }
 
-       $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->users WHERE ID = %d", $id ) );
-       $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
+       $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
+       foreach ( $meta as $mid )
+               delete_metadata_by_mid( 'user', $mid );
 
-       clean_user_cache( $id );
+       $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
+
+       clean_user_cache( $user );
 
        // allow for commit transaction
        do_action( 'deleted_user', $id );
@@ -177,101 +175,6 @@ function wpmu_delete_user( $id ) {
        return true;
 }
 
-function confirm_delete_users( $users ) {
-       global $current_user;
-       if ( !is_array( $users ) )
-               return false;
-
-    screen_icon();
-    ?>
-       <h2><?php esc_html_e( 'Users' ); ?></h2>
-       <p><?php _e( 'Transfer or delete posts and links before deleting users.' ); ?></p>
-       <form action="ms-edit.php?action=dodelete" method="post">
-       <input type="hidden" name="dodelete" />
-    <?php
-       wp_nonce_field( 'ms-users-delete' );
-       $site_admins = get_super_admins();
-       $admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>";
-
-       foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
-               if ( $val != '' && $val != '0' ) {
-                       $delete_user = new WP_User( $val );
-
-                       if ( in_array( $delete_user->user_login, $site_admins ) )
-                               wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network admnistrator.' ), $delete_user->user_login ) );
-
-                       echo "<input type='hidden' name='user[]' value='{$val}'/>\n";
-                       $blogs = get_blogs_of_user( $val, true );
-
-                       if ( !empty( $blogs ) ) {
-                               ?>
-                               <br /><fieldset><p><legend><?php printf( __( "What should be done with posts and links owned by <em>%s</em>?" ), $delete_user->user_login ); ?></legend></p>
-                               <?php
-                               foreach ( (array) $blogs as $key => $details ) {
-                                       $blog_users = get_users_of_blog( $details->userblog_id );
-                                       if ( is_array( $blog_users ) && !empty( $blog_users ) ) {
-                                               $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
-                                               $user_dropdown = "<select name='blog[$val][{$key}]'>";
-                                               $user_list = '';
-                                               foreach ( $blog_users as $user ) {
-                                                       if ( $user->user_id != $val && !in_array( $user->user_id, $allusers ) )
-                                                               $user_list .= "<option value='{$user->user_id}'>{$user->user_login}</option>";
-                                               }
-                                               if ( '' == $user_list )
-                                                       $user_list = $admin_out;
-                                               $user_dropdown .= $user_list;
-                                               $user_dropdown .= "</select>\n";
-                                               ?>
-                                               <ul style="list-style:none;">
-                                                       <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
-                                                       <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" />
-                                                       <?php _e( 'Delete all posts and links.' ); ?></label></li>
-                                                       <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" />
-                                                       <?php echo __( 'Attribute all posts and links to:' ) . '</label>' . $user_dropdown; ?></li>
-                                               </ul>
-                                               <?php
-                                       }
-                               }
-                               echo "</fieldset>";
-                       }
-               }
-       }
-       ?>
-       <p class="submit"><input type="submit" class="button-secondary delete" value="<?php esc_attr_e( 'Confirm Deletion' ); ?>" /></p>
-       </form>
-    <?php
-       return true;
-}
-
-function wpmu_get_blog_allowedthemes( $blog_id = 0 ) {
-       $themes = get_themes();
-
-       if ( $blog_id != 0 )
-               switch_to_blog( $blog_id );
-
-       $blog_allowed_themes = get_option( 'allowedthemes' );
-       if ( !is_array( $blog_allowed_themes ) || empty( $blog_allowed_themes ) ) { // convert old allowed_themes to new allowedthemes
-               $blog_allowed_themes = get_option( 'allowed_themes' );
-
-               if ( is_array( $blog_allowed_themes ) ) {
-                       foreach( (array) $themes as $key => $theme ) {
-                               $theme_key = esc_html( $theme['Stylesheet'] );
-                               if ( isset( $blog_allowed_themes[$key] ) == true ) {
-                                       $blog_allowedthemes[$theme_key] = 1;
-                               }
-                       }
-                       $blog_allowed_themes = $blog_allowedthemes;
-                       add_option( 'allowedthemes', $blog_allowed_themes );
-                       delete_option( 'allowed_themes' );
-               }
-       }
-
-       if ( $blog_id != 0 )
-               restore_current_blog();
-
-       return $blog_allowed_themes;
-}
-
 function update_option_new_admin_email( $old_value, $value ) {
        $email = get_option( 'admin_email' );
        if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
@@ -311,21 +214,22 @@ add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10
 add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
 
 function send_confirmation_on_profile_email() {
-       global $errors, $wpdb, $current_user;
+       global $errors, $wpdb;
+       $current_user = wp_get_current_user();
        if ( ! is_object($errors) )
                $errors = new WP_Error();
 
-       if ( $current_user->id != $_POST['user_id'] )
+       if ( $current_user->ID != $_POST['user_id'] )
                return false;
 
        if ( $current_user->user_email != $_POST['email'] ) {
                if ( !is_email( $_POST['email'] ) ) {
-                       $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address isn't correct." ), array( 'form-field' => 'email' ) );
+                       $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn&#8217;t correct." ), array( 'form-field' => 'email' ) );
                        return;
                }
 
                if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {
-                       $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address is already used." ), array( 'form-field' => 'email' ) );
+                       $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array( 'form-field' => 'email' ) );
                        delete_option( $current_user->ID . '_new_email' );
                        return;
                }
@@ -364,187 +268,110 @@ All at ###SITENAME###
 add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
 
 function new_user_email_admin_notice() {
-       global $current_user;
-       if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( $current_user->ID . '_new_email' ) )
+       if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) )
                echo "<div class='update-nag'>" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "</div>";
 }
 add_action( 'admin_notices', 'new_user_email_admin_notice' );
 
-function get_site_allowed_themes() {
-       $themes = get_themes();
-       $allowed_themes = get_site_option( 'allowedthemes' );
-       if ( !is_array( $allowed_themes ) || empty( $allowed_themes ) ) {
-               $allowed_themes = get_site_option( 'allowed_themes' ); // convert old allowed_themes format
-               if ( !is_array( $allowed_themes ) ) {
-                       $allowed_themes = array();
-               } else {
-                       foreach( (array) $themes as $key => $theme ) {
-                               $theme_key = esc_html( $theme['Stylesheet'] );
-                               if ( isset( $allowed_themes[ $key ] ) == true ) {
-                                       $allowedthemes[ $theme_key ] = 1;
-                               }
-                       }
-                       $allowed_themes = $allowedthemes;
-               }
-       }
-       return $allowed_themes;
-}
-
 /**
- * Determines if there is any upload space left in the current blog's quota.
+ * Check whether a blog has used its allotted upload space.
  *
- * @since 3.0.0
- * @return bool True if space is available, false otherwise.
- */
-function is_upload_space_available() {
-       if ( get_site_option( 'upload_space_check_disabled' ) )
-               return true;
-
-       if ( !( $space_allowed = get_upload_space_available() ) )
-               return false;
-
-       return true;
-}
-
-/*
- * @since 3.0.0
+ * @since MU
  *
- * @return int of upload size limit in bytes
+ * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
+ * @return int
  */
-function upload_size_limit_filter( $size ) {
-       $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
-       return min( $size, $fileupload_maxk, get_upload_space_available() );
-}
-/**
- * Determines if there is any upload space left in the current blog's quota.
- *
- * @return int of upload space available in bytes
- */
-function get_upload_space_available() {
-       $space_allowed = get_space_allowed() * 1024 * 1024;
+function upload_is_user_over_quota( $echo = true ) {
        if ( get_site_option( 'upload_space_check_disabled' ) )
-               return $space_allowed;
+               return false;
 
-       $dir_name = trailingslashit( BLOGUPLOADDIR );
-       if ( !( is_dir( $dir_name) && is_readable( $dir_name ) ) )
-               return $space_allowed;
+       $space_allowed = get_space_allowed();
+       if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) )
+               $space_allowed = 10; // Default space allowed is 10 MB
 
-       $dir = dir( $dir_name );
-       $size = 0;
+       $space_used = get_space_used();
 
-       while ( $file = $dir->read() ) {
-               if ( $file != '.' && $file != '..' ) {
-                       if ( is_dir( $dir_name . $file) ) {
-                               $size += get_dirsize( $dir_name . $file );
-                       } else {
-                               $size += filesize( $dir_name . $file );
-                       }
-               }
+       if ( ( $space_allowed - $space_used ) < 0 ) {
+               if ( $echo )
+                       _e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' );
+               return true;
+       } else {
+               return false;
        }
-       $dir->close();
-
-       if ( ( $space_allowed - $size ) <= 0 )
-               return 0;
-
-       return $space_allowed - $size;
 }
 
 /**
- * Returns the upload quota for the current blog.
+ * Displays the amount of disk space used by the current blog. Not used in core.
  *
- * @return int Quota
+ * @since MU
  */
-function get_space_allowed() {
-       $space_allowed = get_option( 'blog_upload_space' );
-       if ( $space_allowed == false )
-               $space_allowed = get_site_option( 'blog_upload_space' );
-       if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) )
-               $space_allowed = 50;
-
-       return $space_allowed;
-}
-
 function display_space_usage() {
-       $space = get_space_allowed();
-       $used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;
+       $space_allowed = get_space_allowed();
+       $space_used = get_space_used();
 
-       $percentused = ( $used / $space ) * 100;
+       $percent_used = ( $space_used / $space_allowed ) * 100;
 
-       if ( $space > 1000 ) {
-               $space = number_format( $space / 1024 );
+       if ( $space_allowed > 1000 ) {
+               $space = number_format( $space_allowed / 1024 );
                /* translators: Gigabytes */
                $space .= __( 'GB' );
        } else {
+               $space = number_format( $space_allowed );
                /* translators: Megabytes */
                $space .= __( 'MB' );
        }
        ?>
-       <strong><?php printf( __( 'Used: %1s%% of %2s' ), number_format( $percentused ), $space ); ?></strong>
+       <strong><?php printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space ); ?></strong>
        <?php
 }
 
-// Display File upload quota on dashboard
-function dashboard_quota() {
-       if ( get_site_option( 'upload_space_check_disabled' ) )
-               return true;
-
-       $quota = get_space_allowed();
-       $used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;
-
-       if ( $used > $quota )
-               $percentused = '100';
-       else
-               $percentused = ( $used / $quota ) * 100;
-       $used_color = ( $percentused < 70 ) ? ( ( $percentused >= 40 ) ? 'waiting' : 'approved' ) : 'spam';
-       $used = round( $used, 2 );
-       $percentused = number_format( $percentused );
+/**
+ * Get the remaining upload space for this blog.
+ *
+ * @since MU
+ * @uses upload_is_user_over_quota()
+ * @uses get_space_allowed()
+ * @uses get_upload_space_available()
+ *
+ * @param int $size Current max size in bytes
+ * @return int Max size in bytes
+ */
+function fix_import_form_size( $size ) {
+       if ( upload_is_user_over_quota( false ) == true )
+               return 0;
 
-       ?>
-       <p class="sub musub"><?php _e( 'Storage Space' ); ?></p>
-       <div class="table table_content musubtable">
-       <table>
-               <tr class="first">
-                       <td class="first b b-posts"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>' ), esc_url( admin_url( 'upload.php' ) ), $quota ); ?></td>
-                       <td class="t posts"><?php _e( 'Space Allowed' ); ?></td>
-               </tr>
-       </table>
-       </div>
-       <div class="table table_discussion musubtable">
-       <table>
-               <tr class="first">
-                       <td class="b b-comments"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>' ), esc_url( admin_url( 'upload.php' ) ), $used, $percentused ); ?></td>
-                       <td class="last t comments <?php echo $used_color;?>"><?php _e( 'Space Used' );?></td>
-               </tr>
-       </table>
-       </div>
-       <br class="clear" />
-       <?php
+       $available = get_upload_space_available();
+       return min( $size, $available );
 }
-if ( current_user_can( 'edit_posts' ) )
-       add_action( 'activity_box_end', 'dashboard_quota' );
 
 // Edit blog upload space setting on Edit Blog page
 function upload_space_setting( $id ) {
-       $quota = get_blog_option( $id, 'blog_upload_space' );
+       switch_to_blog( $id );
+       $quota = get_option( 'blog_upload_space' );
+       restore_current_blog();
+
        if ( !$quota )
                $quota = '';
 
        ?>
        <tr>
                <th><?php _e( 'Site Upload Space Quota '); ?></th>
-               <td><input type="text" size="3" name="option[blog_upload_space]" value="<?php echo $quota; ?>" /> <?php _e( 'MB (Leave blank for network default)' ); ?></td>
+               <td><input type="number" step="1" min="0" style="width: 100px" name="option[blog_upload_space]" value="<?php echo $quota; ?>" /> <?php _e( 'MB (Leave blank for network default)' ); ?></td>
        </tr>
        <?php
 }
 add_action( 'wpmueditblogaction', 'upload_space_setting' );
 
-function update_user_status( $id, $pref, $value, $refresh = 1 ) {
+function update_user_status( $id, $pref, $value, $deprecated = null ) {
        global $wpdb;
 
+       if ( null !== $deprecated )
+               _deprecated_argument( __FUNCTION__, '3.1' );
+
        $wpdb->update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) );
 
-       if ( $refresh == 1 )
-               refresh_user_details( $id );
+       $user = new WP_User( $id );
+       clean_user_cache( $user );
 
        if ( $pref == 'spam' ) {
                if ( $value == 1 )
@@ -562,7 +389,7 @@ function refresh_user_details( $id ) {
        if ( !$user = get_userdata( $id ) )
                return false;
 
-       clean_user_cache( $id );
+       clean_user_cache( $user );
 
        return $id;
 }
@@ -597,44 +424,41 @@ function sync_category_tag_slugs( $term, $taxonomy ) {
 }
 add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
 
-function redirect_user_to_blog() {
-       global $current_user;
-       $c = 0;
-       if ( isset( $_GET['c'] ) )
-               $c = (int) $_GET['c'];
+function _access_denied_splash() {
+       if ( ! is_user_logged_in() || is_network_admin() )
+               return;
 
-       if ( $c >= 5 ) {
-               wp_die( __( "You don&#8217;t have permission to view this site. Please contact the system administrator." ) );
-       }
-       $c ++;
+       $blogs = get_blogs_of_user( get_current_user_id() );
 
-       $blog = get_active_blog_for_user( $current_user->ID );
-       $dashboard_blog = get_dashboard_blog();
-       if ( is_object( $blog ) ) {
-               wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); // redirect and count to 5, "just in case"
-               exit;
-       }
+       if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
+               return;
 
-       /*
-          If the user is a member of only 1 blog and the user's primary_blog isn't set to that blog,
-          then update the primary_blog record to match the user's blog
-        */
-       $blogs = get_blogs_of_user( $current_user->ID );
-
-       if ( !empty( $blogs ) ) {
-               foreach( $blogs as $blogid => $blog ) {
-                       if ( $blogid != $dashboard_blog->blog_id && get_user_meta( $current_user->ID , 'primary_blog', true ) == $dashboard_blog->blog_id ) {
-                               update_user_meta( $current_user->ID, 'primary_blog', $blogid );
-                               continue;
-                       }
-               }
-               $blog = get_blog_details( get_user_meta( $current_user->ID, 'primary_blog', true ) );
-                       wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) );
-               exit;
+       $blog_name = get_bloginfo( 'name' );
+
+       if ( empty( $blogs ) )
+               wp_die( sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) );
+
+       $output = '<p>' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '</p>';
+       $output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '</p>';
+
+       $output .= '<h3>' . __('Your Sites') . '</h3>';
+       $output .= '<table>';
+
+       foreach ( $blogs as $blog ) {
+               $output .= "<tr>";
+               $output .= "<td valign='top'>";
+               $output .= "{$blog->blogname}";
+               $output .= "</td>";
+               $output .= "<td valign='top'>";
+               $output .= "<a href='" . esc_url( get_admin_url( $blog->userblog_id ) ) . "'>" . __( 'Visit Dashboard' ) . "</a> | <a href='" . esc_url( get_home_url( $blog->userblog_id ) ). "'>" . __( 'View Site' ) . "</a>" ;
+               $output .= "</td>";
+               $output .= "</tr>";
        }
-       wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
+       $output .= '</table>';
+
+       wp_die( $output );
 }
-add_action( 'admin_page_access_denied', 'redirect_user_to_blog', 99 );
+add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
 
 function check_import_new_users( $permission ) {
        if ( !is_super_admin() )
@@ -654,20 +478,20 @@ function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
                if ( $code_lang == 'en_US' ) { // American English
                        $flag = true;
                        $ae = __( 'American English' );
-                       $output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang ) . '> ' . $ae . '</option>';
+                       $output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
                } elseif ( $code_lang == 'en_GB' ) { // British English
                        $flag = true;
                        $be = __( 'British English' );
-                       $output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang ) . '> ' . $be . '</option>';
+                       $output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
                } else {
                        $translated = format_code_lang( $code_lang );
-                       $output[$translated] =  '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang ) . '> ' . esc_html ( $translated ) . '</option>';
+                       $output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>';
                }
 
        }
 
        if ( $flag === false ) // WordPress english
-               $output[] = '<option value=""' . selected( $current, '' ) . '>' . __( 'English' ) . "</option>";
+               $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";
 
        // Order by name
        uksort( $output, 'strnatcasecmp' );
@@ -694,47 +518,17 @@ function secret_salt_warning() {
                echo "<div class='update-nag'>$msg</div>";
        }
 }
-add_action( 'admin_notices', 'secret_salt_warning' );
-
-function admin_notice_feed() {
-       global $current_user, $current_screen;
-       if ( $current_screen->id != 'dashboard' )
-               return;
-
-       if ( !empty( $_GET['feed_dismiss'] ) ) {
-               update_user_option( $current_user->id, 'admin_feed_dismiss', $_GET['feed_dismiss'], true );
-               return;
-       }
-
-       $url = get_site_option( 'admin_notice_feed' );
-       if ( empty( $url ) )
-               return;
-
-       $rss = fetch_feed( $url );
-       if ( ! is_wp_error( $rss ) && $item = $rss->get_item() ) {
-               $title = $item->get_title();
-               if ( md5( $title ) == get_user_option( 'admin_feed_dismiss' ) )
-                       return;
-               $msg = "<h3>" . esc_html( $title ) . "</h3>\n";
-               $content = $item->get_description();
-               $content = $content ? wp_html_excerpt( $content, 200 ) . ' &hellip; ' : '';
-               $link = esc_url( strip_tags( $item->get_link() ) );
-               $msg .= "<p>" . $content . "<a href='$link'>" . __( 'Read More' ) . "</a> <a href='index.php?feed_dismiss=" . md5( $title ) . "'>" . __( 'Dismiss' ) . "</a></p>";
-               echo "<div class='updated'>$msg</div>";
-       } elseif ( is_super_admin() ) {
-               printf( '<div class="update-nag">' . __( 'Your feed at %s is empty.' ) . '</div>', esc_html( $url ) );
-       }
-}
-add_action( 'admin_notices', 'admin_notice_feed' );
+add_action( 'network_admin_notices', 'secret_salt_warning' );
 
 function site_admin_notice() {
-       global $current_user, $wp_db_version;
+       global $wp_db_version;
        if ( !is_super_admin() )
                return false;
        if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version )
-               echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Update Network</a> page to update all your sites.' ), esc_url( admin_url( 'ms-upgrade-network.php' ) ) ) . "</div>";
+               echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Update Network</a> page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "</div>";
 }
 add_action( 'admin_notices', 'site_admin_notice' );
+add_action( 'network_admin_notices', 'site_admin_notice' );
 
 function avoid_blog_page_permalink_collision( $data, $postarr ) {
        if ( is_subdomain_install() )
@@ -760,7 +554,6 @@ function avoid_blog_page_permalink_collision( $data, $postarr ) {
 add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
 
 function choose_primary_blog() {
-       global $current_user;
        ?>
        <table class="form-table">
        <tr>
@@ -768,8 +561,8 @@ function choose_primary_blog() {
                <th scope="row"><?php _e( 'Primary Site' ); ?></th>
                <td>
                <?php
-               $all_blogs = get_blogs_of_user( $current_user->ID );
-               $primary_blog = get_user_meta( $current_user->ID, 'primary_blog', true );
+               $all_blogs = get_blogs_of_user( get_current_user_id() );
+               $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
                if ( count( $all_blogs ) > 1 ) {
                        $found = false;
                        ?>
@@ -777,19 +570,19 @@ function choose_primary_blog() {
                                <?php foreach( (array) $all_blogs as $blog ) {
                                        if ( $primary_blog == $blog->userblog_id )
                                                $found = true;
-                                       ?><option value="<?php echo $blog->userblog_id ?>"<?php selected( $primary_blog,  $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ) ?></option><?php
+                                       ?><option value="<?php echo $blog->userblog_id ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ) ?></option><?php
                                } ?>
                        </select>
                        <?php
                        if ( !$found ) {
                                $blog = array_shift( $all_blogs );
-                               update_user_meta( $current_user->ID, 'primary_blog', $blog->userblog_id );
+                               update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
                        }
                } elseif ( count( $all_blogs ) == 1 ) {
                        $blog = array_shift( $all_blogs );
                        echo $blog->domain;
                        if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
-                               update_user_meta( $current_user->ID, 'primary_blog', $blog->userblog_id );
+                               update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
                } else {
                        echo "N/A";
                }
@@ -799,7 +592,7 @@ function choose_primary_blog() {
        <?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?>
                <tr>
                        <th scope="row" colspan="2" class="th-full">
-                               <a href="<?php echo apply_filters( 'wp_signup_location', network_home_url( 'wp-signup.php' ) ); ?>"><?php _e( 'Create a New Site' ); ?></a>
+                               <a href="<?php echo apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ); ?>"><?php _e( 'Create a New Site' ); ?></a>
                        </th>
                </tr>
        <?php endif; ?>
@@ -807,41 +600,11 @@ function choose_primary_blog() {
        <?php
 }
 
-function show_post_thumbnail_warning() {
-       if ( ! is_super_admin() )
-               return;
-       $mu_media_buttons = get_site_option( 'mu_media_buttons', array() );
-       if ( empty($mu_media_buttons['image']) && current_theme_supports( 'post-thumbnails' ) ) {
-               echo "<div class='update-nag'>" . sprintf( __( "Warning! The current theme supports Featured Images. You must enable image uploads on <a href='%s'>the options page</a> for it to work." ), esc_url( admin_url( 'ms-options.php' ) ) ) . "</div>";
-       }
-}
-add_action( 'admin_notices', 'show_post_thumbnail_warning' );
-
-function ms_deprecated_blogs_file() {
-       if ( ! is_super_admin() )
-               return;
-       if ( ! file_exists( WP_CONTENT_DIR . '/blogs.php' ) )
-               return;
-       echo '<div class="update-nag">' . sprintf( __( 'The <code>%1$s</code> file is deprecated. Please remove it and update your server rewrite rules to use <code>%2$s</code> instead.' ), 'wp-content/blogs.php', 'wp-includes/ms-files.php' ) . '</div>';
-}
-add_action( 'admin_notices', 'ms_deprecated_blogs_file' );
-
-/**
- * Outputs the notice message for multisite regarding activation of plugin page.
- *
- * @since 3.0.0
- * @return none
- */
-function _admin_notice_multisite_activate_plugins_page() {
-       $message = sprintf( __( 'The plugins page is not visible to normal users. It must be activated first. %s' ), '<a href="' . esc_url( admin_url( 'ms-options.php#menu' ) ) . '">' . __( 'Activate' ) . '</a>' );
-       echo "<div class='error'><p>$message</p></div>";
-}
-
 /**
  * Grants super admin privileges.
  *
  * @since 3.0.0
- * @param $user_id
+ * @param int $user_id
  */
 function grant_super_admin( $user_id ) {
        global $super_admins;
@@ -855,8 +618,8 @@ function grant_super_admin( $user_id ) {
        // Directly fetch site_admins instead of using get_super_admins()
        $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
 
-       $user = new WP_User( $user_id );
-       if ( ! in_array( $user->user_login, $super_admins ) ) {
+       $user = get_userdata( $user_id );
+       if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
                $super_admins[] = $user->user_login;
                update_site_option( 'site_admins' , $super_admins );
                do_action( 'granted_super_admin', $user_id );
@@ -869,7 +632,7 @@ function grant_super_admin( $user_id ) {
  * Revokes super admin privileges.
  *
  * @since 3.0.0
- * @param $user_id
+ * @param int $user_id
  */
 function revoke_super_admin( $user_id ) {
        global $super_admins;
@@ -883,8 +646,8 @@ function revoke_super_admin( $user_id ) {
        // Directly fetch site_admins instead of using get_super_admins()
        $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
 
-       $user = new WP_User( $user_id );
-       if ( $user->user_email != get_site_option( 'admin_email' ) ) {
+       $user = get_userdata( $user_id );
+       if ( $user && $user->user_email != get_site_option( 'admin_email' ) ) {
                if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
                        unset( $super_admins[$key] );
                        update_site_option( 'site_admins', $super_admins );
@@ -894,4 +657,58 @@ function revoke_super_admin( $user_id ) {
        }
        return false;
 }
+
+/**
+ * Whether or not we can edit this network from this page
+ *
+ * By default editing of network is restricted to the Network Admin for that site_id this allows for this to be overridden
+ *
+ * @since 3.1.0
+ * @param integer $site_id The network/site id to check.
+ */
+function can_edit_network( $site_id ) {
+       global $wpdb;
+
+       if ($site_id == $wpdb->siteid )
+               $result = true;
+       else
+               $result = false;
+
+       return apply_filters( 'can_edit_network', $result, $site_id );
+}
+
+/**
+ * Thickbox image paths for Network Admin.
+ *
+ * @since 3.1.0
+ * @access private
+ */
+function _thickbox_path_admin_subfolder() {
 ?>
+<script type="text/javascript">
+//<![CDATA[
+var tb_pathToImage = "../../wp-includes/js/thickbox/loadingAnimation.gif";
+//]]>
+</script>
+<?php
+}
+
+/**
+ * Whether or not we have a large network.
+ *
+ * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
+ * Plugins can alter this criteria using the 'wp_is_large_network' filter.
+ *
+ * @since 3.3.0
+ * @param string $using 'sites or 'users'. Default is 'sites'.
+ * @return bool True if the network meets the criteria for large. False otherwise.
+ */
+function wp_is_large_network( $using = 'sites' ) {
+       if ( 'users' == $using ) {
+               $count = get_user_count();
+               return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count );
+       }
+
+       $count = get_blog_count();
+       return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );
+}