Language Packs: Many many fixes such as:

- Add a "Update Translations" stand-alone button to the updates page
- Shift Language feedback to before update process completion action links & limit the verbosity of output (name + success/errors)
- Simplify/combine the language update descriptive string to only include a plugin/theme name
- Properly handle cache clearing after language updates to prevent langs being repeditively updated
- Display a "All items up to date" string when there's nothing to do
- Reduce the 'Connection Information' from a <h2> to a <h3> to remove duplicate h2's and screen icons from update screens
- Fix the Direct filesystem method not being used for Language updates because WP_LANG_DIR doesn't exist (check it's parent for writable instead)
See #18200, #22704


Built from https://develop.svn.wordpress.org/trunk@25806


git-svn-id: http://core.svn.wordpress.org/trunk@25718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2013-10-16 04:15:09 +00:00
parent 9fe39c464a
commit 1c8e79353a
7 changed files with 237 additions and 81 deletions

View File

@ -6636,6 +6636,14 @@ body.iframe {
height: 98%;
}
/* Upgrader styles, Specific to Language Packs */
.lp-show-latest p {
display: none;
}
.lp-show-latest p:last-child,
.lp-show-latest .lp-error p {
display: block;
}
/* - Only used once or twice in all of WP - deprecate for global style
------------------------------------------------------------------------------*/

File diff suppressed because one or more lines are too long

View File

@ -528,6 +528,58 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
}
}
/**
* Translation Upgrader Skin for WordPress Translation Upgrades.
*
* @package WordPress
* @subpackage Upgrader
* @since 3.7.0
*/
class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
var $language_update = null;
var $done_header = false;
var $display_footer_actions = true;
function __construct( $args = array() ) {
$defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
$args = wp_parse_args( $args, $defaults );
if ( $args['skip_header_footer'] ) {
$this->done_header = true;
$this->display_footer_actions = false;
}
parent::__construct( $args );
}
function before() {
$name = $this->upgrader->get_name_for_update( $this->language_update );
echo '<div class="update-messages lp-show-latest">';
printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h4>', $name, $this->language_update->language );
}
function error( $error ) {
echo '<div class="lp-error">';
parent::error( $error );
echo '</div>';
}
function after() {
echo '</div>';
}
function bulk_footer() {
$update_actions = array();
$update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" title="' . esc_attr__( 'Go to WordPress Updates page' ) . '" target="_parent">' . __( 'Return to WordPress Updates' ) . '</a>';
$update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
if ( $update_actions && $this->display_footer_actions )
$this->feedback( implode( ' | ', $update_actions ) );
parent::footer();
}
}
/**
* Upgrader Skin for Automatic WordPress Upgrades
*

View File

@ -307,14 +307,18 @@ class WP_Upgrader {
$options = wp_parse_args($options, $defaults);
extract($options);
//Connect to the Filesystem first.
$res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
if ( ! $res ) //Mainly for non-connected filesystem.
return false;
if ( ! $is_multi ) // call $this->header separately if running multiple times
$this->skin->header();
// Connect to the Filesystem first.
$res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
// Mainly for non-connected filesystem.
if ( ! $res ) {
if ( ! $is_multi )
$this->skin->footer();
return false;
}
$this->skin->before();
if ( is_wp_error($res) ) {
@ -368,8 +372,10 @@ class WP_Upgrader {
$this->skin->after();
if ( ! $is_multi )
if ( ! $is_multi ) {
do_action( 'upgrader_process_complete', $this, $hook_extra );
$this->skin->footer();
}
return $result;
}
@ -442,7 +448,10 @@ class Plugin_Upgrader extends WP_Upgrader {
'destination' => WP_PLUGIN_DIR,
'clear_destination' => false, // Do not overwrite files.
'clear_working' => true,
'hook_extra' => array()
'hook_extra' => array(
'type' => 'plugin',
'action' => 'install',
)
) );
remove_filter('upgrader_source_selection', array($this, 'check_package') );
@ -453,8 +462,6 @@ class Plugin_Upgrader extends WP_Upgrader {
// Force refresh of plugin update information
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'plugin' ), $package );
return true;
}
@ -490,7 +497,9 @@ class Plugin_Upgrader extends WP_Upgrader {
'clear_destination' => true,
'clear_working' => true,
'hook_extra' => array(
'plugin' => $plugin
'plugin' => $plugin,
'type' => 'plugin',
'action' => 'update',
),
) );
@ -504,8 +513,6 @@ class Plugin_Upgrader extends WP_Upgrader {
// Force refresh of plugin update information
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin' ), $plugin );
return true;
}
@ -587,6 +594,13 @@ class Plugin_Upgrader extends WP_Upgrader {
$this->maintenance_mode(false);
do_action( 'upgrader_process_complete', $this, array(
'action' => 'update',
'type' => 'plugin',
'bulk' => true,
'plugins' => $plugins,
) );
$this->skin->bulk_footer();
$this->skin->footer();
@ -597,8 +611,6 @@ class Plugin_Upgrader extends WP_Upgrader {
// Force refresh of plugin update information
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin', 'bulk' => true ), $plugins );
return $results;
}
@ -814,7 +826,11 @@ class Theme_Upgrader extends WP_Upgrader {
'package' => $package,
'destination' => get_theme_root(),
'clear_destination' => false, //Do not overwrite files.
'clear_working' => true
'clear_working' => true,
'hook_extra' => array(
'type' => 'theme',
'action' => 'install',
),
) );
remove_filter('upgrader_source_selection', array($this, 'check_package') );
@ -826,8 +842,6 @@ class Theme_Upgrader extends WP_Upgrader {
// Refresh the Theme Update information
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'theme' ), $package );
return true;
}
@ -863,7 +877,9 @@ class Theme_Upgrader extends WP_Upgrader {
'clear_destination' => true,
'clear_working' => true,
'hook_extra' => array(
'theme' => $theme
'theme' => $theme,
'type' => 'theme',
'action' => 'update',
),
) );
@ -876,8 +892,6 @@ class Theme_Upgrader extends WP_Upgrader {
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme' ), $theme );
return true;
}
@ -959,6 +973,13 @@ class Theme_Upgrader extends WP_Upgrader {
$this->maintenance_mode(false);
do_action( 'upgrader_process_complete', $this, array(
'action' => 'update',
'type' => 'plugin',
'bulk' => true,
'themes' => $themes,
) );
$this->skin->bulk_footer();
$this->skin->footer();
@ -971,8 +992,6 @@ class Theme_Upgrader extends WP_Upgrader {
// Refresh the Theme Update information
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme', 'bulk' => true ), $themes );
return $results;
}
@ -1073,18 +1092,27 @@ class Theme_Upgrader extends WP_Upgrader {
}
add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3 );
add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
class Language_Pack_Upgrader extends WP_Upgrader {
var $result;
var $bulk = true;
static function async_upgrade( $upgrader, $context, $package ) {
static function async_upgrade( $upgrader = false ) {
// Avoid recursion.
if ( $upgrader instanceof Language_Pack_Upgrader )
if ( $upgrader && $upgrader instanceof Language_Pack_Upgrader )
return;
$lp_upgrader = new Language_Pack_Upgrader( new Headerless_Upgrader_Skin() );
// Nothing to do?
$language_updates = wp_get_translation_updates();
if ( ! $language_updates )
return;
$skin = new Language_Pack_Upgrader_Skin( array(
'skip_header_footer' => true,
) );
$lp_upgrader = new Language_Pack_Upgrader( $skin );
$lp_upgrader->upgrade();
}
@ -1098,24 +1126,37 @@ class Language_Pack_Upgrader extends WP_Upgrader {
$this->strings['process_success'] = __( 'Translation updated successfully.' );
}
function upgrade( $update = false ) {
function upgrade( $update = false, $args = array() ) {
if ( $update )
$update = array( $update );
$results = $this->bulk_upgrade( $update );
$results = $this->bulk_upgrade( $update, $args );
return $results[0];
}
function bulk_upgrade( $language_updates = array() ) {
function bulk_upgrade( $language_updates = array(), $args = array() ) {
global $wp_filesystem;
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$this->upgrade_strings();
if ( ! $language_updates )
$language_updates = wp_get_translation_updates();
if ( empty( $language_updates ) )
if ( empty( $language_updates ) ) {
$this->skin->header();
$this->skin->before();
$this->skin->set_result( true );
$this->skin->feedback( 'up_to_date' );
$this->skin->after();
$this->skin->bulk_footer();
$this->skin->footer();
return true;
}
if ( 'upgrader_process_complete' == current_filter() )
$this->skin->feedback( 'starting_upgrade' );
@ -1145,6 +1186,8 @@ class Language_Pack_Upgrader extends WP_Upgrader {
foreach ( $language_updates as $language_update ) {
$this->skin->language_update = $language_update;
$destination = WP_LANG_DIR;
if ( 'plugin' == $language_update->type )
$destination .= '/plugins';
@ -1175,9 +1218,19 @@ class Language_Pack_Upgrader extends WP_Upgrader {
break;
}
$this->skin->bulk_footer();
$this->skin->footer();
// Clean up our hooks, in case something else does an upgrade on this connection.
remove_filter( 'upgrader_source_selection', array( &$this, 'check_package' ), 10, 2 );
if ( $parsed_args['clear_update_cache'] ) {
wp_clean_themes_cache( true );
wp_clean_plugins_cache( true );
delete_site_transient( 'update_core' );
}
return $results;
}
@ -1206,6 +1259,26 @@ class Language_Pack_Upgrader extends WP_Upgrader {
return $source;
}
function get_name_for_update( $update ) {
switch ( $update->type ) {
case 'core':
return 'WordPress'; // Not translated
break;
case 'theme':
$theme = wp_get_theme( $update->slug );
if ( $theme->exists() )
return $theme->Get( 'Name' );
break;
case 'plugin':
$plugin_data = get_plugins( '/' . $update->slug );
$plugin_data = array_shift( $plugin_data );
if ( $plugin_data )
return $plugin_data['Name'];
break;
}
return '';
}
}
/**
@ -1321,7 +1394,6 @@ class Core_Upgrader extends WP_Upgrader {
}
}
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ), $result );
return $result;
}
@ -1628,42 +1700,8 @@ class WP_Automatic_Upgrader {
$skin->feedback( __( 'Updating plugin: %s' ), $item_name );
break;
case 'language':
if ( 'theme' == $item->type ) {
$theme = wp_get_theme( $item->slug );
$skin->feedback( sprintf(
__( 'Updating the %1$s translation for the %2$s theme' ),
$item->language,
$theme->Get( 'Name' )
) );
$item_name = sprintf(
__( '%1$s translation for the %2$s theme' ),
$item->language,
$theme->Get( 'Name' )
);
} elseif ( 'plugin' == $item->type ) {
$plugin_data = get_plugins( '/' . $item->slug );
$plugin_data = array_shift( $plugin_data );
$skin->feedback( sprintf(
__( 'Updating the %1$s translation for the %2$s plugin' ),
$item->language,
$plugin_data['Name']
) );
$item_name = sprintf(
__( '%1$s translation for the %2$s plugin' ),
$item->language,
$plugin_data['Name']
);
} else {
$skin->feedback( sprintf(
__( 'Updating %s translation' ),
$item->language
) );
$item_name = sprintf(
__( '%s translation' ),
$item->language
);
}
$name = $upgrader->get_name_for_update( $item );
$skin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)&#8230;' ), $name, $item->language ) );
break;
}
@ -1711,7 +1749,7 @@ class WP_Automatic_Upgrader {
return;
// Don't automatically run these thins, as we'll handle it ourselves
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3 );
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
remove_action( 'upgrader_process_complete', 'wp_version_check' );
remove_action( 'upgrader_process_complete', 'wp_update_plugins' );
remove_action( 'upgrader_process_complete', 'wp_update_themes' );

View File

@ -891,6 +891,11 @@ function get_filesystem_method($args = array(), $context = false) {
if ( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
if ( !$context )
$context = WP_CONTENT_DIR;
// If the directory doesn't exist (wp-content/languages) then use the parent directory as we'll create it.
if ( WP_LANG_DIR == $context && ! is_dir( $context ) )
$context = dirname( $context );
$context = trailingslashit($context);
$temp_file_name = $context . 'temp-write-test-' . time();
$temp_handle = @fopen($temp_file_name, 'w');
@ -1021,9 +1026,8 @@ jQuery(function($){
-->
</script>
<form action="<?php echo esc_url( $form_post ) ?>" method="post">
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php _e('Connection Information') ?></h2>
<div>
<h3><?php _e('Connection Information') ?></h3>
<p><?php
$label_user = __('Username');
$label_pass = __('Password');

View File

@ -889,6 +889,9 @@ function update_core($from, $to) {
// Remove maintenance file, we're done.
$wp_filesystem->delete($maintenance_file);
// Has to be in here, rather than the Upgrader as the filter below will override and kill the process before themes get updated on major updates
do_action( 'upgrader_process_complete', null, array( 'action' => 'update', 'type' => 'core' ) );
// If we made it this far:
do_action( '_core_updated_successfully', $wp_version );

View File

@ -324,6 +324,27 @@ function list_theme_updates() {
<?php
}
function list_translation_updates() {
$updates = wp_get_translation_updates();
if ( ! $updates ) {
if ( 'en_US' != get_locale() ) {
echo '<h3>' . __( 'Translations' ) . '</h3>';
echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
}
return;
}
$form_action = 'update-core.php?action=do-translation-upgrade';
?>
<h3><?php _e( 'Translations' ); ?></h3>
<form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
<p><?php _e( 'Some of your translations are out of date.' ); ?></p>
<?php wp_nonce_field('upgrade-translations'); ?>
<p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
</form>
<?php
}
/**
* Upgrade WordPress core display.
*
@ -341,8 +362,6 @@ function do_core_upgrade( $reinstall = false ) {
else
$url = 'update-core.php?action=do-core-upgrade';
$url = wp_nonce_url($url, 'upgrade-core');
if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) )
return;
$version = isset( $_POST['version'] )? $_POST['version'] : false;
$locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
@ -350,15 +369,24 @@ function do_core_upgrade( $reinstall = false ) {
if ( !$update )
return;
if ( ! WP_Filesystem($credentials, ABSPATH) ) {
request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
return;
}
?>
<div class="wrap">
<?php screen_icon('tools'); ?>
<h2><?php _e('Update WordPress'); ?></h2>
<?php
if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH ) ) ) {
echo '</div>';
return;
}
if ( ! WP_Filesystem( $credentials, ABSPATH ) ) {
// Failed to connect, Error and request again
request_filesystem_credentials( $url, '', true, ABSPATH );
echo '</div>';
return;
}
if ( $wp_filesystem->errors->get_error_code() ) {
foreach ( $wp_filesystem->errors->get_error_messages() as $message )
show_message($message);
@ -477,12 +505,15 @@ if ( 'upgrade-core' == $action ) {
echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url('update-core.php') ) . '">' . __( 'Check Again' ) . '</a>';
echo '</p>';
if ( current_user_can( 'update_core' ) )
if ( $core = current_user_can( 'update_core' ) )
core_upgrade_preamble();
if ( current_user_can( 'update_plugins' ) )
if ( $plugins = current_user_can( 'update_plugins' ) )
list_plugin_updates();
if ( current_user_can( 'update_themes' ) )
if ( $themes = current_user_can( 'update_themes' ) )
list_theme_updates();
if ( $core || $plugins || $themes )
list_translation_updates();
unset( $core, $plugins, $themes );
do_action('core_upgrade_preamble');
echo '</div>';
include(ABSPATH . 'wp-admin/admin-footer.php');
@ -570,6 +601,26 @@ if ( 'upgrade-core' == $action ) {
echo '</div>';
include(ABSPATH . 'wp-admin/admin-footer.php');
} elseif ( 'do-translation-upgrade' == $action ) {
if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) )
wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
check_admin_referer( 'upgrade-translations' );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
$url = 'update-core.php?action=do-translation-upgrade';
$nonce = 'upgrade-translations';
$title = __( 'Update Translations' );
$context = WP_LANG_DIR;
$upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
$result = $upgrader->bulk_upgrade();
require_once( ABSPATH . 'wp-admin/admin-footer.php' );
} else {
do_action('update-core-custom_' . $action);
}