Make WordPress Core


Ignore:
Timestamp:
10/31/2008 06:51:06 PM (18 years ago)
Author:
ryan
Message:

Better i18n support for automatic upgrade. Props nbachiyski. fixes #8023

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/update.php

    r9279 r9441  
    123123}
    124124
    125 /**
    126  * Display upgrade WordPress for downloading latest or upgrading automatically form.
    127  *
    128  * @since 2.7
    129  *
    130  * @return null
    131  */
    132 function core_upgrade_preamble() {
    133         $update = get_option('update_core');
    134 
    135         echo '<div class="wrap">';
    136         echo '<h2>' . __('Upgrade WordPress') . '</h2>';
    137 
    138         if ( !isset($update->response) || 'latest' == $update->response ) {
    139                 _e('You have the latest version of WordPress. You do not need to upgrade.');
    140                 echo '</div>';
    141                 return;
    142         }
    143 
    144         echo '<p>';
    145         _e('A new version of WordPress is available for upgrade.  Before upgrading, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>.'); 
    146         echo '</p>';
    147 
     125function list_core_update( $update ) {
     126        $version_string = 'en_US' == $update->locale?
     127                        $update->current : sprintf("%s&ndash;<strong>%s</strong>", $update->current, $update->locale);
    148128        if ( 'development' == $update->response ) {
    149                 $message = __('You are using a development version of WordPress.  You can upgrade to the latest nightly build automatically or download the nightly build and install it manually. Which would you like to do?');
     129                $message = __('You are using a development version of WordPress.  You can upgrade to the latest nightly build automatically or download the nightly build and install it manually:');
    150130                $submit = __('Download nightly build');
    151131        } else {
    152                 $message =      sprintf(__('You can upgrade to version %s automatically or download the package and install it manually. Which would you like to do?'), $update->current);
    153                 $submit = sprintf(__('Download %s'), $update->current);
     132                $message =      sprintf(__('You can upgrade to version %s automatically or download the package and install it manually:'), $version_string);
     133                $submit = sprintf(__('Download %s'), $version_string);
    154134        }
    155135
     
    157137        echo $message;
    158138        echo '</p>';
    159         echo '<form id="post" method="post" action="update.php?action=do-core-upgrade" name="upgrade">';
     139        echo '<form method="post" action="update.php?action=do-core-upgrade" name="upgrade" class="upgrade">';
    160140        wp_nonce_field('upgrade-core');
    161141        echo '<p>';
    162         echo '<input id="upgrade" class="button" type="submit" value="' . __('Upgrade Automatically') . '" name="upgrade" />';
    163         echo '<a href="' . $update->package . '" class="button">' . $submit . '</a>';
     142        echo '<input id="upgrade" class="button" type="submit" value="' . __('Upgrade Automatically') . '" name="upgrade" />&nbsp;';
     143        echo '<input name="version" value="'.$update->current.'" type="hidden"/>';
     144        echo '<input name="locale" value="'.$update->locale.'" type="hidden"/>';
     145        echo '<a href="' . $update->package . '" class="button">' . $submit . '</a>&nbsp;';
     146        if ( 'en_US' != $update->locale )
     147                if ( !isset( $update->dismissed ) || !$update->dismissed )
     148                        echo '<input id="dismiss" class="button" type="submit" value="' . attribute_escape(__('Hide this update')) . '" name="dismiss" />';
     149                else
     150                        echo '<input id="undismiss" class="button" type="submit" value="' . attribute_escape(__('Bring back this update')) . '" name="undismiss" />';
    164151        echo '</p>';
    165152        echo '</form>';
    166 
     153       
     154}
     155
     156function dismissed_updates() {
     157        $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
     158        if ( $dismissed ) {
     159               
     160                $show_text = js_escape(__('Show hidden updates'));
     161                $hide_text = js_escape(__('Hide hidden updates'));
     162        ?>
     163        <script type="text/javascript">
     164               
     165                jQuery(function($) {
     166                        $('dismissed-updates').show();
     167                        $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
     168                        $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
     169                });
     170        </script>
     171        <?php
     172                echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
     173                echo '<ul id="dismissed-updates" class="core-updates dismissed">';
     174                foreach($dismissed as $update) {
     175                        echo '<li>';
     176                        list_core_update( $update );
     177                        echo '</li>';
     178                }
     179                echo '</ul>';
     180        }       
     181}
     182
     183/**
     184 * Display upgrade WordPress for downloading latest or upgrading automatically form.
     185 *
     186 * @since 2.7
     187 *
     188 * @return null
     189 */
     190function core_upgrade_preamble() {
     191        $updates = get_core_updates();
     192       
     193        echo '<div class="wrap">';
     194        echo '<h2>' . __('Upgrade WordPress') . '</h2>';
     195
     196        if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
     197                echo '<h3>';
     198                _e('You have the latest version of WordPress. You do not need to upgrade');
     199                echo '</h3>';
     200                dismissed_updates();
     201                echo '</div>';
     202                return;
     203        }
     204
     205        echo '<div class="updated fade"><p>';
     206        _e('<strong>Important:</strong> before upgrading, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>.'); 
     207        echo '</p></div>';
     208       
     209        echo '<h3 class="response">';
     210        _e( 'There is a new version of WordPress available for upgrade' );
     211        echo '</h3>';
     212        echo '<ul class="core-updates">';
     213        $alternate = true;
     214        foreach( $updates as $update ) {
     215                $class = $alternate? ' class="alternate"' : '';
     216                $alternate = !$alternate;
     217                echo "<li $class>";
     218                list_core_update( $update );
     219                echo '</li>';
     220        }
     221        echo '</ul>';
     222        dismissed_updates();
    167223        echo '</div>';
    168224}
     225
    169226
    170227/**
     
    177234function do_core_upgrade() {
    178235        global $wp_filesystem;
    179 
     236       
    180237        $url = wp_nonce_url('update.php?action=do-core-upgrade', 'upgrade-core');
    181238        if ( false === ($credentials = request_filesystem_credentials($url)) )
    182239                return;
     240               
     241        $version = isset( $_POST['version'] )? $_POST['version'] : false;
     242        $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
     243        $update = find_core_update( $version, $locale );
     244        if ( !$update )
     245                return;
     246               
    183247
    184248        if ( ! WP_Filesystem($credentials) ) {
     
    196260        }
    197261
    198         $result = wp_update_core('show_message');
     262        $result = wp_update_core($update, 'show_message');
    199263
    200264        if ( is_wp_error($result) ) {
     
    206270        }
    207271        echo '</div>';
     272}
     273
     274function do_dismiss_core_update() {
     275        $version = isset( $_POST['version'] )? $_POST['version'] : false;
     276        $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
     277        $update = find_core_update( $version, $locale );
     278        if ( !$update )
     279                return;
     280        dismiss_core_update( $update );
     281        wp_redirect( wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') );
     282}
     283
     284function do_undismiss_core_update() {
     285        $version = isset( $_POST['version'] )? $_POST['version'] : false;
     286        $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
     287        $update = find_core_update( $version, $locale );
     288        if ( !$update )
     289                return;
     290        undismiss_core_update( $version, $locale );
     291        wp_redirect( wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') );
    208292}
    209293
     
    249333                $title = __('Upgrade WordPress');
    250334                $parent_file = 'index.php';
     335                // do the (un)dismiss actions before headers,
     336                // so that they can redirect
     337                if ( isset( $_POST['dismiss'] ) )
     338                        do_dismiss_core_update();
     339                elseif ( isset( $_POST['undismiss'] ) )
     340                        do_undismiss_core_update();
    251341                require_once('admin-header.php');
    252                 do_core_upgrade();
     342                if ( isset( $_POST['upgrade'] ) )
     343                        do_core_upgrade();
    253344                include('admin-footer.php');
    254345        } elseif ( 'upgrade-theme' == $action ) {       
Note: See TracChangeset for help on using the changeset viewer.