Ticket #18200: lp.4.diff
| File lp.4.diff, 16.0 KB (added by dd32, 9 months ago) |
|---|
-
wp-includes/update.php
64 64 $wp_install = home_url( '/' ); 65 65 } 66 66 67 $installed_languages = get_installed_language_files( 'core' ); 68 67 69 $query = array( 68 70 'version' => $wp_version, 69 71 'php' => $php_version, … … 80 82 $options = array( 81 83 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ), 82 84 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 85 'body' => array( 'installed_languages' => serialize( $installed_languages ) ), 83 86 'headers' => array( 84 87 'wp_install' => $wp_install, 85 88 'wp_blog' => home_url( '/' ) 86 89 ) 87 90 ); 88 91 89 $response = wp_remote_ get($url, $options);92 $response = wp_remote_post($url, $options); 90 93 91 94 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) 92 95 return false; … … 154 157 155 158 // Check for update on a different schedule, depending on the page. 156 159 switch ( current_filter() ) { 160 case 'upgrader_process_complete': 161 $timeout = 0; 162 break; 157 163 case 'load-update-core.php' : 158 164 $timeout = MINUTE_IN_SECONDS; 159 165 break; … … 194 200 $current->last_checked = time(); 195 201 set_site_transient( 'update_plugins', $current ); 196 202 203 $installed_languages = get_installed_language_files( 'plugins' ); 204 197 205 $to_send = (object) compact('plugins', 'active'); 198 206 199 207 $options = array( 200 208 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), 201 'body' => array( 'plugins' => serialize( $to_send ) ),209 'body' => array( 'plugins' => serialize( $to_send ), 'installed_languages' => serialize( $installed_languages ) ), 202 210 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 203 211 ); 204 212 … … 263 271 264 272 // Check for update on a different schedule, depending on the page. 265 273 switch ( current_filter() ) { 274 case 'upgrader_process_complete': 275 $timeout = 0; 276 break; 266 277 case 'load-update-core.php' : 267 278 $timeout = MINUTE_IN_SECONDS; 268 279 break; … … 301 312 $last_update->last_checked = time(); 302 313 set_site_transient( 'update_themes', $last_update ); 303 314 315 $installed_languages = get_installed_language_files( 'themes' ); 316 304 317 $options = array( 305 318 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), 306 'body' => array( 'themes' => serialize( $themes ) ),319 'body' => array( 'themes' => serialize( $themes ), 'installed_languages' => serialize( $installed_languages ) ), 307 320 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 308 321 ); 309 322 … … 433 446 434 447 add_action( 'admin_init', '_maybe_update_core' ); 435 448 add_action( 'wp_version_check', 'wp_version_check' ); 449 add_action( 'upgrader_process_complete', 'wp_version_check' ); 436 450 437 451 add_action( 'load-plugins.php', 'wp_update_plugins' ); 438 452 add_action( 'load-update.php', 'wp_update_plugins' ); 439 453 add_action( 'load-update-core.php', 'wp_update_plugins' ); 440 454 add_action( 'admin_init', '_maybe_update_plugins' ); 441 455 add_action( 'wp_update_plugins', 'wp_update_plugins' ); 456 add_action( 'upgrader_process_complete', 'wp_update_plugins' ); 442 457 443 458 add_action( 'load-themes.php', 'wp_update_themes' ); 444 459 add_action( 'load-update.php', 'wp_update_themes' ); 445 460 add_action( 'load-update-core.php', 'wp_update_themes' ); 446 461 add_action( 'admin_init', '_maybe_update_themes' ); 447 462 add_action( 'wp_update_themes', 'wp_update_themes' ); 463 add_action( 'upgrader_process_complete', 'wp_update_themes' ); 448 464 449 465 add_action('init', 'wp_schedule_update_checks'); -
wp-includes/l10n.php
546 546 } 547 547 548 548 return $languages; 549 } 550 551 // Returns a list of translation files and their details. 552 function get_installed_language_files( $type = false ) { 553 $language_files = array(); 554 555 if ( ! is_dir( WP_LANG_DIR ) ) 556 return $language_files; 557 558 $dirs_to_check = array( WP_LANG_DIR ); 559 foreach ( (array)glob( WP_LANG_DIR . '/*', GLOB_ONLYDIR) as $dir ) 560 $dirs_to_check[] = $dir; 561 562 foreach ( $dirs_to_check as $dir ) { 563 foreach ( (array)glob( $dir . '/*.po') as $lang_file ) { 564 $lang_file = str_replace( trailingslashit(WP_LANG_DIR), '', $lang_file ); 565 566 $file_data = get_translation_file_data( $lang_file ); 567 $file_data['file'] = basename( $lang_file ); 568 $file_data['type'] = dirname( $lang_file ); 569 if ( '.' == $file_data['type'] ) 570 $file_data['type'] = 'core'; 571 572 if ( $type && $type != $file_data['type'] ) 573 continue; 574 575 if ( preg_match( '!(.*?)-?([a-z]{2}_[a-z]{2})?\.po!i', $file_data['file'], $lang_match ) ) { 576 $file_data['slug'] = $lang_match[1]; 577 if ( isset( $lang_match[2] ) ) 578 $file_data['language'] = $lang_match[2]; 579 } 580 581 $language_files[] = $file_data; 582 583 } 584 } 585 586 return $language_files; 587 } 588 589 // retrieves the date/generator/project-id headers from a po file relative to WP_LANG_DIR 590 function get_translation_file_data( $file ) { 591 // Just incase someone calls with the machine file instead of the textual version 592 $file = preg_replace( '!\.mo$!i', '.po', $file ); 593 594 // Lets just assume that it's within the WP_LANG_DIR for now 595 // if we keep track of the loaded text domains later, we can probably include a lookup for the location of the files instead. 596 $data = get_file_data( WP_LANG_DIR . '/' . $file, array( 597 'date' => '"PO-Revision-Date', 598 'generator' => '"X-Generator', 599 'project-id' => '"Project-Id-Version' 600 ) ); 601 602 // Strip the .po field endings off the values, which may, or may not, include a textual \n 603 foreach ( (array)$data as $key => $value ) 604 $data[ $key ] = preg_replace( '!(\\\n)?"$!', '', $value); 605 606 return $data; 549 607 } 608 No newline at end of file -
wp-admin/includes/update.php
307 307 echo "<div class='update-nag'>$msg</div>"; 308 308 } 309 309 add_action( 'admin_notices', 'maintenance_nag' ); 310 311 // Retrieves a list of all language updates available. 312 function get_language_updates() { 313 314 $updates = array(); 315 foreach ( array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' ) as $transient => $type ) { 316 317 $transient = get_site_transient( $transient ); 318 if ( empty( $transient->language_updates ) ) 319 continue; 320 321 foreach ( (array)$transient->language_updates as $update ) { 322 if ( empty( $update->type ) ) 323 $update->type = $type; 324 325 $updates[] = $update; 326 } 327 } 328 329 return $updates; 330 331 /* // Expected content: 332 return array( 333 (object)array( 334 'type' => 'core', 335 'lang' => 'de_DE', // The language it is.. This isn't currently used anywhere 336 'version' => '2012-02-18 08:48:04', // New Version - Nothing looks at this either. 337 'package' => 'http://core-downloads/core-de_DE.zip' 338 ), 339 (object)array( 340 '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.. 341 'slug' => 'akismet', // not used. 342 'for' => 'akismet/akismet.php', // again, not used yet. 343 'lang' => 'de_DE', 344 'version' => '2012-02-18 08:48:04', 345 'package' => 'http://core-downloads/akismet-de_DE.zip' 346 ), 347 (object)array( 348 'type' => 'theme', 349 'slug' => 'twentytwelve', 350 'lang' => 'de_DE', 351 'version' => '2012-02-18 08:48:04', 352 'package' => 'http://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. 353 ), 354 ); 355 Zip file expected format: 356 ./akismet-de_DE.mo 357 ./akismet-de_DE.po 358 (ie. Language files bundled together in root, other files such as .php and .css would be kept with it) 359 */ 360 } 361 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 ) ); … … 412 414 // Force refresh of plugin update information 413 415 delete_site_transient('update_plugins'); 414 416 wp_cache_delete( 'plugins', 'plugins' ); 417 do_action( 'upgrader_process_complete', $this, 'install-plugin', $package ); 415 418 416 419 return true; 417 420 } … … 457 460 // Force refresh of plugin update information 458 461 delete_site_transient('update_plugins'); 459 462 wp_cache_delete( 'plugins', 'plugins' ); 463 do_action( 'upgrader_process_complete', $this, 'update-plugin', $plugin ); 460 464 } 461 465 462 466 function bulk_upgrade($plugins) { … … 539 543 // Force refresh of plugin update information 540 544 delete_site_transient('update_plugins'); 541 545 wp_cache_delete( 'plugins', 'plugins' ); 546 do_action( 'upgrader_process_complete', $this, 'bulk-upgrade-plugins', $plugins ); 542 547 543 548 return $results; 544 549 } … … 764 769 765 770 // Force refresh of theme update information 766 771 wp_clean_themes_cache(); 772 do_action( 'upgrader_process_complete', $this, 'install-theme', $package ); 767 773 768 774 return true; 769 775 } … … 810 816 811 817 // Force refresh of theme update information 812 818 wp_clean_themes_cache(); 819 do_action( 'upgrader_process_complete', $this, 'upgrade-theme', $theme ); 813 820 814 821 return true; 815 822 } … … 897 904 898 905 // Force refresh of theme update information 899 906 wp_clean_themes_cache(); 907 do_action( 'upgrader_process_complete', $this, 'bulk-upgrade-themes', $themes ); 900 908 901 909 return $results; 902 910 } … … 1067 1075 if ( ! function_exists( 'update_core' ) ) 1068 1076 return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] ); 1069 1077 1070 return update_core($working_dir, $wp_dir); 1078 $result = update_core($working_dir, $wp_dir); 1079 do_action( 'upgrader_process_complete', $this, 'upgrade-core', $result ); 1080 return $result; 1071 1081 } 1072 1082 1073 1083 } 1074 1084 1085 add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3); 1086 class Language_Pack_Upgrader extends WP_Upgrader { 1087 1088 var $result; 1089 var $bulk = true; 1090 1091 static function async_upgrade( $upgrader, $context, $package ) { 1092 // Don't do Language updates on language updates on language updates.. 1093 if ( $upgrader instanceof Language_Pack_Upgrader ) 1094 return; 1095 1096 echo '<!-- start languages --><div style="padding-left: 3em; border-left: 5px solid grey">'; 1097 1098 $lp_upgrader = new Language_Pack_Upgrader( new Headerless_Skin() ); 1099 1100 $lp_upgrader->upgrade(); 1101 1102 echo '</div><!-- end of languages -->'; 1103 } 1104 function upgrade_strings() { 1105 $this->strings['starting_upgrade'] = __( 'Some of your language files need updating, Sit tight for a few more seconds while we update them as well.' ); 1106 $this->strings['up_to_date'] = __('The language is up to date.'); // We need to silently skip this case 1107 $this->strings['no_package'] = __('Update package not available.'); 1108 $this->strings['downloading_package'] = __('Downloading language update from <span class="code">%s</span>…'); 1109 $this->strings['unpack_package'] = __('Unpacking the update…'); 1110 $this->strings['remove_old'] = __('Removing the old version of the language…'); 1111 $this->strings['remove_old_failed'] = __('Could not remove the old language.'); 1112 $this->strings['process_failed'] = __('Language update failed.'); 1113 $this->strings['process_success'] = __('Language updated successfully.'); 1114 } 1115 1116 function upgrade() { 1117 return $this->bulk_upgrade(); 1118 } 1119 1120 function bulk_upgrade() { 1121 1122 $this->init(); 1123 $this->upgrade_strings(); 1124 1125 $language_updates = get_language_updates(); 1126 1127 if ( empty($language_updates) ) 1128 return true; 1129 1130 $this->skin->feedback( 'starting_upgrade' ); 1131 1132 add_filter('upgrader_source_selection', array(&$this, 'check_package'), 10, 3 ); 1133 1134 $this->skin->header(); 1135 1136 // Connect to the Filesystem first. 1137 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_LANG_DIR) ); 1138 if ( ! $res ) { 1139 $this->skin->footer(); 1140 return false; 1141 } 1142 1143 $results = array(); 1144 1145 $this->update_count = count($language_updates); 1146 $this->update_current = 0; 1147 foreach ( $language_updates as $language_update ) { 1148 1149 $destination = WP_LANG_DIR; 1150 if ( 'plugin' == $language_update->type ) { 1151 $destination .= '/plugins'; 1152 } elseif ( 'theme' == $language_update->type ) { 1153 $destination .= '/themes'; 1154 } 1155 1156 $this->update_current++; 1157 1158 $options = array( 1159 'package' => $language_update->package, 1160 'destination' => $destination, 1161 'clear_destination' => false, 1162 'abort_if_destination_exists' => false, // We expect the destination to exist. 1163 'clear_working' => true, 1164 'is_multi' => true, 1165 'hook_extra' => array( 1166 'language_update_type' => $language_update->type, 1167 'language_update' => $language_update, 1168 ) 1169 ); 1170 1171 $result = $this->run($options); 1172 1173 $results[] = $this->result; 1174 1175 // Prevent credentials auth screen from displaying multiple times 1176 if ( false === $result ) 1177 break; 1178 } //end foreach $language_updates 1179 1180 // Cleanup our hooks, in case something else does a upgrade on this connection. 1181 remove_filter('upgrader_source_selection', array(&$this, 'check_package'), 10, 2 ); 1182 1183 return $results; 1184 } 1185 1186 function check_package( $source, $remote_source ) { 1187 global $wp_filesystem; 1188 1189 if ( is_wp_error($source) ) 1190 return $source; 1191 1192 // Check the folder contains a valid language 1193 $files = $wp_filesystem->dirlist( $remote_source ); 1194 1195 // Check to see if a .po and .mo exist in the folder.. 1196 $po = $mo = false; 1197 foreach ( (array)$files as $file => $filedata ) { 1198 if ( '.po' == substr( $file, -3) ) 1199 $po = true; 1200 elseif ( '.mo' == substr($file, -3) ) 1201 $mo = true; 1202 } 1203 1204 if ( ! $mo || ! $po ) 1205 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.' ) ); 1206 1207 return $source; 1208 } 1209 1210 } 1211 1075 1212 /** 1076 1213 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. 1077 1214 * … … 1160 1297 } 1161 1298 1162 1299 /** 1300 * A basic Upgrader skin which doesn't have any Header/Footers 1301 * 1302 * @package WordPress 1303 * @subpackage Upgrader 1304 * @since 3.4.0 1305 */ 1306 class Headerless_Skin extends WP_Upgrader_Skin { 1307 function before() {} 1308 function after() {} 1309 function header() {} 1310 function footer() {} 1311 } 1312 1313 /** 1163 1314 * Plugin Upgrader Skin for WordPress Plugin Upgrades. 1164 1315 * 1165 1316 * @TODO More Detailed docs, for methods as well.