From ddaaa6d88a880c56b56d891466d217ff3fa281ca Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 16 Oct 2013 04:14:29 +0000 Subject: [PATCH] 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

to a

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 git-svn-id: https://develop.svn.wordpress.org/trunk@25806 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/wp-admin.css | 8 + .../includes/class-wp-upgrader-skins.php | 52 ++++++ src/wp-admin/includes/class-wp-upgrader.php | 174 +++++++++++------- src/wp-admin/includes/file.php | 10 +- src/wp-admin/includes/update-core.php | 3 + src/wp-admin/update-core.php | 69 ++++++- 6 files changed, 236 insertions(+), 80 deletions(-) diff --git a/src/wp-admin/css/wp-admin.css b/src/wp-admin/css/wp-admin.css index 5cbc8fd88e..ff26406f68 100644 --- a/src/wp-admin/css/wp-admin.css +++ b/src/wp-admin/css/wp-admin.css @@ -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 ------------------------------------------------------------------------------*/ diff --git a/src/wp-admin/includes/class-wp-upgrader-skins.php b/src/wp-admin/includes/class-wp-upgrader-skins.php index a532db201f..48d7ce75dd 100644 --- a/src/wp-admin/includes/class-wp-upgrader-skins.php +++ b/src/wp-admin/includes/class-wp-upgrader-skins.php @@ -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 '
'; + + printf( '

' . __( 'Updating translations for %1$s (%2$s)…' ) . '

', $name, $this->language_update->language ); + } + + function error( $error ) { + echo '
'; + parent::error( $error ); + echo '
'; + } + + function after() { + echo '
'; + } + + function bulk_footer() { + $update_actions = array(); + $update_actions['updates_page'] = '' . __( 'Return to WordPress Updates' ) . ''; + $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 * diff --git a/src/wp-admin/includes/class-wp-upgrader.php b/src/wp-admin/includes/class-wp-upgrader.php index 459a30749c..8e181686df 100644 --- a/src/wp-admin/includes/class-wp-upgrader.php +++ b/src/wp-admin/includes/class-wp-upgrader.php @@ -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)…' ), $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' ); diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index 7407a2b131..3f0455caea 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -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($){ -->
-
- -

+
+

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 ); diff --git a/src/wp-admin/update-core.php b/src/wp-admin/update-core.php index 39cf45a167..8fb3bf428d 100644 --- a/src/wp-admin/update-core.php +++ b/src/wp-admin/update-core.php @@ -324,6 +324,27 @@ function list_theme_updates() { ' . __( 'Translations' ) . '

'; + echo '

' . __( 'Your translations are all up to date.' ) . '

'; + } + return; + } + + $form_action = 'update-core.php?action=do-translation-upgrade'; + ?> +

+ +

+ +

+ +

'; + return; + } + + if ( ! WP_Filesystem( $credentials, ABSPATH ) ) { + // Failed to connect, Error and request again + request_filesystem_credentials( $url, '', true, ABSPATH ); + echo '
'; + 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 '   ' . __( 'Check Again' ) . ''; echo '

'; - 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 ''; include(ABSPATH . 'wp-admin/admin-footer.php'); @@ -570,6 +601,26 @@ if ( 'upgrade-core' == $action ) { echo ''; 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); }