source: trunk/www.guidonia.net/wp/wp-admin/update-core.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 8.1 KB
Line 
1<?php
2/**
3 * Update Core administration panel.
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
8
9/** WordPress Administration Bootstrap */
10require_once('admin.php');
11
12if ( ! current_user_can('update_plugins') )
13 wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
14
15function list_core_update( $update ) {
16 global $wp_local_package;
17 $version_string = ('en_US' == $update->locale && 'en_US' == get_locale() ) ?
18 $update->current : sprintf("%s&ndash;<strong>%s</strong>", $update->current, $update->locale);
19 $current = false;
20 if ( !isset($update->response) || 'latest' == $update->response )
21 $current = true;
22 $submit = __('Upgrade Automatically');
23 $form_action = 'update-core.php?action=do-core-upgrade';
24 if ( 'development' == $update->response ) {
25 $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:');
26 $download = __('Download nightly build');
27 } else {
28 if ( $current ) {
29 $message = sprintf(__('You have the latest version of WordPress. You do not need to upgrade. However, if you want to re-install version %s, you can do so automatically or download the package and re-install manually:'), $version_string);
30 $submit = __('Re-install Automatically');
31 $form_action = 'update-core.php?action=do-core-reinstall';
32 } else {
33 $message = sprintf(__('You can upgrade to version %s automatically or download the package and install it manually:'), $version_string);
34 }
35 $download = sprintf(__('Download %s'), $version_string);
36 }
37
38 echo '<p>';
39 echo $message;
40 echo '</p>';
41 echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
42 wp_nonce_field('upgrade-core');
43 echo '<p>';
44 echo '<input id="upgrade" class="button" type="submit" value="' . esc_attr($submit) . '" name="upgrade" />&nbsp;';
45 echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
46 echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
47 echo '<a href="' . esc_url($update->package) . '" class="button">' . $download . '</a>&nbsp;';
48 if ( 'en_US' != $update->locale )
49 if ( !isset( $update->dismissed ) || !$update->dismissed )
50 echo '<input id="dismiss" class="button" type="submit" value="' . esc_attr__('Hide this update') . '" name="dismiss" />';
51 else
52 echo '<input id="undismiss" class="button" type="submit" value="' . esc_attr__('Bring back this update') . '" name="undismiss" />';
53 echo '</p>';
54 if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
55 echo '<p class="hint">'.__('This localized version contains both the translation and various other localization fixes. You can skip upgrading if you want to keep your current translation.').'</p>';
56 else if ( 'en_US' == $update->locale && get_locale() != 'en_US' ) {
57 echo '<p class="hint">'.sprintf( __('You are about to install WordPress %s <strong>in English.</strong> There is a chance this upgrade will break your translation. You may prefer to wait for the localized version to be released.'), $update->current ).'</p>';
58 }
59 echo '</form>';
60
61}
62
63function dismissed_updates() {
64 $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
65 if ( $dismissed ) {
66
67 $show_text = esc_js(__('Show hidden updates'));
68 $hide_text = esc_js(__('Hide hidden updates'));
69 ?>
70 <script type="text/javascript">
71
72 jQuery(function($) {
73 $('dismissed-updates').show();
74 $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
75 $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
76 });
77 </script>
78 <?php
79 echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
80 echo '<ul id="dismissed-updates" class="core-updates dismissed">';
81 foreach( (array) $dismissed as $update) {
82 echo '<li>';
83 list_core_update( $update );
84 echo '</li>';
85 }
86 echo '</ul>';
87 }
88}
89
90/**
91 * Display upgrade WordPress for downloading latest or upgrading automatically form.
92 *
93 * @since 2.7
94 *
95 * @return null
96 */
97function core_upgrade_preamble() {
98 $updates = get_core_updates();
99?>
100 <div class="wrap">
101 <?php screen_icon(); ?>
102 <h2><?php _e('Upgrade WordPress'); ?></h2>
103<?php
104 if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
105 echo '<h3>';
106 _e('You have the latest version of WordPress. You do not need to upgrade');
107 echo '</h3>';
108 } else {
109 echo '<div class="updated fade"><p>';
110 _e('<strong>Important:</strong> before upgrading, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>.');
111 echo '</p></div>';
112
113 echo '<h3 class="response">';
114 _e( 'There is a new version of WordPress available for upgrade' );
115 echo '</h3>';
116 }
117
118 echo '<ul class="core-updates">';
119 $alternate = true;
120 foreach( (array) $updates as $update ) {
121 $class = $alternate? ' class="alternate"' : '';
122 $alternate = !$alternate;
123 echo "<li $class>";
124 list_core_update( $update );
125 echo '</li>';
126 }
127 echo '</ul>';
128 dismissed_updates();
129 echo '</div>';
130}
131
132
133/**
134 * Upgrade WordPress core display.
135 *
136 * @since 2.7
137 *
138 * @return null
139 */
140function do_core_upgrade( $reinstall = false ) {
141 global $wp_filesystem;
142
143 if ( $reinstall )
144 $url = 'update-core.php?action=do-core-reinstall';
145 else
146 $url = 'update-core.php?action=do-core-upgrade';
147 $url = wp_nonce_url($url, 'upgrade-core');
148 if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) )
149 return;
150
151 $version = isset( $_POST['version'] )? $_POST['version'] : false;
152 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
153 $update = find_core_update( $version, $locale );
154 if ( !$update )
155 return;
156
157
158 if ( ! WP_Filesystem($credentials, ABSPATH) ) {
159 request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
160 return;
161 }
162?>
163 <div class="wrap">
164 <?php screen_icon(); ?>
165 <h2><?php _e('Upgrade WordPress'); ?></h2>
166<?php
167 if ( $wp_filesystem->errors->get_error_code() ) {
168 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
169 show_message($message);
170 echo '</div>';
171 return;
172 }
173
174 if ( $reinstall )
175 $update->response = 'reinstall';
176
177 $result = wp_update_core($update, 'show_message');
178
179 if ( is_wp_error($result) ) {
180 show_message($result);
181 if ('up_to_date' != $result->get_error_code() )
182 show_message( __('Installation Failed') );
183 } else {
184 show_message( __('WordPress upgraded successfully') );
185 }
186 echo '</div>';
187}
188
189function do_dismiss_core_update() {
190 $version = isset( $_POST['version'] )? $_POST['version'] : false;
191 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
192 $update = find_core_update( $version, $locale );
193 if ( !$update )
194 return;
195 dismiss_core_update( $update );
196 wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
197}
198
199function do_undismiss_core_update() {
200 $version = isset( $_POST['version'] )? $_POST['version'] : false;
201 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
202 $update = find_core_update( $version, $locale );
203 if ( !$update )
204 return;
205 undismiss_core_update( $version, $locale );
206 wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
207}
208
209$action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
210
211if ( 'upgrade-core' == $action ) {
212 wp_version_check();
213 $title = __('Upgrade WordPress');
214 $parent_file = 'tools.php';
215 require_once('admin-header.php');
216 core_upgrade_preamble();
217 include('admin-footer.php');
218} elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
219 check_admin_referer('upgrade-core');
220 $title = __('Upgrade WordPress');
221 $parent_file = 'tools.php';
222 // do the (un)dismiss actions before headers,
223 // so that they can redirect
224 if ( isset( $_POST['dismiss'] ) )
225 do_dismiss_core_update();
226 elseif ( isset( $_POST['undismiss'] ) )
227 do_undismiss_core_update();
228 require_once('admin-header.php');
229 if ( 'do-core-reinstall' == $action )
230 $reinstall = true;
231 else
232 $reinstall = false;
233 if ( isset( $_POST['upgrade'] ) )
234 do_core_upgrade($reinstall);
235 include('admin-footer.php');
236
237}?>
Note: See TracBrowser for help on using the repository browser.