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

git-svn-id: https://develop.svn.wordpress.org/trunk@9441 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-10-31 18:51:06 +00:00
parent 8ab270a8ce
commit 769544395d
5 changed files with 221 additions and 51 deletions
+120 -29
View File
@@ -122,6 +122,64 @@ function do_theme_upgrade($theme) {
echo '</div>';
}
function list_core_update( $update ) {
$version_string = 'en_US' == $update->locale?
$update->current : sprintf("%s&ndash;<strong>%s</strong>", $update->current, $update->locale);
if ( 'development' == $update->response ) {
$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:');
$submit = __('Download nightly build');
} else {
$message = sprintf(__('You can upgrade to version %s automatically or download the package and install it manually:'), $version_string);
$submit = sprintf(__('Download %s'), $version_string);
}
echo '<p>';
echo $message;
echo '</p>';
echo '<form method="post" action="update.php?action=do-core-upgrade" name="upgrade" class="upgrade">';
wp_nonce_field('upgrade-core');
echo '<p>';
echo '<input id="upgrade" class="button" type="submit" value="' . __('Upgrade Automatically') . '" name="upgrade" />&nbsp;';
echo '<input name="version" value="'.$update->current.'" type="hidden"/>';
echo '<input name="locale" value="'.$update->locale.'" type="hidden"/>';
echo '<a href="' . $update->package . '" class="button">' . $submit . '</a>&nbsp;';
if ( 'en_US' != $update->locale )
if ( !isset( $update->dismissed ) || !$update->dismissed )
echo '<input id="dismiss" class="button" type="submit" value="' . attribute_escape(__('Hide this update')) . '" name="dismiss" />';
else
echo '<input id="undismiss" class="button" type="submit" value="' . attribute_escape(__('Bring back this update')) . '" name="undismiss" />';
echo '</p>';
echo '</form>';
}
function dismissed_updates() {
$dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
if ( $dismissed ) {
$show_text = js_escape(__('Show hidden updates'));
$hide_text = js_escape(__('Hide hidden updates'));
?>
<script type="text/javascript">
jQuery(function($) {
$('dismissed-updates').show();
$('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
$('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
});
</script>
<?php
echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
echo '<ul id="dismissed-updates" class="core-updates dismissed">';
foreach($dismissed as $update) {
echo '<li>';
list_core_update( $update );
echo '</li>';
}
echo '</ul>';
}
}
/**
* Display upgrade WordPress for downloading latest or upgrading automatically form.
*
@@ -130,43 +188,42 @@ function do_theme_upgrade($theme) {
* @return null
*/
function core_upgrade_preamble() {
$update = get_option('update_core');
$updates = get_core_updates();
echo '<div class="wrap">';
echo '<h2>' . __('Upgrade WordPress') . '</h2>';
if ( !isset($update->response) || 'latest' == $update->response ) {
_e('You have the latest version of WordPress. You do not need to upgrade.');
if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
echo '<h3>';
_e('You have the latest version of WordPress. You do not need to upgrade');
echo '</h3>';
dismissed_updates();
echo '</div>';
return;
}
echo '<p>';
_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>.');
echo '</p>';
if ( 'development' == $update->response ) {
$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?');
$submit = __('Download nightly build');
} else {
$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);
$submit = sprintf(__('Download %s'), $update->current);
echo '<div class="updated fade"><p>';
_e('<strong>Important:</strong> before upgrading, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>.');
echo '</p></div>';
echo '<h3 class="response">';
_e( 'There is a new version of WordPress available for upgrade' );
echo '</h3>';
echo '<ul class="core-updates">';
$alternate = true;
foreach( $updates as $update ) {
$class = $alternate? ' class="alternate"' : '';
$alternate = !$alternate;
echo "<li $class>";
list_core_update( $update );
echo '</li>';
}
echo '<p>';
echo $message;
echo '</p>';
echo '<form id="post" method="post" action="update.php?action=do-core-upgrade" name="upgrade">';
wp_nonce_field('upgrade-core');
echo '<p>';
echo '<input id="upgrade" class="button" type="submit" value="' . __('Upgrade Automatically') . '" name="upgrade" />';
echo '<a href="' . $update->package . '" class="button">' . $submit . '</a>';
echo '</p>';
echo '</form>';
echo '</ul>';
dismissed_updates();
echo '</div>';
}
/**
* Upgrade WordPress core display.
*
@@ -176,10 +233,17 @@ function core_upgrade_preamble() {
*/
function do_core_upgrade() {
global $wp_filesystem;
$url = wp_nonce_url('update.php?action=do-core-upgrade', 'upgrade-core');
if ( false === ($credentials = request_filesystem_credentials($url)) )
return;
$version = isset( $_POST['version'] )? $_POST['version'] : false;
$locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
$update = find_core_update( $version, $locale );
if ( !$update )
return;
if ( ! WP_Filesystem($credentials) ) {
request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
@@ -195,7 +259,7 @@ function do_core_upgrade() {
return;
}
$result = wp_update_core('show_message');
$result = wp_update_core($update, 'show_message');
if ( is_wp_error($result) ) {
show_message($result);
@@ -207,6 +271,26 @@ function do_core_upgrade() {
echo '</div>';
}
function do_dismiss_core_update() {
$version = isset( $_POST['version'] )? $_POST['version'] : false;
$locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
$update = find_core_update( $version, $locale );
if ( !$update )
return;
dismiss_core_update( $update );
wp_redirect( wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') );
}
function do_undismiss_core_update() {
$version = isset( $_POST['version'] )? $_POST['version'] : false;
$locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
$update = find_core_update( $version, $locale );
if ( !$update )
return;
undismiss_core_update( $version, $locale );
wp_redirect( wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') );
}
if ( isset($_GET['action']) ) {
$plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : '';
$theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
@@ -248,8 +332,15 @@ if ( isset($_GET['action']) ) {
check_admin_referer('upgrade-core');
$title = __('Upgrade WordPress');
$parent_file = 'index.php';
// do the (un)dismiss actions before headers,
// so that they can redirect
if ( isset( $_POST['dismiss'] ) )
do_dismiss_core_update();
elseif ( isset( $_POST['undismiss'] ) )
do_undismiss_core_update();
require_once('admin-header.php');
do_core_upgrade();
if ( isset( $_POST['upgrade'] ) )
do_core_upgrade();
include('admin-footer.php');
} elseif ( 'upgrade-theme' == $action ) {
check_admin_referer('upgrade-theme_' . $theme);