Make WordPress Core

Ticket #11869: 11869.diff

File 11869.diff, 4.8 KB (added by ocean90, 15 years ago)

Its not perfect, only a first try.

  • wp-admin/ms-upgrade-network.php

     
    1212if ( !is_multisite() )
    1313        wp_die( __('Multisite support is not enabled.') );
    1414
    15 require_once( ABSPATH . WPINC . '/http.php' );
    16 
    17 $title = __('Update Network');
    18 $parent_file = 'ms-admin.php';
    19 require_once('admin-header.php');
    20 
    2115if ( ! current_user_can( 'manage_network' ) )
    2216        wp_die( __('You do not have permission to access this page.') );
    2317
    24 echo '<div class="wrap">';
    25 screen_icon();
    26 echo '<h2>'.__('Update Network').'</h2>';
     18require_once( ABSPATH . WPINC . '/http.php' );
    2719
    2820$action = isset($_GET['action']) ? $_GET['action'] : 'show';
     21$n = ( isset($_GET['n']) ) ? intval($_GET['n']) : 0;
    2922
     23$ajax = false;
     24if ( 'upgrade' == $action && $n > 4 )
     25        $ajax = true;
     26
     27if ( !$ajax ) {
     28        $title = __('Update Network');
     29        $parent_file = 'ms-admin.php';
     30        require_once('admin-header.php');
     31        echo '<div class="wrap">';
     32        screen_icon();
     33        echo '<h2>'.__('Update Network').'</h2>';
     34} else {
     35        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
     36}
     37
    3038switch ( $action ) {
    3139        case "upgrade":
    32                 $n = ( isset($_GET['n']) ) ? intval($_GET['n']) : 0;
     40               
    3341
    3442                if ( $n < 5 ) {
    3543                        global $wp_db_version;
     
    3745                }
    3846
    3947                $blogs = $wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A );
    40                 if ( empty( $blogs ) ) {
    41                         echo '<p>' . __( 'All done!' ) . '</p>';
    42                         break;
    43                 }
    44                 echo "<ul>";
     48                if ( empty( $blogs ) )
     49                        die( '0' );
     50
     51                if ( !$ajax )
     52                        echo "<ul id='site_list'>";
     53
    4554                foreach ( (array) $blogs as $details ) {
    4655                        if ( $details['spam'] == 0 && $details['deleted'] == 0 && $details['archived'] == 0 ) {
    4756                                $siteurl = get_blog_option( $details['blog_id'], 'siteurl' );
    48                                 echo "<li>$siteurl</li>";
     57
    4958                                $response = wp_remote_get( trailingslashit( $siteurl ) . "wp-admin/upgrade.php?step=1", array( 'timeout' => 120, 'httpversion' => '1.1' ) );
    50                                 if ( is_wp_error( $response ) )
    51                                         wp_die( "<strong>Warning!</strong> Problem updating {$siteurl}. Your server may not be able to connect to sites running on it.<br /> Error message: <em>" . $response->get_error_message() ."</em>" );
     59                                if ( is_wp_error( $response ) ) {
     60                                        echo '<div class="error inline" style="width:600px;"><p>';
     61                                        _e( "<strong>Warning!</strong> Problem updating {$siteurl}. Your server may not be able to connect to sites running on it.<br /> Error message: <em>" . $response->get_error_message() ."</em>" );
     62                                        echo '</p></div>';
     63                                } else {
     64                                        echo "<li><div class='updated inline' style='width:600px;'><p><strong>" . __('Successful:') . "</strong> $siteurl</p></div></li>";
     65                                }
    5266                                do_action( 'after_mu_upgrade', $response );
    5367                                do_action( 'wpmu_upgrade_site', $details[ 'blog_id' ] );
    5468                        }
    5569                }
    56                 echo "</ul>";
    57                 ?><p><?php _e("If your browser doesn't start loading the next page automatically click this link:"); ?> <a class="button" href="ms-upgrade-network.php?action=upgrade&amp;n=<?php echo ($n + 5) ?>"><?php _e("Next Sites"); ?></a></p>
     70                if ( !$ajax ) {
     71                        echo "</ul>";
     72                ?>
     73               
    5874                <script type='text/javascript'>
    59                 <!--
    60                 function nextpage() {
    61                         location.href = "ms-upgrade-network.php?action=upgrade&n=<?php echo ($n + 5) ?>";
     75                jQuery(document).ready(function($){
     76                        var admin_url = "<?php echo admin_url(); ?>";
     77                        var n = 0;
     78
     79                        function nextsites() {
     80                                n = n + 5;
     81                                nexturl = admin_url + 'ms-upgrade-network.php?action=upgrade&n=' + n;
     82                                jQuery.post(nexturl, function(r) {
     83                                        if ( r == '0' ) {
     84                                                $('ul#site_list').after('<div class="updated inline"><p><strong><?php _e('All Done!'); ?></strong></p></div>');
     85                                                $('div.wrap h2:first').after('<div id="message" class="updated fade"><p><strong><?php _e( 'All Done!' ); ?></strong></p></div>');
     86                                        } else {
     87                                                $('ul#site_list').append(r);
     88                                                nextsites();
     89                                        }
     90                                })
     91                        }
     92                        nextsites();
     93                })
     94                </script>
     95                <?php
    6296                }
    63                 setTimeout( "nextpage()", 250 );
    64                 //-->
    65                 </script><?php
    6697        break;
    6798        case 'show':
    6899        default:
    69100                ?><p><?php _e("You can update all the sites on your network through this page. It works by calling the update script of each site automatically. Hit the link below to update."); ?></p>
    70                 <p><a class="button" href="ms-upgrade-network.php?action=upgrade"><?php _e("Update Network"); ?></a></p><?php
     101                <p><a class="button" href="<?php echo admin_url( 'ms-upgrade-network.php?action=upgrade' ) ?>"><?php _e("Update Network"); ?></a></p><?php
    71102                do_action( 'wpmu_upgrade_page' );
    72103        break;
    73104}
     105
     106if ( !$ajax ) {
     107        include('admin-footer.php');
     108        echo '</div>';
     109}
    74110?>
    75 </div>
    76 
    77 <?php include('admin-footer.php'); ?>