Ticket #18200: lp.3.diff
| File lp.3.diff, 17.5 KB (added by dd32, 14 months ago) |
|---|
-
wp-includes/update.php
63 63 $wp_install = home_url( '/' ); 64 64 } 65 65 66 $installed_languages = get_installed_language_files( 'core' ); 67 66 68 $query = array( 67 69 'version' => $wp_version, 68 70 'php' => $php_version, … … 79 81 $options = array( 80 82 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ), 81 83 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 84 'body' => array( 'installed_languages' => serialize( $installed_languages ) ), 82 85 'headers' => array( 83 86 'wp_install' => $wp_install, 84 87 'wp_blog' => home_url( '/' ) 85 88 ) 86 89 ); 87 90 88 $response = wp_remote_ get($url, $options);91 $response = wp_remote_post($url, $options); 89 92 90 93 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) 91 94 return false; … … 142 145 if ( !function_exists( 'get_plugins' ) ) 143 146 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 144 147 148 // If we've just finished an update, get some fresh data 149 if ( 'upgrader_process_complete' == current_filter() ) 150 wp_cache_delete( 'plugins', 'plugins' ); 151 145 152 $plugins = get_plugins(); 146 153 $active = get_option( 'active_plugins', array() ); 147 154 $current = get_site_transient( 'update_plugins' ); … … 153 160 154 161 // Check for update on a different schedule, depending on the page. 155 162 switch ( current_filter() ) { 163 case 'upgrader_process_complete': 164 $timeout = 0; 165 break; 156 166 case 'load-update-core.php' : 157 167 $timeout = 60; // 1 min 158 168 break; … … 193 203 $current->last_checked = time(); 194 204 set_site_transient( 'update_plugins', $current ); 195 205 206 $installed_languages = get_installed_language_files( 'plugins' ); 207 196 208 $to_send = (object) compact('plugins', 'active'); 197 209 198 210 $options = array( 199 211 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), 200 'body' => array( 'plugins' => serialize( $to_send ) ),212 'body' => array( 'plugins' => serialize( $to_send ), 'installed_languages' => serialize( $installed_languages ) ), 201 213 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 202 214 ); 203 215 … … 235 247 if ( defined( 'WP_INSTALLING' ) ) 236 248 return false; 237 249 250 //if ( 'upgrader_process_complete' == current_filter() ) 251 // delete_some_magical_cache(); 252 238 253 $installed_themes = wp_get_themes(); 239 254 $last_update = get_site_transient( 'update_themes' ); 240 255 if ( ! is_object($last_update) ) … … 262 277 263 278 // Check for update on a different schedule, depending on the page. 264 279 switch ( current_filter() ) { 280 case 'upgrader_process_complete': 281 $timeout = 0; 282 break; 265 283 case 'load-update-core.php' : 266 284 $timeout = 60; // 1 min 267 285 break; … … 302 320 $last_update->last_checked = time(); 303 321 set_site_transient( 'update_themes', $last_update ); 304 322 323 $installed_languages = get_installed_language_files( 'themes' ); 324 305 325 $options = array( 306 326 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), 307 'body' => array( 'themes' => serialize( $themes ) ),327 'body' => array( 'themes' => serialize( $themes ), 'installed_languages' => serialize( $installed_languages ) ), 308 328 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 309 329 ); 310 330 … … 434 454 435 455 add_action( 'admin_init', '_maybe_update_core' ); 436 456 add_action( 'wp_version_check', 'wp_version_check' ); 457 add_action( 'upgrader_process_complete', 'wp_version_check' ); 437 458 438 459 add_action( 'load-plugins.php', 'wp_update_plugins' ); 439 460 add_action( 'load-update.php', 'wp_update_plugins' ); 440 461 add_action( 'load-update-core.php', 'wp_update_plugins' ); 441 462 add_action( 'admin_init', '_maybe_update_plugins' ); 442 463 add_action( 'wp_update_plugins', 'wp_update_plugins' ); 464 add_action( 'upgrader_process_complete', 'wp_update_plugins' ); // NOTE: This is used to force the updates to be done after upgrades, retrieving any new language file updates for the now installed plugin/theme. Has the side benefit that the Buble updates with the correct update number on next pageload! 443 465 444 466 add_action( 'load-themes.php', 'wp_update_themes' ); 445 467 add_action( 'load-update.php', 'wp_update_themes' ); 446 468 add_action( 'load-update-core.php', 'wp_update_themes' ); 447 469 add_action( 'admin_init', '_maybe_update_themes' ); 448 470 add_action( 'wp_update_themes', 'wp_update_themes' ); 471 add_action( 'upgrader_process_complete', 'wp_update_themes' ); 449 472 450 473 add_action('init', 'wp_schedule_update_checks'); -
wp-includes/l10n.php
540 540 } 541 541 542 542 return $languages; 543 } 544 545 // Returns a list of translation files and their details. 546 function get_installed_language_files( $type = false ) { 547 $language_files = array(); 548 549 if ( ! is_dir( WP_LANG_DIR ) ) 550 return array(); 551 552 $dirs_to_check = array( WP_LANG_DIR ); 553 foreach ( (array)glob( WP_LANG_DIR . '/*', GLOB_ONLYDIR) as $dir ) 554 $dirs_to_check[] = $dir; 555 556 foreach ( $dirs_to_check as $dir ) { 557 foreach ( (array)glob( $dir . '/*.po') as $lang_file ) { 558 $lang_file = str_replace( trailingslashit(WP_LANG_DIR), '', $lang_file ); 559 560 $file_data = get_translation_file_data( $lang_file ); 561 $file_data['file'] = basename( $lang_file ); 562 $file_data['type'] = dirname( $lang_file ); 563 if ( '.' == $file_data['type'] ) 564 $file_data['type'] = 'core'; 565 566 if ( preg_match( '!(.*?)-?([a-z]{2}_[a-z]{2})?\.po!i', $file_data['file'], $lang_match ) ) { 567 $file_data['slug'] = $lang_match[1]; 568 if ( isset( $lang_match[2] ) ) 569 $file_data['language'] = $lang_match[2]; 570 } 571 572 $language_files[] = $file_data; 573 574 } 575 } 576 577 // @TODO: Wasteful, Slot this into the above somewhere instead 578 if ( $type ) 579 $language_files = wp_list_filter( $language_files, array( 'type' => $type ) ); 580 581 return $language_files; 582 } 583 584 // retrieves the date/generator/project-id headers from a po file relative to WP_LANG_DIR 585 function get_translation_file_data( $file ) { 586 // Just incase someone calls with the machine file instead of the textual version 587 $file = preg_replace( '!\.mo$!i', '.po', $file ); 588 589 // Lets just assume that it's within the WP_LANG_DIR for now 590 // if we keep track of the loaded text domains later, we can probably include a lookup for the location of the files instead. 591 $data = get_file_data( WP_LANG_DIR . '/' . $file, 592 array( 593 'date' => '"PO-Revision-Date', 594 'generator' => '"X-Generator', 595 'project-id' => '"Project-Id-Version' 596 ) 597 ); 598 599 // Strip the .po field endings off the values, which may, or may not, include a textual \n 600 foreach ( (array)$data as $key => $value ) 601 $data[$key] = preg_replace( '!(\\\n)?"$!', '', $value); 602 603 return $data; 543 604 } 605 No newline at end of file -
wp-admin/includes/update.php
301 301 echo "<div class='update-nag'>$msg</div>"; 302 302 } 303 303 add_action( 'admin_notices', 'maintenance_nag' ); 304 305 // Retrieves a list of all language updates available. 306 function get_language_updates() { 307 308 $updates = array(); 309 foreach ( array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' ) as $transient => $type ) { 310 311 $transient = get_site_transient( $transient ); 312 if ( empty( $transient->language_updates ) ) 313 continue; 314 315 foreach ( (array)$transient->language_updates as $update ) { 316 if ( empty( $update->type ) ) 317 $update->type = $type; 318 319 $updates[] = $update; 320 } 321 } 322 323 return $updates; 324 325 /* // Expected content: 326 return array( 327 (object)array( 328 'type' => 'core', 329 'lang' => 'de_DE', // The language it is.. This isn't currently used anywhere 330 'version' => '2012-02-18 08:48:04', // New Version - Nothing looks at this either. 331 'package' => 'http://tools.dd32.id.au/wordpress/core-downloads/core-de_DE.zip' 332 ), 333 (object)array( 334 'type' => 'plugin', // The type of the upgrade, 'plugin' or 'theme' will throw files into that folder, any other name (ie. 'core') is thrown into WP_LANG_DIR.. 335 'slug' => 'akismet', // not used. 336 'for' => 'akismet/akismet.php', // again, not used yet. 337 'lang' => 'de_DE', 338 'version' => '2012-02-18 08:48:04', 339 'package' => 'http://tools.dd32.id.au/wordpress/core-downloads/akismet-de_DE.zip' 340 ), 341 (object)array( 342 'type' => 'theme', 343 'slug' => 'twentytwelve', 344 'lang' => 'de_DE', 345 'version' => '2012-02-18 08:48:04', 346 'package' => 'http://tools.dd32.id.au/wordpress/core-downloads/twentytwelve-de_DE.zip' // And no, this isn't a translation of 2012, I believe it's a out of date Core set. 347 ) 348 );*/ 349 } 350 No newline at end of file -
wp-admin/includes/class-wp-upgrader.php
165 165 function install_package($args = array()) { 166 166 global $wp_filesystem; 167 167 $defaults = array( 'source' => '', 'destination' => '', //Please always pass these 168 'clear_destination' => false, 'clear_working' => false, 168 'clear_destination' => false, 'clear_working' => false, 'abort_if_destination_exists' => true, 169 169 'hook_extra' => array()); 170 170 171 171 $args = wp_parse_args($args, $defaults); … … 224 224 return $removed; 225 225 else if ( ! $removed ) 226 226 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); 227 } elseif ( $ wp_filesystem->exists($remote_destination) ) {227 } elseif ( $abort_if_destination_exists && $wp_filesystem->exists($remote_destination) ) { 228 228 //If we're not clearing the destination folder and something exists there already, Bail. 229 229 //But first check to see if there are actually any files in the folder. 230 230 $_files = $wp_filesystem->dirlist($remote_destination); … … 272 272 $defaults = array( 'package' => '', //Please always pass this. 273 273 'destination' => '', //And this 274 274 'clear_destination' => false, 275 'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please 275 276 'clear_working' => true, 276 277 'is_multi' => false, 277 278 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters. … … 318 319 'source' => $working_dir, 319 320 'destination' => $destination, 320 321 'clear_destination' => $clear_destination, 322 'abort_if_destination_exists' => $abort_if_destination_exists, 321 323 'clear_working' => $clear_working, 322 324 'hook_extra' => $hook_extra 323 325 ) ); … … 410 412 if ( ! $this->result || is_wp_error($this->result) ) 411 413 return $this->result; 412 414 413 // Force refresh of plugin update information 414 delete_site_transient('update_plugins'); 415 do_action( 'upgrader_process_complete', $this, 'install-plugin', $package ); 415 416 416 417 return true; 417 418 } … … 454 455 if ( ! $this->result || is_wp_error($this->result) ) 455 456 return $this->result; 456 457 457 // Force refresh of plugin update information458 delete_site_transient('update_plugins'); 458 do_action( 'upgrader_process_complete', $this, 'update-plugin', $plugin ); 459 459 460 } 460 461 461 462 function bulk_upgrade($plugins) { … … 535 536 // Cleanup our hooks, in case something else does a upgrade on this connection. 536 537 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); 537 538 538 // Force refresh of plugin update information 539 delete_site_transient('update_plugins'); 539 do_action( 'upgrader_process_complete', $this, 'bulk-upgrade-plugins', $plugins ); 540 540 541 541 return $results; 542 542 } … … 761 761 if ( ! $this->result || is_wp_error($this->result) ) 762 762 return $this->result; 763 763 764 // Force refresh of theme update information 765 delete_site_transient('update_themes'); 764 do_action( 'upgrader_process_complete', $this, 'install-theme', $package ); 766 765 767 766 return true; 768 767 } … … 807 806 if ( ! $this->result || is_wp_error($this->result) ) 808 807 return $this->result; 809 808 810 // Force refresh of theme update information 811 delete_site_transient('update_themes'); 809 do_action( 'upgrader_process_complete', $this, 'upgrade-theme', $theme ); 812 810 813 811 return true; 814 812 } … … 894 892 remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); 895 893 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); 896 894 897 // Force refresh of theme update information 898 delete_site_transient('update_themes'); 895 do_action( 'upgrader_process_complete', $this, 'bulk-upgrade-themes', $themes ); 899 896 900 897 return $results; 901 898 } … … 1064 1061 1065 1062 require(ABSPATH . 'wp-admin/includes/update-core.php'); 1066 1063 1064 // @TODO: Add the upgrader_process_complete bizzo here somewhere 1067 1065 return update_core($working_dir, $wp_dir); 1068 1066 } 1069 1067 1070 1068 } 1071 1069 1070 add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3); 1071 class Language_Pack_Upgrader extends WP_Upgrader { 1072 1073 var $result; 1074 var $bulk = true; 1075 1076 static function async_upgrade( $upgrader, $context, $package ) { 1077 // Don't do Language updates on language updates on language updates.. 1078 if ( $upgrader instanceof Language_Pack_Upgrader ) 1079 return; 1080 1081 echo '<!-- start languages --><div style="padding-left: 3em; border-left: 5px solid grey">'; 1082 1083 $lp_upgrader = new Language_Pack_Upgrader( new Headerless_Skin() ); 1084 1085 $lp_upgrader->upgrade(); 1086 1087 echo '</div><!-- end of languages -->'; 1088 } 1089 function upgrade_strings() { 1090 $this->strings['starting_upgrade'] = __( 'Some of your language files need updating, Sit tight for a few more seconds while we update them as well.' ); 1091 $this->strings['up_to_date'] = __('The language is up to date.'); // We need to silently skip this case 1092 $this->strings['no_package'] = __('Update package not available.'); 1093 $this->strings['downloading_package'] = __('Downloading language update from <span class="code">%s</span>…'); 1094 $this->strings['unpack_package'] = __('Unpacking the update…'); 1095 $this->strings['remove_old'] = __('Removing the old version of the language…'); 1096 $this->strings['remove_old_failed'] = __('Could not remove the old language.'); 1097 $this->strings['process_failed'] = __('Language update failed.'); 1098 $this->strings['process_success'] = __('Language updated successfully.'); 1099 } 1100 1101 function upgrade() { 1102 return $this->bulk_upgrade(); 1103 } 1104 1105 function bulk_upgrade() { 1106 1107 $this->init(); 1108 $this->upgrade_strings(); 1109 1110 $language_updates = get_language_updates(); 1111 1112 if ( empty($language_updates) ) 1113 return true; 1114 1115 $this->skin->feedback( 'starting_upgrade' ); 1116 1117 add_filter('upgrader_source_selection', array(&$this, 'check_package'), 10, 3 ); 1118 1119 $this->skin->header(); 1120 1121 // Connect to the Filesystem first. 1122 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_LANG_DIR) ); 1123 if ( ! $res ) { 1124 $this->skin->footer(); 1125 return false; 1126 } 1127 1128 $results = array(); 1129 1130 $this->update_count = count($language_updates); 1131 $this->update_current = 0; 1132 foreach ( $language_updates as $language_update ) { 1133 1134 $destination = WP_LANG_DIR; 1135 if ( 'plugin' == $language_update->type ) { 1136 $destination .= '/plugins'; 1137 } elseif ( 'theme' == $language_update->type ) { 1138 $destination .= '/themes'; 1139 } 1140 1141 $this->update_current++; 1142 1143 $options = array( 1144 'package' => $language_update->package, 1145 'destination' => $destination, 1146 'clear_destination' => false, 1147 'abort_if_destination_exists' => false, // We expect the destination to exist. 1148 'clear_working' => true, 1149 'is_multi' => true, 1150 'hook_extra' => array( 1151 'language_update_type' => $language_update->type, 1152 'language_update' => $language_update, 1153 ) 1154 ); 1155 1156 $result = $this->run($options); 1157 1158 $results[] = $this->result; 1159 1160 // Prevent credentials auth screen from displaying multiple times 1161 if ( false === $result ) 1162 break; 1163 } //end foreach $language_updates 1164 1165 // Cleanup our hooks, in case something else does a upgrade on this connection. 1166 remove_filter('upgrader_source_selection', array(&$this, 'check_package'), 10, 2 ); 1167 1168 return $results; 1169 } 1170 1171 function check_package( $source, $remote_source ) { 1172 global $wp_filesystem; 1173 1174 if ( is_wp_error($source) ) 1175 return $source; 1176 1177 // Check the folder contains a valid language 1178 $files = $wp_filesystem->dirlist( $remote_source ); 1179 1180 // Check to see if a .po and .mo exist in the folder.. 1181 $po = $mo = false; 1182 foreach ( (array)$files as $file => $filedata ) { 1183 if ( '.po' == substr( $file, -3) ) 1184 $po = true; 1185 elseif ( '.mo' == substr($file, -3) ) 1186 $mo = true; 1187 } 1188 1189 if ( ! $mo || ! $po ) 1190 return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __( 'The language pack is missing either the <code>.po</code> or <code>.mo</code> files.' ) ); 1191 1192 return $source; 1193 } 1194 1195 } 1196 1072 1197 /** 1073 1198 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. 1074 1199 * … … 1157 1282 } 1158 1283 1159 1284 /** 1285 * A basic Upgrader skin which doesn't have any Header/Footers 1286 * 1287 * @package WordPress 1288 * @subpackage Upgrader 1289 * @since 3.4.0 1290 */ 1291 class Headerless_Skin extends WP_Upgrader_Skin { 1292 function before() {} 1293 function after() {} 1294 function header() {} 1295 function footer() {} 1296 } 1297 1298 /** 1160 1299 * Plugin Upgrader Skin for WordPress Plugin Upgrades. 1161 1300 * 1162 1301 * @TODO More Detailed docs, for methods as well.
