Make WordPress Core

Changeset 13602


Ignore:
Timestamp:
03/06/2010 08:39:50 AM (15 years ago)
Author:
dd32
Message:

First scrape at new UI for Bulk plugin upgrades. See #11232

Location:
trunk/wp-admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-upgrader.php

    r13089 r13602  
    298298        if ( is_wp_error($download) ) {
    299299            $this->skin->error($download);
     300            $this->skin->after();
    300301            return $download;
    301302        }
     
    305306        if ( is_wp_error($working_dir) ) {
    306307            $this->skin->error($working_dir);
     308            $this->skin->after();
    307309            return $working_dir;
    308310        }
     
    410412        $current = get_site_transient( 'update_plugins' );
    411413        if ( !isset( $current->response[ $plugin ] ) ) {
     414            $this->skin->before();
    412415            $this->skin->set_result(false);
    413416            $this->skin->error('up_to_date');
     
    467470        $results = array();
    468471
    469         $all = count($plugins);
    470         $i = 1;
     472        $this->plugin_count = count($plugins);
     473        $this->plugin_current = 0;
    471474        foreach ( $plugins as $plugin ) {
    472 
    473             $this->show_before = sprintf( '<h4>' . __('Updating plugin %1$d of %2$d&#8230;') . '</h4>', $i, $all );
    474             $i++;
     475            $this->plugin_current++;
     476            $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
    475477
    476478            if ( !isset( $current->response[ $plugin ] ) ) {
    477479                $this->skin->set_result(false);
     480                $this->skin->before();
    478481                $this->skin->error('up_to_date');
    479482                $this->skin->after();
     
    503506            if ( false === $result )
    504507                break;
    505         }
     508        } //end foreach $plugins
    506509        $this->maintenance_mode(false);
    507510        $this->skin->footer();
     
    646649        $current = get_site_transient( 'update_themes' );
    647650        if ( !isset( $current->response[ $theme ] ) ) {
     651            $this->skin->before();
    648652            $this->skin->set_result(false);
    649653            $this->skin->error('up_to_date');
     
    911915
    912916    function after() {
    913         if ( $this->upgrader->bulk )
    914             return;
    915 
    916917        $this->plugin = $this->upgrader->plugin_info();
    917918        if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
     
    943944
    944945/**
     946 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
     947 *
     948 * @package WordPress
     949 * @subpackage Upgrader
     950 * @since 3.0
     951 */
     952class Bulk_Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
     953    var $in_loop = false;
     954    var $error = false;
     955
     956    function Plugin_Upgrader_Skin($args = array()) {
     957        return $this->__construct($args);
     958    }
     959
     960    function __construct($args = array()) {
     961        $defaults = array( 'url' => '', 'nonce' => '' );
     962        $args = wp_parse_args($args, $defaults);
     963
     964        parent::__construct($args);
     965    }
     966   
     967    function feedback($string) {
     968        if ( isset( $this->upgrader->strings[$string] ) )
     969            $string = $this->upgrader->strings[$string];
     970
     971        if ( strpos($string, '%') !== false ) {
     972            $args = func_get_args();
     973            $args = array_splice($args, 1);
     974            if ( !empty($args) )
     975                $string = vsprintf($string, $args);
     976        }
     977        if ( empty($string) )
     978            return;
     979        if ( $this->in_loop )
     980            echo "$string<br />\n";
     981        else
     982            echo "<p>$string</p>\n";
     983    }
     984
     985    function header() {
     986        // Nothing, This will be displayed within a iframe.
     987    }
     988
     989    function footer() {
     990        // Nothing, This will be displayed within a iframe.
     991    }
     992    function error($error) {
     993        if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
     994            $this->error = $this->upgrader->strings[$error];
     995       
     996        if ( is_wp_error($error) && $error->get_error_code() ) {
     997            foreach ( $error->get_error_messages() as $emessage ) {
     998                if ( $error->get_error_data() )
     999                    $messages[] = $emessage . ' ' . $error->get_error_data();
     1000                else
     1001                    $messages[] = $emessage;
     1002            }
     1003            $this->error = implode(', ', $messages);
     1004        }
     1005    }
     1006
     1007    function before() {
     1008        $this->in_loop = true;
     1009        printf( '<h4>' . __('Updating Plugin %1$s (%2$d/%3$d)') . '</h4>',  $this->plugin_info['Title'], $this->upgrader->plugin_current, $this->upgrader->plugin_count);
     1010        echo '<div class="update-messages" style="display:none" id="progress-' . esc_attr($this->upgrader->plugin_current) . '"><p>';
     1011        $this->flush_output();
     1012    }
     1013
     1014    function after() {
     1015        echo '</p></div>';
     1016        if ( $this->error || ! $this->result ) {
     1017            if ( $this->error )
     1018                echo '<div class="error"><p>' . sprintf(__('An error occured while updating %1$s: <strong>%2$s</strong>.'), $this->plugin_info['Title'], $this->error) . '</p></div>';
     1019            else
     1020                echo '<div class="error"><p>' . sprintf(__('The update of %1$s failed.'), $this->plugin_info['Title']) . '</p></div>';
     1021            echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->plugin_current) . '\').show();</script>';
     1022        }
     1023        if ( !empty($this->result) && !is_wp_error($this->result) ) {
     1024            echo '<div class="updated"><p>' . sprintf(__('%1$s updated successfully. <a onclick="%2$s" href="#">See Details</a>.'), $this->plugin_info['Title'], 'jQuery(\'#progress-' . esc_js($this->upgrader->plugin_current) . '\').toggle(); return false;') . '</p></div>';
     1025        }
     1026        $this->reset();
     1027        $this->flush_output();
     1028    }
     1029
     1030    function reset() {
     1031        $this->in_loop = false;
     1032        $this->error = false;
     1033    }
     1034
     1035    function flush_output() {
     1036        wp_ob_end_flush_all();
     1037        flush();
     1038    }
     1039
     1040}
     1041
     1042/**
    9451043 * Plugin Installer Skin for WordPress Plugin Installer.
    9461044 *
  • trunk/wp-admin/includes/misc.php

    r13487 r13602  
    272272    }
    273273    echo "<p>$message</p>\n";
     274    wp_ob_end_flush_all();
     275    flush();
    274276}
    275277
  • trunk/wp-admin/plugins.php

    r13499 r13602  
    9797            break;
    9898        case 'update-selected' :
    99             if ( ! current_user_can( 'update_plugins' ) )
    100                 wp_die( __( 'You do not have sufficient permissions to update plugins for this blog.' ) );
    101 
     99       
    102100            check_admin_referer( 'bulk-manage-plugins' );
    103 
     101           
    104102            if ( isset( $_GET['plugins'] ) )
    105103                $plugins = explode( ',', $_GET['plugins'] );
     
    107105                $plugins = (array) $_POST['checked'];
    108106            else
    109                 break;
    110 
    111             if ( empty( $plugins ) )
    112                 break;
    113 
    114             // We'll be passing all checked plugins as long as at least one is out of date.
    115             $_plugins = $plugins;
    116             $current = get_site_transient( 'update_plugins' );
    117             foreach ( $_plugins as $k => $v ) {
    118                 if ( ! isset( $current->response[ $v ] ) )
    119                     unset( $_plugins[ $k ] );
    120             }
    121             unset( $current );
    122             // If all checked plugins are up to date
    123             if ( empty( $_plugins ) )
    124                 break;
    125 
    126             require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
     107                $plugins = array();
     108           
     109            $title = __( 'Upgrade Plugins' );
     110            $parent_file = 'plugins.php';
     111
    127112            require_once( 'admin-header.php' );
    128 
    129             $url = 'plugins.php?action=upgrade-selected&amp;plugins=' . urlencode( join( ',', $plugins ) );
    130             $title = __( 'Upgrade Plugins' );
    131             $nonce = 'bulk-manage-plugins';
    132             $parent_file = 'plugins.php';
    133 
    134             $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) );
    135             $upgrader->bulk_upgrade( $plugins );
    136 
     113           
     114            echo '<div class="wrap">';
     115            screen_icon();
     116            echo '<h2>' . esc_html( $title ) . '</h2>';
     117
     118
     119            $url = 'update.php?action=update-selected&amp;plugins=' . urlencode( join(',', $plugins) );
     120            $url = wp_nonce_url($url, 'bulk-update-plugins');
     121
     122            echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
     123            echo '</div>';
    137124            require_once( 'admin-footer.php' );
    138125            exit;
  • trunk/wp-admin/update-core.php

    r13590 r13602  
    352352}
    353353
    354 function do_plugin_upgrade() {
    355     if ( isset( $_GET['plugins'] ) ) {
    356         $plugins = explode( ',', $_GET['plugins'] );
    357     } elseif ( isset( $_POST['checked'] ) ) {
    358         $plugins = (array) $_POST['checked'];
    359     } else {
    360         // Nothing to do.
    361         return;
    362     }
    363 
    364     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    365     $url = 'update-core.php?action=do-plugin-upgrade&amp;plugins=' . urlencode( implode( ',', $plugins ) );
    366     $title = __( 'Upgrade Plugins' );
    367     $nonce = 'upgrade-core';
    368     $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) );
    369     $upgrader->bulk_upgrade( $plugins );
    370 }
    371 
    372354$action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
    373355
     
    387369} elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
    388370    check_admin_referer('upgrade-core');
     371
    389372    // do the (un)dismiss actions before headers,
    390373    // so that they can redirect
     
    392375        do_dismiss_core_update();
    393376    elseif ( isset( $_POST['undismiss'] ) )
    394     do_undismiss_core_update();
     377        do_undismiss_core_update();
     378
    395379    require_once('admin-header.php');
    396380    if ( 'do-core-reinstall' == $action )
     
    398382    else
    399383        $reinstall = false;
     384
    400385    if ( isset( $_POST['upgrade'] ) )
    401386        do_core_upgrade($reinstall);
     387
    402388} elseif ( 'do-plugin-upgrade' == $action ) {
    403389    check_admin_referer('upgrade-core');
     390
     391    if ( isset( $_GET['plugins'] ) ) {
     392        $plugins = explode( ',', $_GET['plugins'] );
     393    } elseif ( isset( $_POST['checked'] ) ) {
     394        $plugins = (array) $_POST['checked'];
     395    } else {
     396        wp_redirect('plugins.php');
     397        exit;
     398    }
     399
     400    $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
     401    $url = wp_nonce_url($url, 'bulk-update-plugins');
     402
     403    $title = __('Update Plugins');
     404
    404405    require_once('admin-header.php');
    405     do_plugin_upgrade();
     406    echo '<div class="wrap">';
     407    screen_icon('plugins');
     408    echo '<h2>' . esc_html__('Update Plugins') . '</h2>';
     409    echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
     410    echo '</div>';
    406411}
    407412
  • trunk/wp-admin/update.php

    r13499 r13602  
    1717    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    1818
    19     if ( 'upgrade-plugin' == $action ) {
     19    if ( 'update-selected' == $action ) {
     20        if ( ! current_user_can( 'update_plugins' ) )
     21            wp_die( __( 'You do not have sufficient permissions to update plugins for this blog.' ) );
     22
     23        check_admin_referer( 'bulk-update-plugins' );
     24
     25        if ( isset( $_GET['plugins'] ) )
     26            $plugins = explode( ',', stripslashes($_GET['plugins']) );
     27        elseif ( isset( $_POST['checked'] ) )
     28            $plugins = (array) $_POST['checked'];
     29        else
     30            $plugins = array();
     31
     32        $plugins = array_map('urldecode', $plugins);
     33
     34        $url = 'update.php?action=update-selected&amp;plugins=' . urlencode(implode(',', $plugins));
     35        $nonce = 'bulk-update-plugins';
     36
     37        require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
     38        wp_enqueue_script('jquery');
     39        iframe_header();
     40
     41        $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
     42        $upgrader->bulk_upgrade( $plugins );
     43
     44        iframe_footer();
     45        exit;
     46           
     47    } elseif ( 'upgrade-plugin' == $action ) {
    2048        if ( ! current_user_can('update_plugins') )
    2149            wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
Note: See TracChangeset for help on using the changeset viewer.