Ticket #18200: lp.5.diff
File lp.5.diff, 17.9 KB (added by , 10 years ago) |
---|
-
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. -
wp-admin/includes/update.php
308 308 echo "<div class='update-nag'>$msg</div>"; 309 309 } 310 310 add_action( 'admin_notices', 'maintenance_nag' ); 311 312 // Retrieves a list of all language updates available. 313 function get_language_updates() { 314 315 $updates = array(); 316 foreach ( array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' ) as $transient => $type ) { 317 318 $transient = get_site_transient( $transient ); 319 if ( empty( $transient->language_updates ) ) 320 continue; 321 322 foreach ( (array)$transient->language_updates as $update ) { 323 if ( empty( $update->type ) ) 324 $update->type = $type; 325 326 $updates[] = $update; 327 } 328 } 329 330 return $updates; 331 332 /* // Expected content: 333 return array( 334 (object)array( 335 'type' => 'core', 336 'lang' => 'de_DE', // The language it is.. This isn't currently used anywhere 337 'version' => '2012-02-18 08:48:04', // New Version - Nothing looks at this either. 338 'package' => 'http://core-downloads/core-de_DE.zip' 339 ), 340 (object)array( 341 '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.. 342 'slug' => 'akismet', // not used. 343 'for' => 'akismet/akismet.php', // again, not used yet. 344 'lang' => 'de_DE', 345 'version' => '2012-02-18 08:48:04', 346 'package' => 'http://core-downloads/akismet-de_DE.zip' 347 ), 348 (object)array( 349 'type' => 'theme', 350 'slug' => 'twentytwelve', 351 'lang' => 'de_DE', 352 'version' => '2012-02-18 08:48:04', 353 '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. 354 ), 355 ); 356 Zip file expected format: 357 ./akismet-de_DE.mo 358 ./akismet-de_DE.po 359 (ie. Language files bundled together in root, other files such as .php and .css would be kept with it) 360 */ 361 } 362 No newline at end of file -
wp-includes/l10n.php
550 550 } 551 551 552 552 return $languages; 553 } 554 No newline at end of file 553 } 554 555 // Returns a list of translation files and their details. 556 function get_installed_language_files( $type = false ) { 557 $language_files = array(); 558 559 if ( ! is_dir( WP_LANG_DIR ) ) 560 return $language_files; 561 562 $dirs_to_check = array( WP_LANG_DIR ); 563 foreach ( (array)glob( WP_LANG_DIR . '/*', GLOB_ONLYDIR) as $dir ) 564 $dirs_to_check[] = $dir; 565 566 foreach ( $dirs_to_check as $dir ) { 567 foreach ( (array)glob( $dir . '/*.po') as $lang_file ) { 568 $lang_file = str_replace( trailingslashit(WP_LANG_DIR), '', $lang_file ); 569 570 $file_data = get_translation_file_data( $lang_file ); 571 $file_data['file'] = basename( $lang_file ); 572 $file_data['type'] = dirname( $lang_file ); 573 if ( '.' == $file_data['type'] ) 574 $file_data['type'] = 'core'; 575 576 if ( $type && $type != $file_data['type'] ) 577 continue; 578 579 if ( preg_match( '!(.*?)-?([a-z]{2}_[a-z]{2})?\.po!i', $file_data['file'], $lang_match ) ) { 580 $file_data['slug'] = $lang_match[1]; 581 if ( isset( $lang_match[2] ) ) 582 $file_data['language'] = $lang_match[2]; 583 } 584 585 $language_files[] = $file_data; 586 587 } 588 } 589 590 return $language_files; 591 } 592 593 // retrieves the date/generator/project-id headers from a po file relative to WP_LANG_DIR 594 function get_translation_file_data( $file ) { 595 // Just incase someone calls with the machine file instead of the textual version 596 $file = preg_replace( '!\.mo$!i', '.po', $file ); 597 598 // Lets just assume that it's within the WP_LANG_DIR for now 599 // if we keep track of the loaded text domains later, we can probably include a lookup for the location of the files instead. 600 $data = get_file_data( WP_LANG_DIR . '/' . $file, array( 601 'date' => '"PO-Revision-Date', 602 'generator' => '"X-Generator', 603 'project-id' => '"Project-Id-Version' 604 ) ); 605 606 // Strip the .po field endings off the values, which may, or may not, include a textual \n 607 foreach ( (array)$data as $key => $value ) 608 $data[ $key ] = preg_replace( '!(\\\n)?"$!', '', $value); 609 610 return $data; 611 } 612 No newline at end of file -
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; … … 117 120 $updates->updates = $offers; 118 121 $updates->last_checked = time(); 119 122 $updates->version_checked = $wp_version; 123 if ( isset( $body['language_updates'] ) ) 124 $updates->language_updates = $body['language_updates']; 120 125 set_site_transient( 'update_core', $updates); 121 126 } 122 127 … … 154 159 155 160 // Check for update on a different schedule, depending on the page. 156 161 switch ( current_filter() ) { 162 case 'upgrader_process_complete': 163 $timeout = 0; 164 break; 157 165 case 'load-update-core.php' : 158 166 $timeout = MINUTE_IN_SECONDS; 159 167 break; … … 194 202 $current->last_checked = time(); 195 203 set_site_transient( 'update_plugins', $current ); 196 204 205 $installed_languages = get_installed_language_files( 'plugins' ); 206 197 207 $to_send = (object) compact('plugins', 'active'); 198 208 199 209 $options = array( 200 210 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), 201 'body' => array( 'plugins' => serialize( $to_send ) ),211 'body' => array( 'plugins' => serialize( $to_send ), 'installed_languages' => serialize( $installed_languages ) ), 202 212 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 203 213 ); 204 214 … … 209 219 210 220 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); 211 221 212 if ( is_array( $response ) ) 222 if ( is_array( $response ) ) { 223 if ( isset( $response['language_updates'] ) ) { 224 $new_option->language_updates = $response['language_updates']; 225 unset( $response['language_updates'] ); 226 } 213 227 $new_option->response = $response; 214 else228 } else { 215 229 $new_option->response = array(); 230 } 216 231 217 232 set_site_transient( 'update_plugins', $new_option ); 218 233 } … … 263 278 264 279 // Check for update on a different schedule, depending on the page. 265 280 switch ( current_filter() ) { 281 case 'upgrader_process_complete': 282 $timeout = 0; 283 break; 266 284 case 'load-update-core.php' : 267 285 $timeout = MINUTE_IN_SECONDS; 268 286 break; … … 301 319 $last_update->last_checked = time(); 302 320 set_site_transient( 'update_themes', $last_update ); 303 321 322 $installed_languages = get_installed_language_files( 'themes' ); 323 304 324 $options = array( 305 325 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), 306 'body' => array( 'themes' => serialize( $themes ) ),326 'body' => array( 'themes' => serialize( $themes ), 'installed_languages' => serialize( $installed_languages ) ), 307 327 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 308 328 ); 309 329 … … 317 337 $new_update->checked = $checked; 318 338 319 339 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); 320 if ( is_array( $response ) ) 340 341 if ( is_array( $response ) ) { 342 if ( isset( $response['language_updates'] ) ) { 343 $new_update->language_updates = $response['language_updates']; 344 unset( $response['language_updates'] ); 345 } 321 346 $new_update->response = $response; 347 } 322 348 323 349 set_site_transient( 'update_themes', $new_update ); 324 350 } … … 433 459 434 460 add_action( 'admin_init', '_maybe_update_core' ); 435 461 add_action( 'wp_version_check', 'wp_version_check' ); 462 add_action( 'upgrader_process_complete', 'wp_version_check' ); 436 463 437 464 add_action( 'load-plugins.php', 'wp_update_plugins' ); 438 465 add_action( 'load-update.php', 'wp_update_plugins' ); 439 466 add_action( 'load-update-core.php', 'wp_update_plugins' ); 440 467 add_action( 'admin_init', '_maybe_update_plugins' ); 441 468 add_action( 'wp_update_plugins', 'wp_update_plugins' ); 469 add_action( 'upgrader_process_complete', 'wp_update_plugins' ); 442 470 443 471 add_action( 'load-themes.php', 'wp_update_themes' ); 444 472 add_action( 'load-update.php', 'wp_update_themes' ); 445 473 add_action( 'load-update-core.php', 'wp_update_themes' ); 446 474 add_action( 'admin_init', '_maybe_update_themes' ); 447 475 add_action( 'wp_update_themes', 'wp_update_themes' ); 476 add_action( 'upgrader_process_complete', 'wp_update_themes' ); 448 477 449 478 add_action('init', 'wp_schedule_update_checks');