Make WordPress Core

Changeset 25806


Ignore:
Timestamp:
10/16/2013 04:14:29 AM (13 years ago)
Author:
dd32
Message:

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

Location:
trunk/src/wp-admin
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/wp-admin.css

    r25771 r25806  
    66376637}
    66386638
     6639/* Upgrader styles, Specific to Language Packs */
     6640.lp-show-latest p {
     6641        display: none;
     6642}
     6643.lp-show-latest p:last-child,
     6644.lp-show-latest .lp-error p {
     6645        display: block;
     6646}
    66396647
    66406648/* - Only used once or twice in all of WP - deprecate for global style
  • trunk/src/wp-admin/includes/class-wp-upgrader-skins.php

    r25775 r25806  
    530530
    531531/**
     532 * Translation Upgrader Skin for WordPress Translation Upgrades.
     533 *
     534 * @package WordPress
     535 * @subpackage Upgrader
     536 * @since 3.7.0
     537 */
     538class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
     539        var $language_update = null;
     540        var $done_header = false;
     541        var $display_footer_actions = true;
     542
     543        function __construct( $args = array() ) {
     544                $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
     545                $args = wp_parse_args( $args, $defaults );
     546                if ( $args['skip_header_footer'] ) {
     547                        $this->done_header = true;
     548                        $this->display_footer_actions = false;
     549                }
     550                parent::__construct( $args );
     551        }
     552
     553        function before() {
     554                $name = $this->upgrader->get_name_for_update( $this->language_update );
     555
     556                echo '<div class="update-messages lp-show-latest">';
     557
     558                printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h4>', $name, $this->language_update->language );
     559        }
     560
     561        function error( $error ) {
     562                echo '<div class="lp-error">';
     563                parent::error( $error );
     564                echo '</div>';
     565        }
     566
     567        function after() {
     568                echo '</div>';
     569        }
     570
     571        function bulk_footer() {
     572                $update_actions = array();
     573                $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>';
     574                $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
     575
     576                if ( $update_actions && $this->display_footer_actions )
     577                        $this->feedback( implode( ' | ', $update_actions ) );
     578
     579                parent::footer();
     580        }
     581}
     582
     583/**
    532584 * Upgrader Skin for Automatic WordPress Upgrades
    533585 *
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r25801 r25806  
    308308                extract($options);
    309309
    310                 //Connect to the Filesystem first.
    311                 $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
    312                 if ( ! $res ) //Mainly for non-connected filesystem.
    313                         return false;
    314 
    315310                if ( ! $is_multi ) // call $this->header separately if running multiple times
    316311                        $this->skin->header();
     312
     313                // Connect to the Filesystem first.
     314                $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
     315                // Mainly for non-connected filesystem.
     316                if ( ! $res ) {
     317                        if ( ! $is_multi )
     318                                $this->skin->footer();
     319                        return false;
     320                }
    317321
    318322                $this->skin->before();
    … …  
    369373                $this->skin->after();
    370374
    371                 if ( ! $is_multi )
     375                if ( ! $is_multi ) {
     376                        do_action( 'upgrader_process_complete', $this, $hook_extra );
    372377                        $this->skin->footer();
     378                }
    373379
    374380                return $result;
    … …  
    443449                        'clear_destination' => false, // Do not overwrite files.
    444450                        'clear_working' => true,
    445                         'hook_extra' => array()
     451                        'hook_extra' => array(
     452                                'type' => 'plugin',
     453                                'action' => 'install',
     454                        )
    446455                ) );
    447456
    … …  
    453462                // Force refresh of plugin update information
    454463                wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
    455 
    456                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'plugin' ), $package );
    457464
    458465                return true;
    … …  
    491498                        'clear_working' => true,
    492499                        'hook_extra' => array(
    493                                 'plugin' => $plugin
     500                                'plugin' => $plugin,
     501                                'type' => 'plugin',
     502                                'action' => 'update',
    494503                        ),
    495504                ) );
    … …  
    504513                // Force refresh of plugin update information
    505514                wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
    506 
    507                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin' ), $plugin );
    508515
    509516                return true;
    … …  
    588595                $this->maintenance_mode(false);
    589596
     597                do_action( 'upgrader_process_complete', $this, array(
     598                        'action' => 'update',
     599                        'type' => 'plugin',
     600                        'bulk' => true,
     601                        'plugins' => $plugins,
     602                ) );
     603
    590604                $this->skin->bulk_footer();
    591605
    … …  
    597611                // Force refresh of plugin update information
    598612                wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
    599 
    600                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin', 'bulk' => true ), $plugins );
    601613
    602614                return $results;
    … …  
    815827                        'destination' => get_theme_root(),
    816828                        'clear_destination' => false, //Do not overwrite files.
    817                         'clear_working' => true
     829                        'clear_working' => true,
     830                        'hook_extra' => array(
     831                                'type' => 'theme',
     832                                'action' => 'install',
     833                        ),
    818834                ) );
    819835
    … …  
    826842                // Refresh the Theme Update information
    827843                wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
    828 
    829                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'theme' ), $package );
    830844
    831845                return true;
    … …  
    864878                        'clear_working' => true,
    865879                        'hook_extra' => array(
    866                                 'theme' => $theme
     880                                'theme' => $theme,
     881                                'type' => 'theme',
     882                                'action' => 'update',
    867883                        ),
    868884                ) );
    … …  
    876892
    877893                wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
    878 
    879                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme' ), $theme );
    880894
    881895                return true;
    … …  
    960974                $this->maintenance_mode(false);
    961975
     976                do_action( 'upgrader_process_complete', $this, array(
     977                        'action' => 'update',
     978                        'type' => 'plugin',
     979                        'bulk' => true,
     980                        'themes' => $themes,
     981                ) );
     982
    962983                $this->skin->bulk_footer();
    963984
    … …  
    971992                // Refresh the Theme Update information
    972993                wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
    973 
    974                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme', 'bulk' => true ), $themes );
    975994
    976995                return $results;
    … …  
    10741093}
    10751094
    1076 add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3 );
     1095add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
    10771096class Language_Pack_Upgrader extends WP_Upgrader {
    10781097
    … …  
    10801099        var $bulk = true;
    10811100
    1082         static function async_upgrade( $upgrader, $context, $package ) {
     1101        static function async_upgrade( $upgrader = false ) {
    10831102                // Avoid recursion.
    1084                 if ( $upgrader instanceof Language_Pack_Upgrader )
     1103                if ( $upgrader && $upgrader instanceof Language_Pack_Upgrader )
    10851104                        return;
    10861105
    1087                 $lp_upgrader = new Language_Pack_Upgrader( new Headerless_Upgrader_Skin() );
     1106                // Nothing to do?
     1107                $language_updates = wp_get_translation_updates();
     1108                if ( ! $language_updates )
     1109                        return;
     1110
     1111                $skin = new Language_Pack_Upgrader_Skin( array(
     1112                        'skip_header_footer' => true,
     1113                ) );
     1114
     1115                $lp_upgrader = new Language_Pack_Upgrader( $skin );
    10881116                $lp_upgrader->upgrade();
    10891117        }
    … …  
    10991127        }
    11001128
    1101         function upgrade( $update = false ) {
     1129        function upgrade( $update = false, $args = array() ) {
    11021130                if ( $update )
    11031131                        $update = array( $update );
    1104                 $results = $this->bulk_upgrade( $update );
     1132                $results = $this->bulk_upgrade( $update, $args );
    11051133                return $results[0];
    11061134        }
    11071135
    1108         function bulk_upgrade( $language_updates = array() ) {
     1136        function bulk_upgrade( $language_updates = array(), $args = array() ) {
    11091137                global $wp_filesystem;
     1138
     1139                $defaults = array(
     1140                        'clear_update_cache' => true,
     1141                );
     1142                $parsed_args = wp_parse_args( $args, $defaults );
    11101143
    11111144                $this->init();
    … …  
    11151148                        $language_updates = wp_get_translation_updates();
    11161149
    1117                 if ( empty( $language_updates ) )
     1150                if ( empty( $language_updates ) ) {
     1151                        $this->skin->header();
     1152                        $this->skin->before();
     1153                        $this->skin->set_result( true );
     1154                        $this->skin->feedback( 'up_to_date' );
     1155                        $this->skin->after();
     1156                        $this->skin->bulk_footer();
     1157                        $this->skin->footer();
    11181158                        return true;
     1159                }
    11191160
    11201161                if ( 'upgrader_process_complete' == current_filter() )
    … …  
    11451186
    11461187                foreach ( $language_updates as $language_update ) {
     1188
     1189                        $this->skin->language_update = $language_update;
    11471190
    11481191                        $destination = WP_LANG_DIR;
    … …  
    11761219                }
    11771220
     1221                $this->skin->bulk_footer();
     1222
     1223                $this->skin->footer();
     1224
    11781225                // Clean up our hooks, in case something else does an upgrade on this connection.
    11791226                remove_filter( 'upgrader_source_selection', array( &$this, 'check_package' ), 10, 2 );
     1227
     1228                if ( $parsed_args['clear_update_cache'] ) {
     1229                        wp_clean_themes_cache( true );
     1230                        wp_clean_plugins_cache( true );
     1231                        delete_site_transient( 'update_core' );
     1232                }
    11801233
    11811234                return $results;
    … …  
    12051258
    12061259                return $source;
     1260        }
     1261
     1262        function get_name_for_update( $update ) {
     1263                switch ( $update->type ) {
     1264                        case 'core':
     1265                                return 'WordPress'; // Not translated
     1266                                break;
     1267                        case 'theme':
     1268                                $theme = wp_get_theme( $update->slug );
     1269                                if ( $theme->exists() )
     1270                                        return $theme->Get( 'Name' );
     1271                                break;
     1272                        case 'plugin':
     1273                                $plugin_data = get_plugins( '/' . $update->slug );
     1274                                $plugin_data = array_shift( $plugin_data );
     1275                                if ( $plugin_data )
     1276                                        return $plugin_data['Name'];
     1277                                break;
     1278                }
     1279                return '';
    12071280        }
    12081281
    … …  
    13221395                }
    13231396
    1324                 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ), $result );
    13251397                return $result;
    13261398        }
    … …  
    16291701                                break;
    16301702                        case 'language':
    1631                                 if ( 'theme' == $item->type ) {
    1632                                         $theme = wp_get_theme( $item->slug );
    1633                                         $skin->feedback( sprintf(
    1634                                                 __( 'Updating the %1$s translation for the %2$s theme' ),
    1635                                                 $item->language,
    1636                                                 $theme->Get( 'Name' )
    1637                                         ) );
    1638                                         $item_name = sprintf(
    1639                                                 __( '%1$s translation for the %2$s theme' ),
    1640                                                 $item->language,
    1641                                                 $theme->Get( 'Name' )
    1642                                         );
    1643                                 } elseif ( 'plugin' == $item->type ) {
    1644                                         $plugin_data = get_plugins( '/' . $item->slug );
    1645                                         $plugin_data = array_shift( $plugin_data );
    1646                                         $skin->feedback( sprintf(
    1647                                                 __( 'Updating the %1$s translation for the %2$s plugin' ),
    1648                                                 $item->language,
    1649                                                 $plugin_data['Name']
    1650                                         ) );
    1651                                         $item_name = sprintf(
    1652                                                 __( '%1$s translation for the %2$s plugin' ),
    1653                                                 $item->language,
    1654                                                 $plugin_data['Name']
    1655                                         );
    1656                                 } else {
    1657                                         $skin->feedback( sprintf(
    1658                                                 __( 'Updating %s translation' ),
    1659                                                 $item->language
    1660                                         ) );
    1661                                         $item_name = sprintf(
    1662                                                 __( '%s translation' ),
    1663                                                 $item->language
    1664                                         );
    1665                                 }
    1666                                
     1703                                $name = $upgrader->get_name_for_update( $item );
     1704                                $skin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)&#8230;' ), $name, $item->language ) );
    16671705                                break;
    16681706                }
    … …  
    17121750
    17131751                // Don't automatically run these thins, as we'll handle it ourselves
    1714                 remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3 );
     1752                remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
    17151753                remove_action( 'upgrader_process_complete', 'wp_version_check' );
    17161754                remove_action( 'upgrader_process_complete', 'wp_update_plugins' );
  • trunk/src/wp-admin/includes/file.php

    r25799 r25806  
    892892                if ( !$context )
    893893                        $context = WP_CONTENT_DIR;
     894
     895                // If the directory doesn't exist (wp-content/languages) then use the parent directory as we'll create it.
     896                if ( WP_LANG_DIR == $context && ! is_dir( $context ) )
     897                        $context = dirname( $context );
     898
    894899                $context = trailingslashit($context);
    895900                $temp_file_name = $context . 'temp-write-test-' . time();
    … …  
    10221027</script>
    10231028<form action="<?php echo esc_url( $form_post ) ?>" method="post">
    1024 <div class="wrap">
    1025 <?php screen_icon(); ?>
    1026 <h2><?php _e('Connection Information') ?></h2>
     1029<div>
     1030<h3><?php _e('Connection Information') ?></h3>
    10271031<p><?php
    10281032        $label_user = __('Username');
  • trunk/src/wp-admin/includes/update-core.php

    r25805 r25806  
    890890        $wp_filesystem->delete($maintenance_file);
    891891
     892        // 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
     893        do_action( 'upgrader_process_complete', null, array( 'action' => 'update', 'type' => 'core' ) );
     894
    892895        // If we made it this far:
    893896        do_action( '_core_updated_successfully', $wp_version );
  • trunk/src/wp-admin/update-core.php

    r25784 r25806  
    325325}
    326326
     327function list_translation_updates() {
     328        $updates = wp_get_translation_updates();
     329        if ( ! $updates ) {
     330                if ( 'en_US' != get_locale() ) {
     331                        echo '<h3>' . __( 'Translations' ) . '</h3>';
     332                        echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
     333                }
     334                return;
     335        }
     336
     337        $form_action = 'update-core.php?action=do-translation-upgrade';
     338        ?>
     339        <h3><?php _e( 'Translations' ); ?></h3>
     340        <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
     341                <p><?php _e( 'Some of your translations are out of date.' ); ?></p>
     342                <?php wp_nonce_field('upgrade-translations'); ?>
     343                <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
     344        </form>
     345        <?php
     346}
     347
    327348/**
    328349 * Upgrade WordPress core display.
    … …  
    342363                $url = 'update-core.php?action=do-core-upgrade';
    343364        $url = wp_nonce_url($url, 'upgrade-core');
    344         if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) )
    345                 return;
    346365
    347366        $version = isset( $_POST['version'] )? $_POST['version'] : false;
    … …  
    351370                return;
    352371
    353         if ( ! WP_Filesystem($credentials, ABSPATH) ) {
    354                 request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
    355                 return;
    356         }
    357372?>
    358373        <div class="wrap">
    … …  
    360375        <h2><?php _e('Update WordPress'); ?></h2>
    361376<?php
     377
     378        if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH ) ) ) {
     379                echo '</div>';
     380                return;
     381        }
     382
     383        if ( ! WP_Filesystem( $credentials, ABSPATH ) ) {
     384                // Failed to connect, Error and request again
     385                request_filesystem_credentials( $url, '', true, ABSPATH );
     386                echo '</div>';
     387                return;
     388        }
     389
    362390        if ( $wp_filesystem->errors->get_error_code() ) {
    363391                foreach ( $wp_filesystem->errors->get_error_messages() as $message )
    … …  
    478506        echo '</p>';
    479507
    480         if ( current_user_can( 'update_core' ) )
     508        if ( $core = current_user_can( 'update_core' ) )
    481509                core_upgrade_preamble();
    482         if ( current_user_can( 'update_plugins' ) )
     510        if ( $plugins = current_user_can( 'update_plugins' ) )
    483511                list_plugin_updates();
    484         if ( current_user_can( 'update_themes' ) )
     512        if ( $themes = current_user_can( 'update_themes' ) )
    485513                list_theme_updates();
     514        if ( $core || $plugins || $themes )
     515                list_translation_updates();
     516        unset( $core, $plugins, $themes );
    486517        do_action('core_upgrade_preamble');
    487518        echo '</div>';
    … …  
    571602        include(ABSPATH . 'wp-admin/admin-footer.php');
    572603
     604} elseif ( 'do-translation-upgrade' == $action ) {
     605
     606        if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) )
     607                wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
     608
     609        check_admin_referer( 'upgrade-translations' );
     610
     611        require_once( ABSPATH . 'wp-admin/admin-header.php' );
     612        include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
     613
     614        $url = 'update-core.php?action=do-translation-upgrade';
     615        $nonce = 'upgrade-translations';
     616        $title = __( 'Update Translations' );
     617        $context = WP_LANG_DIR;
     618
     619        $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
     620        $result = $upgrader->bulk_upgrade();
     621
     622        require_once( ABSPATH . 'wp-admin/admin-footer.php' );
     623
    573624} else {
    574625        do_action('update-core-custom_' . $action);
Note: See TracChangeset for help on using the changeset viewer.