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

git-svn-id: http://svn.automattic.com/wordpress/trunk@13602 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-03-06 08:39:50 +00:00
parent a9642826f3
commit f3af366e3d
5 changed files with 178 additions and 58 deletions

View File

@ -297,6 +297,7 @@ class WP_Upgrader {
$download = $this->download_package( $package );
if ( is_wp_error($download) ) {
$this->skin->error($download);
$this->skin->after();
return $download;
}
@ -304,6 +305,7 @@ class WP_Upgrader {
$working_dir = $this->unpack_package( $download );
if ( is_wp_error($working_dir) ) {
$this->skin->error($working_dir);
$this->skin->after();
return $working_dir;
}
@ -409,6 +411,7 @@ class Plugin_Upgrader extends WP_Upgrader {
$current = get_site_transient( 'update_plugins' );
if ( !isset( $current->response[ $plugin ] ) ) {
$this->skin->before();
$this->skin->set_result(false);
$this->skin->error('up_to_date');
$this->skin->after();
@ -466,15 +469,15 @@ class Plugin_Upgrader extends WP_Upgrader {
$results = array();
$all = count($plugins);
$i = 1;
$this->plugin_count = count($plugins);
$this->plugin_current = 0;
foreach ( $plugins as $plugin ) {
$this->show_before = sprintf( '<h4>' . __('Updating plugin %1$d of %2$d&#8230;') . '</h4>', $i, $all );
$i++;
$this->plugin_current++;
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
if ( !isset( $current->response[ $plugin ] ) ) {
$this->skin->set_result(false);
$this->skin->before();
$this->skin->error('up_to_date');
$this->skin->after();
$results[$plugin] = false;
@ -502,7 +505,7 @@ class Plugin_Upgrader extends WP_Upgrader {
// Prevent credentials auth screen from displaying multiple times
if ( false === $result )
break;
}
} //end foreach $plugins
$this->maintenance_mode(false);
$this->skin->footer();
@ -645,6 +648,7 @@ class Theme_Upgrader extends WP_Upgrader {
// Is an update available?
$current = get_site_transient( 'update_themes' );
if ( !isset( $current->response[ $theme ] ) ) {
$this->skin->before();
$this->skin->set_result(false);
$this->skin->error('up_to_date');
$this->skin->after();
@ -910,9 +914,6 @@ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
}
function after() {
if ( $this->upgrader->bulk )
return;
$this->plugin = $this->upgrader->plugin_info();
if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
show_message(__('Reactivating the plugin&#8230;'));
@ -941,6 +942,103 @@ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
}
}
/**
* Plugin Upgrader Skin for WordPress Plugin Upgrades.
*
* @package WordPress
* @subpackage Upgrader
* @since 3.0
*/
class Bulk_Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
var $in_loop = false;
var $error = false;
function Plugin_Upgrader_Skin($args = array()) {
return $this->__construct($args);
}
function __construct($args = array()) {
$defaults = array( 'url' => '', 'nonce' => '' );
$args = wp_parse_args($args, $defaults);
parent::__construct($args);
}
function feedback($string) {
if ( isset( $this->upgrader->strings[$string] ) )
$string = $this->upgrader->strings[$string];
if ( strpos($string, '%') !== false ) {
$args = func_get_args();
$args = array_splice($args, 1);
if ( !empty($args) )
$string = vsprintf($string, $args);
}
if ( empty($string) )
return;
if ( $this->in_loop )
echo "$string<br />\n";
else
echo "<p>$string</p>\n";
}
function header() {
// Nothing, This will be displayed within a iframe.
}
function footer() {
// Nothing, This will be displayed within a iframe.
}
function error($error) {
if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
$this->error = $this->upgrader->strings[$error];
if ( is_wp_error($error) && $error->get_error_code() ) {
foreach ( $error->get_error_messages() as $emessage ) {
if ( $error->get_error_data() )
$messages[] = $emessage . ' ' . $error->get_error_data();
else
$messages[] = $emessage;
}
$this->error = implode(', ', $messages);
}
}
function before() {
$this->in_loop = true;
printf( '<h4>' . __('Updating Plugin %1$s (%2$d/%3$d)') . '</h4>', $this->plugin_info['Title'], $this->upgrader->plugin_current, $this->upgrader->plugin_count);
echo '<div class="update-messages" style="display:none" id="progress-' . esc_attr($this->upgrader->plugin_current) . '"><p>';
$this->flush_output();
}
function after() {
echo '</p></div>';
if ( $this->error || ! $this->result ) {
if ( $this->error )
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>';
else
echo '<div class="error"><p>' . sprintf(__('The update of %1$s failed.'), $this->plugin_info['Title']) . '</p></div>';
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->plugin_current) . '\').show();</script>';
}
if ( !empty($this->result) && !is_wp_error($this->result) ) {
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>';
}
$this->reset();
$this->flush_output();
}
function reset() {
$this->in_loop = false;
$this->error = false;
}
function flush_output() {
wp_ob_end_flush_all();
flush();
}
}
/**
* Plugin Installer Skin for WordPress Plugin Installer.
*

View File

@ -271,6 +271,8 @@ function show_message($message) {
$message = $message->get_error_message();
}
echo "<p>$message</p>\n";
wp_ob_end_flush_all();
flush();
}
function wp_doc_link_parse( $content ) {

View File

@ -96,8 +96,6 @@ if ( !empty($action) ) {
exit;
break;
case 'update-selected' :
if ( ! current_user_can( 'update_plugins' ) )
wp_die( __( 'You do not have sufficient permissions to update plugins for this blog.' ) );
check_admin_referer( 'bulk-manage-plugins' );
@ -106,34 +104,23 @@ if ( !empty($action) ) {
elseif ( isset( $_POST['checked'] ) )
$plugins = (array) $_POST['checked'];
else
break;
$plugins = array();
if ( empty( $plugins ) )
break;
// We'll be passing all checked plugins as long as at least one is out of date.
$_plugins = $plugins;
$current = get_site_transient( 'update_plugins' );
foreach ( $_plugins as $k => $v ) {
if ( ! isset( $current->response[ $v ] ) )
unset( $_plugins[ $k ] );
}
unset( $current );
// If all checked plugins are up to date
if ( empty( $_plugins ) )
break;
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
require_once( 'admin-header.php' );
$url = 'plugins.php?action=upgrade-selected&amp;plugins=' . urlencode( join( ',', $plugins ) );
$title = __( 'Upgrade Plugins' );
$nonce = 'bulk-manage-plugins';
$parent_file = 'plugins.php';
$upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) );
$upgrader->bulk_upgrade( $plugins );
require_once( 'admin-header.php' );
echo '<div class="wrap">';
screen_icon();
echo '<h2>' . esc_html( $title ) . '</h2>';
$url = 'update.php?action=update-selected&amp;plugins=' . urlencode( join(',', $plugins) );
$url = wp_nonce_url($url, 'bulk-update-plugins');
echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
echo '</div>';
require_once( 'admin-footer.php' );
exit;
break;

View File

@ -351,24 +351,6 @@ function no_update_actions($actions) {
return '';
}
function do_plugin_upgrade() {
if ( isset( $_GET['plugins'] ) ) {
$plugins = explode( ',', $_GET['plugins'] );
} elseif ( isset( $_POST['checked'] ) ) {
$plugins = (array) $_POST['checked'];
} else {
// Nothing to do.
return;
}
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$url = 'update-core.php?action=do-plugin-upgrade&amp;plugins=' . urlencode( implode( ',', $plugins ) );
$title = __( 'Upgrade Plugins' );
$nonce = 'upgrade-core';
$upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) );
$upgrader->bulk_upgrade( $plugins );
}
$action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
$upgrade_error = false;
@ -386,23 +368,46 @@ if ( 'upgrade-core' == $action ) {
core_upgrade_preamble();
} elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
check_admin_referer('upgrade-core');
// do the (un)dismiss actions before headers,
// so that they can redirect
if ( isset( $_POST['dismiss'] ) )
do_dismiss_core_update();
elseif ( isset( $_POST['undismiss'] ) )
do_undismiss_core_update();
do_undismiss_core_update();
require_once('admin-header.php');
if ( 'do-core-reinstall' == $action )
$reinstall = true;
else
$reinstall = false;
if ( isset( $_POST['upgrade'] ) )
do_core_upgrade($reinstall);
} elseif ( 'do-plugin-upgrade' == $action ) {
check_admin_referer('upgrade-core');
if ( isset( $_GET['plugins'] ) ) {
$plugins = explode( ',', $_GET['plugins'] );
} elseif ( isset( $_POST['checked'] ) ) {
$plugins = (array) $_POST['checked'];
} else {
wp_redirect('plugins.php');
exit;
}
$url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
$url = wp_nonce_url($url, 'bulk-update-plugins');
$title = __('Update Plugins');
require_once('admin-header.php');
do_plugin_upgrade();
echo '<div class="wrap">';
screen_icon('plugins');
echo '<h2>' . esc_html__('Update Plugins') . '</h2>';
echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
echo '</div>';
}
include('admin-footer.php');

View File

@ -16,7 +16,35 @@ if ( isset($_GET['action']) ) {
$theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
if ( 'upgrade-plugin' == $action ) {
if ( 'update-selected' == $action ) {
if ( ! current_user_can( 'update_plugins' ) )
wp_die( __( 'You do not have sufficient permissions to update plugins for this blog.' ) );
check_admin_referer( 'bulk-update-plugins' );
if ( isset( $_GET['plugins'] ) )
$plugins = explode( ',', stripslashes($_GET['plugins']) );
elseif ( isset( $_POST['checked'] ) )
$plugins = (array) $_POST['checked'];
else
$plugins = array();
$plugins = array_map('urldecode', $plugins);
$url = 'update.php?action=update-selected&amp;plugins=' . urlencode(implode(',', $plugins));
$nonce = 'bulk-update-plugins';
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
wp_enqueue_script('jquery');
iframe_header();
$upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
$upgrader->bulk_upgrade( $plugins );
iframe_footer();
exit;
} elseif ( 'upgrade-plugin' == $action ) {
if ( ! current_user_can('update_plugins') )
wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));