Changeset 9441
- Timestamp:
- 10/31/2008 06:51:06 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/update.php
r9427 r9441 9 9 // The admin side of our 1.1 update system 10 10 11 /** 12 * Selects the first update version from the update_core option 13 * 14 * @return object the response from the API 15 */ 16 function get_preferred_from_update_core() { 17 $updates = get_core_updates(); 18 if ( !is_array( $updates ) ) 19 return false; 20 if ( empty( $updates ) ) 21 return (object)array('response' => 'latest'); 22 return $updates[0]; 23 } 24 25 /** 26 * Get available core updates 27 * 28 * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too, 29 * set $options['available'] to false to skip not-dimissed updates. 30 * @return array Array of the update objects 31 */ 32 function get_core_updates( $options = array() ) { 33 $options = array_merge( array('available' => true, 'dismissed' => false ), $options ); 34 $dismissed = get_option( 'dismissed_update_core' ); 35 if ( !is_array( $dismissed ) ) $dismissed = array(); 36 $from_api = get_option( 'update_core' ); 37 if ( !is_array( $from_api ) ) return false; 38 $result = array(); 39 foreach($from_api as $update) { 40 if ( array_key_exists( $update->current.'|'.$update->locale, $dismissed ) ) { 41 if ( $options['dismissed'] ) { 42 $update->dismissed = true; 43 $result[]= $update; 44 } 45 } else { 46 if ( $options['available'] ) { 47 $update->dismissed = false; 48 $result[]= $update; 49 } 50 } 51 } 52 return $result; 53 } 54 55 function dismiss_core_update( $update ) { 56 $dismissed = get_option( 'dismissed_update_core' ); 57 $dismissed[ $update->current.'|'.$update->locale ] = true; 58 return update_option( 'dismissed_update_core', $dismissed ); 59 } 60 61 function undismiss_core_update( $version, $locale ) { 62 $dismissed = get_option( 'dismissed_update_core' ); 63 $key = $version.'|'.$locale; 64 if ( !isset( $dismissed[$key] ) ) return false; 65 unset( $dismissed[$key] ); 66 return update_option( 'dismissed_update_core', $dismissed ); 67 } 68 69 function find_core_update( $version, $locale ) { 70 $from_api = get_option( 'update_core' ); 71 if ( !is_array( $from_api ) ) return false; 72 foreach($from_api as $update) { 73 if ( $update->current == $version && $update->locale == $locale ) 74 return $update; 75 } 76 return false; 77 } 78 11 79 function core_update_footer( $msg = '' ) { 12 80 if ( !current_user_can('manage_options') ) 13 81 return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] ); 14 82 15 $cur = get_ option( 'update_core');83 $cur = get_preferred_from_update_core(); 16 84 if ( ! isset( $cur->current ) ) 17 85 $cur->current = ''; … … 40 108 41 109 function update_nag() { 42 $cur = get_ option( 'update_core');110 $cur = get_preferred_from_update_core(); 43 111 44 112 if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) … … 56 124 // Called directly from dashboard 57 125 function update_right_now_message() { 58 $cur = get_ option( 'update_core');126 $cur = get_preferred_from_update_core(); 59 127 60 128 $msg = sprintf( __('You are using <span class="b">WordPress %s</span>.'), $GLOBALS['wp_version'] ); … … 321 389 322 390 323 function wp_update_core($ feedback = '') {391 function wp_update_core($current, $feedback = '') { 324 392 global $wp_filesystem; 325 393 … … 330 398 331 399 // Is an update available? 332 $current = get_option( 'update_core' );333 400 if ( !isset( $current->response ) || $current->response == 'latest' ) 334 401 return new WP_Error('up_to_date', __('WordPress is at the latest version.')); -
trunk/wp-admin/menu.php
r9311 r9441 87 87 if ( ! $is_opera ) 88 88 $submenu['import.php'][20] = array( __('Turbo'), 'read', 'turbo.php' ); 89 $submenu['import.php'][30] = array( __('Update'), 'read', wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core')); 89 90 90 91 $menu[50] = array( __('Settings'), 'manage_options', 'options-general.php', '', 'menu-top-last', 'menu-settings', 'images/menu/settings.png' ); -
trunk/wp-admin/update.php
r9279 r9441 123 123 } 124 124 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 125 function list_core_update( $update ) { 126 $version_string = 'en_US' == $update->locale? 127 $update->current : sprintf("%s–<strong>%s</strong>", $update->current, $update->locale); 148 128 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:'); 150 130 $submit = __('Download nightly build'); 151 131 } 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); 154 134 } 155 135 … … 157 137 echo $message; 158 138 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">'; 160 140 wp_nonce_field('upgrade-core'); 161 141 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" /> '; 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> '; 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" />'; 164 151 echo '</p>'; 165 152 echo '</form>'; 166 153 154 } 155 156 function 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 */ 190 function 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(); 167 223 echo '</div>'; 168 224 } 225 169 226 170 227 /** … … 177 234 function do_core_upgrade() { 178 235 global $wp_filesystem; 179 236 180 237 $url = wp_nonce_url('update.php?action=do-core-upgrade', 'upgrade-core'); 181 238 if ( false === ($credentials = request_filesystem_credentials($url)) ) 182 239 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 183 247 184 248 if ( ! WP_Filesystem($credentials) ) { … … 196 260 } 197 261 198 $result = wp_update_core( 'show_message');262 $result = wp_update_core($update, 'show_message'); 199 263 200 264 if ( is_wp_error($result) ) { … … 206 270 } 207 271 echo '</div>'; 272 } 273 274 function 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 284 function 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') ); 208 292 } 209 293 … … 249 333 $title = __('Upgrade WordPress'); 250 334 $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(); 251 341 require_once('admin-header.php'); 252 do_core_upgrade(); 342 if ( isset( $_POST['upgrade'] ) ) 343 do_core_upgrade(); 253 344 include('admin-footer.php'); 254 345 } elseif ( 'upgrade-theme' == $action ) { -
trunk/wp-admin/wp-admin.css
r9436 r9441 2915 2915 font-style: italic; 2916 2916 } 2917 ul#dismissed-updates { 2918 display: none; 2919 } 2920 ul.core-updates li { 2921 padding: 12px; 2922 } 2923 form.upgrade { 2924 margin-top: 8px; 2925 } -
trunk/wp-includes/update.php
r9323 r9441 24 24 return; 25 25 26 global $wp_version, $wpdb ;26 global $wp_version, $wpdb, $wp_local_package; 27 27 $php_version = phpversion(); 28 28 29 29 $current = get_option( 'update_core' ); 30 30 $locale = get_locale(); 31 32 31 if ( 33 32 isset( $current->last_checked ) && … … 36 35 ) 37 36 return false; 38 39 37 $new_option = ''; 40 38 $new_option->last_checked = time(); // this gets set whether we get a response or not, so if something is down or misconfigured it won't delay the page load for more than 3 seconds, twice a day … … 45 43 else 46 44 $mysql_version = 'N/A'; 47 48 $url = "http://api.wordpress.org/core/version-check/1. 2/?version=$wp_version&php=$php_version&locale=$locale&mysql=$mysql_version";45 $local_package = isset( $wp_local_package )? $wp_local_package : ''; 46 $url = "http://api.wordpress.org/core/version-check/1.3/?version=$wp_version&php=$php_version&locale=$locale&mysql=$mysql_version&local_package=$local_package"; 49 47 50 48 $options = array('timeout' => 3); … … 64 62 $body = trim( $response['body'] ); 65 63 $body = str_replace(array("\r\n", "\r"), "\n", $body); 66 $returns = explode("\n", $body); 67 68 $new_option->response = attribute_escape( $returns[0] ); 69 if ( isset( $returns[1] ) ) 70 $new_option->url = clean_url( $returns[1] ); 71 if ( isset( $returns[2] ) ) 72 $new_option->package = clean_url( $returns[2] ); 73 if ( isset( $returns[3] ) ) 74 $new_option->current = attribute_escape( $returns[3] ); 75 if ( isset( $returns[4] ) ) 76 $new_option->locale = attribute_escape( $returns[4] ); 77 78 update_option( 'update_core', $new_option ); 64 $new_options = array(); 65 foreach( explode( "\n\n", $body ) as $entry) { 66 $returns = explode("\n", $entry); 67 $new_option = new stdClass(); 68 $new_option->response = attribute_escape( $returns[0] ); 69 if ( isset( $returns[1] ) ) 70 $new_option->url = clean_url( $returns[1] ); 71 if ( isset( $returns[2] ) ) 72 $new_option->package = clean_url( $returns[2] ); 73 if ( isset( $returns[3] ) ) 74 $new_option->current = attribute_escape( $returns[3] ); 75 if ( isset( $returns[4] ) ) 76 $new_option->locale = attribute_escape( $returns[4] ); 77 $new_options[] = $new_option; 78 } 79 80 update_option( 'update_core', $new_options ); 79 81 } 80 82 add_action( 'init', 'wp_version_check' );
Note: See TracChangeset
for help on using the changeset viewer.