Make WordPress Core

Ticket #17703: 17703.2.diff

File 17703.2.diff, 18.8 KB (added by mitchoyoshitaka, 14 years ago)

Patch v1.1, forgot to add update.dev.js

  • wp-admin/includes/class-wp-upgrader.php

     
    324324                } else {
    325325                        //Install Suceeded
    326326                        $this->skin->feedback('process_success');
     327                        $updated = array();
     328                        if ( isset( $updating ) )
     329                                $updated[$updating] = 1;
     330                        echo '<script type="text/javascript">(window.parent || window).updateUpdateCounts(' . json_encode( wp_get_update_data($updated) ) . ');</script>';
    327331                }
    328332                $this->skin->after();
    329333
     
    432436                                        'clear_working' => true,
    433437                                        'hook_extra' => array(
    434438                                                                'plugin' => $plugin
    435                                         )
     439                                        ),
     440                                        'updating' => 'plugins'
    436441                                ));
    437442
    438443                // Cleanup our hooks, incase something else does a upgrade on this connection.
     
    544549
    545550                return $this->result['destination_name'] . '/' . $pluginfiles[0];
    546551        }
    547 
     552       
    548553        //Hooked to pre_install
    549554        function deactivate_plugin_before_upgrade($return, $plugin) {
    550555
     
    679684                                                'clear_working' => true,
    680685                                                'hook_extra' => array(
    681686                                                                                        'theme' => $theme
    682                                                                                         )
     687                                                                                        ),
     688                                                'updating' => 'themes'
    683689                                                );
    684690
    685691                $this->run($options);
     
    10591065class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
    10601066        var $in_loop = false;
    10611067        var $error = false;
     1068        var $updated = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0 );
    10621069
    10631070        function __construct($args = array()) {
    10641071                $defaults = array( 'url' => '', 'nonce' => '' );
     
    11321139                $this->flush_output();
    11331140        }
    11341141
    1135         function after($title = '') {
     1142        function after($title = '', $updating = 'plugins') {
    11361143                echo '</p></div>';
    11371144                if ( $this->error || ! $this->result ) {
    11381145                        if ( $this->error )
     
    11441151                }
    11451152                if ( !empty($this->result) && !is_wp_error($this->result) ) {
    11461153                        echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>';
    1147                         echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
     1154                        $this->updated[$updating] ++;
     1155                        echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide(); (window.parent || window).updateUpdateCounts(' . json_encode( wp_get_update_data($this->updated) ) . ');</script>';
    11481156                }
    11491157
    11501158                $this->reset();
     
    12111219        }
    12121220
    12131221        function after() {
    1214                 parent::after($this->theme_info['Name']);
     1222                parent::after($this->theme_info['Name'], 'themes');
    12151223        }
    12161224        function bulk_footer() {
    12171225                parent::bulk_footer();
  • wp-admin/update.php

     
    5454                $title = __('Update Plugin');
    5555                $parent_file = 'plugins.php';
    5656                $submenu_file = 'plugins.php';
     57                wp_enqueue_script('update');
    5758                require_once(ABSPATH . 'wp-admin/admin-header.php');
    5859
    5960                $nonce = 'upgrade-plugin_' . $plugin;
     
    154155                $title = __('Update Theme');
    155156                $parent_file = 'themes.php';
    156157                $submenu_file = 'themes.php';
     158                wp_enqueue_script('update');
    157159                require_once(ABSPATH . 'wp-admin/admin-header.php');
    158160
    159161                $nonce = 'upgrade-theme_' . $theme;
  • wp-includes/admin-bar.php

     
    264264 * @since 3.1.0
    265265 */
    266266function wp_admin_bar_updates_menu( $wp_admin_bar ) {
    267         if ( !current_user_can('install_plugins') )
    268                 return;
    269267
    270         $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
    271         $update_plugins = get_site_transient( 'update_plugins' );
    272         if ( !empty($update_plugins->response) )
    273                 $plugin_update_count = count( $update_plugins->response );
    274         $update_themes = get_site_transient( 'update_themes' );
    275         if ( !empty($update_themes->response) )
    276                 $theme_update_count = count( $update_themes->response );
    277         /* @todo get_core_updates() is only available on admin page loads
    278         $update_wordpress = get_core_updates( array('dismissed' => false) );
    279         if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) )
    280                 $wordpress_update_count = 1;
    281         */
     268        $update_data = wp_get_update_data();
    282269
    283         $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
    284 
    285         if ( !$update_count )
     270        if ( !$update_data['counts']['total'] )
    286271                return;
    287272
    288         $update_title = array();
    289         if ( $wordpress_update_count )
    290                 $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count);
    291         if ( $plugin_update_count )
    292                 $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count);
    293         if ( $theme_update_count )
    294                 $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $theme_update_count), $theme_update_count);
    295 
    296         $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
    297 
    298         $update_title = "<span title='$update_title'>";
    299         $update_title .= sprintf( __('Updates %s'), "<span id='ab-updates' class='update-count'>" . number_format_i18n($update_count) . '</span>' );
     273        $update_title = "<span title='{$update_data['title']}'>";
     274        $update_title .= sprintf( __('Updates %s'), "<span id='ab-updates' class='update-count'>" . number_format_i18n($update_data['counts']['total']) . '</span>' );
    300275        $update_title .= '</span>';
    301276
    302277        $wp_admin_bar->add_menu( array( 'id' => 'updates', 'title' => $update_title, 'href' => network_admin_url( 'update-core.php' ) ) );
  • wp-includes/update.php

     
    281281        set_site_transient( 'update_themes', $new_update );
    282282}
    283283
     284/*
     285 * Collect counts and UI strings for available updates
     286 *
     287 * @package WordPress
     288 * @since 3.3.0
     289 *
     290 * @return array
     291 */
     292function wp_get_update_data( $updated = array() ) {
     293        $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0 );
     294        $formatted = array();
     295
     296        if ( current_user_can( 'update_plugins' ) ) {
     297                $update_plugins = get_site_transient( 'update_plugins' );
     298                if ( ! empty( $update_plugins->response ) )
     299                        $counts['plugins'] = count( $update_plugins->response );
     300                if ( ! empty( $updated['plugins'] ) && $updated['plugins'] <= $counts['plugins'] )
     301                        $counts['plugins'] -= $updated['plugins'];
     302                $formatted['plugins'] = number_format_i18n( $counts['plugins'] );
     303        }
     304
     305        if ( current_user_can( 'update_themes' ) ) {
     306                $update_themes = get_site_transient( 'update_themes' );
     307                if ( !empty($update_themes->response) )
     308                        $counts['themes'] = count( $update_themes->response );
     309                if ( ! empty( $updated['themes'] ) && $updated['themes'] <= $counts['themes'] )
     310                        $counts['themes'] -= $updated['themes'];
     311                $formatted['themes'] = number_format_i18n( $counts['themes'] );
     312        }
     313
     314        if ( function_exists( 'get_core_updates' ) && current_user_can( 'update_core' ) ) {
     315                $update_wordpress = get_core_updates( array('dismissed' => false) );
     316                if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') )
     317                        $counts['wordpress'] = 1;
     318                if ( ! empty( $updated['wordpress'] ) )
     319                        $counts['wordpress'] -= $updated['wordpress'];
     320        }
     321
     322        $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'];
     323        $formatted['total'] = number_format_i18n( $counts['total'] );
     324        $update_title = array();
     325        if ( $counts['wordpress'] )
     326                $update_title[] = sprintf(__('%d WordPress Update'), $counts['wordpress']);
     327        if ( $counts['plugins'] )
     328                $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $counts['plugins']), $counts['plugins']);
     329        if ( $counts['themes'] )
     330                $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $counts['themes']), $counts['themes']);
     331
     332        $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
     333       
     334        return array( 'counts' => $counts, 'formatted' => $formatted, 'title' => $update_title );
     335}
     336
    284337function _maybe_update_core() {
    285338        include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
    286339
  • wp-includes/script-loader.php

     
    401401                        'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
    402402                ) );
    403403
     404                $scripts->add( 'update', "/wp-admin/js/update$suffix.js", array( 'jquery' ), '20110604' );
     405
    404406                $scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'jquery', 'thickbox' ), '20110113' );
    405407                $scripts->add_data( 'plugin-install', 'group', 1 );
    406408                $scripts->localize( 'plugin-install', 'plugininstallL10n', array(
  • wp-admin/network/menu.php

     
    2121$submenu['users.php'][5]  = array( __('All Users'), 'manage_network_users', 'users.php' );
    2222$submenu['users.php'][10]  = array( _x('Add New', 'user'), 'create_users', 'user-new.php' );
    2323
    24 if ( current_user_can( 'update_themes' ) ) {
    25         $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
    26         $update_themes = get_site_transient( 'update_themes' );
    27         if ( !empty($update_themes->response) )
    28                 $theme_update_count = count( $update_themes->response );
    29         $menu[15] = array(sprintf( __( 'Themes %s' ), "<span class='update-plugins count-$theme_update_count'><span class='theme-count'>" . number_format_i18n( $theme_update_count ) . "</span></span>" ), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' );
     24$update_data = wp_get_update_data();
     25
     26if ( $update_data['counts']['themes'] ) {
     27        $menu[15] = array(sprintf( __( 'Themes %s' ), "<span class='update-plugins count-{$update_data['counts']['themes']}'><span class='theme-count'>" . number_format_i18n( $update_data['counts']['themes'] ) . "</span></span>" ), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' );
    3028} else {
    3129        $menu[15] = array( __( 'Themes' ), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' );
    3230}
     
    3533$submenu['themes.php'][15] = array( _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php' );
    3634
    3735if ( current_user_can( 'update_plugins' ) ) {
    38         $update_plugins = get_site_transient( 'update_plugins' );
    39         if ( !empty($update_plugins->response) )
    40                 $plugin_update_count = count( $update_plugins->response );
    41         $menu[20] = array( sprintf( __( 'Plugins %s' ), "<span class='update-plugins count-$plugin_update_count'><span class='plugin-count'>" . number_format_i18n( $plugin_update_count ) . "</span></span>" ), 'manage_network_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div');
     36        $menu[20] = array( sprintf( __( 'Plugins %s' ), "<span class='update-plugins count-{$update_data['counts']['plugins']}'><span class='plugin-count'>" . number_format_i18n( $update_data['counts']['plugins'] ) . "</span></span>" ), 'manage_network_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div');
    4237} else {
    4338        $menu[20] = array( __('Plugins'), 'manage_network_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' );
    4439}
     
    5348        $submenu['settings.php'][10] = array( __('Network Setup'), 'manage_network_options', 'setup.php' );
    5449}
    5550
    56 if ( current_user_can( 'update_core' ) ) {
    57         $update_wordpress = get_core_updates( array('dismissed' => false) );
    58         if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) )
    59                 $wordpress_update_count = 1;
    60        
    61         $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
    62         $update_title = array();
    63         if ( $wordpress_update_count )
    64                 $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count);
    65         if ( $plugin_update_count )
    66                 $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count);
    67         if ( $theme_update_count )
    68                 $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $theme_update_count), $theme_update_count);
    69        
    70         $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
    71        
    72         $menu[30] = array( sprintf( __( 'Updates %s' ), "<span class='update-plugins count-$update_count' title='$update_title'><span class='update-count'>" . number_format_i18n($update_count) . "</span></span>" ), 'manage_network', 'upgrade.php', '', 'menu-top menu-icon-tools', 'menu-update', 'div' );
     51if ( $update_data['counts']['total'] ) {
     52        $menu[30] = array( sprintf( __( 'Updates %s' ), "<span class='update-plugins count-{$update_data['counts']['total']}' title='{$update_data['title']}'><span class='update-count'>" . number_format_i18n($update_data['counts']['total']) . "</span></span>" ), 'manage_network', 'upgrade.php', '', 'menu-top menu-icon-tools', 'menu-update', 'div' );
    7353} else {
    7454        $menu[30] = array( __( 'Updates' ), 'manage_network', 'upgrade.php', '', 'menu-top menu-icon-tools', 'menu-update', 'div' );
    7555}
    7656
     57unset($update_data);
     58
    7759$submenu[ 'upgrade.php' ][10] = array( __( 'Available Updates' ), 'update_core',  'update-core.php' );
    7860$submenu[ 'upgrade.php' ][15] = array( __( 'Update Network' ), 'manage_network', 'upgrade.php' );
    79 unset($plugin_update_count, $theme_update_count, $wordpress_update_count, $update_count, $update_title, $update_themes, $update_plugins, $update_wordpress);
    8061
    81 
    8262$menu[99] = array( '', 'read', 'separator-last', '', 'wp-menu-separator-last' );
    8363
    8464require_once(ABSPATH . 'wp-admin/includes/menu.php');
  • wp-admin/menu.php

     
    3030        $submenu[ 'index.php' ][5] = array( __('My Sites'), 'read', 'my-sites.php' );
    3131}
    3232
    33 if ( ! is_multisite() || is_super_admin() ) {
    34         $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
     33if ( ! is_multisite() || is_super_admin() )
     34        $update_data = wp_get_update_data();
    3535
    36         if ( current_user_can( 'update_plugins' ) ) {
    37                 $update_plugins = get_site_transient( 'update_plugins' );
    38                 if ( ! empty( $update_plugins->response ) )
    39                         $plugin_update_count = count( $update_plugins->response );
    40         }
    41 
    42         if ( current_user_can( 'update_themes' ) ) {
    43                 $update_themes = get_site_transient( 'update_themes' );
    44                 if ( !empty($update_themes->response) )
    45                         $theme_update_count = count( $update_themes->response );
    46         }
    47 
    48         if ( current_user_can( 'update_core' ) ) {
    49                 $update_wordpress = get_core_updates( array('dismissed' => false) );
    50                 if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') )
    51                         $wordpress_update_count = 1;
    52         }
    53 
    54         $total_update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
    55         $update_title = array();
    56         if ( $wordpress_update_count )
    57                 $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count);
    58         if ( $plugin_update_count )
    59                 $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count);
    60         if ( $theme_update_count )
    61                 $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $theme_update_count), $theme_update_count);
    62 
    63         $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
    64 }
    65 
    6636if ( ! is_multisite() ) {
    67         $submenu[ 'index.php' ][10] = array( sprintf( __('Updates %s'), "<span class='update-plugins count-$total_update_count' title='$update_title'><span class='update-count'>" . number_format_i18n($total_update_count) . "</span></span>" ), 'update_core',  'update-core.php');
     37        $submenu[ 'index.php' ][10] = array( sprintf( __('Updates %s'), "<span class='update-plugins count-{$update_data['counts']['total']}' title='{$update_data['title']}'><span class='update-count'>" . number_format_i18n($update_data['counts']['total']) . "</span></span>" ), 'update_core',  'update-core.php');
    6838}
    6939
    70 unset($theme_update_count, $wordpress_update_count, $update_themes, $update_plugins, $update_wordpress);
    71 
    7240$menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
    7341
    7442$menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-post', 'menu-posts', 'div' );
     
    176144
    177145$menu_perms = get_site_option('menu_items', array());
    178146if ( ! is_multisite() || is_super_admin() || ! empty( $menu_perms['plugins'] ) ) {
    179         $count = "<span class='update-plugins count-$plugin_update_count'><span class='plugin-count'>" . number_format_i18n($plugin_update_count) . "</span></span>";
     147        if ( !isset( $update_data ) )
     148                $update_data = wp_get_update_data();
     149
     150        $count = "<span class='update-plugins count-{$update_data['counts']['plugins']}'><span class='plugin-count'>" . number_format_i18n($update_data['counts']['plugins']) . "</span></span>";
    180151        if ( is_multisite() || ! current_user_can( 'update_plugins' ) )
    181152                $count = '';
    182153        $menu[65] = array( sprintf( __('Plugins %s'), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' );
     
    189160                        $submenu['plugins.php'][15] = array( _x('Editor', 'plugin editor'), 'edit_plugins', 'plugin-editor.php' );
    190161                }
    191162}
    192 unset($menu_perms, $update_plugins, $plugin_update_count);
     163unset($menu_perms, $update_data);
    193164
    194165if ( current_user_can('list_users') )
    195166        $menu[70] = array( __('Users'), 'list_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' );
  • wp-admin/update-core.php

     
    395395        $action = 'upgrade-core';
    396396}
    397397
     398wp_enqueue_script( 'update' );
     399
    398400$title = __('WordPress Updates');
    399401$parent_file = 'tools.php';
    400402
  • wp-admin/js/update.dev.js

     
     1/**
     2 * Updater JS functions
     3 *
     4 * @version 3.3.0
     5 *
     6 * @package WordPress
     7 * @subpackage Administration
     8 */
     9
     10function updateUpdateCounts( data ) {
     11        var $ = jQuery, upgradeData;
     12
     13        updateData = ( typeof data == 'string' ) ? $.parseJson( data ) : data;
     14       
     15        // @todo fix parent span class count-%d values
     16        $('#ab-updates, .update-count').text( updateData.formatted.total ).parent()
     17                .attr( 'title', updateData.title )
     18                .addClass( 'count-' + updateData.counts.total );
     19        $('.plugin-count').text( updateData.formatted.plugins ).parent()
     20                .addClass( 'count-' + updateData.counts.plugins );
     21}