Ticket #18200: patch.diff
| File patch.diff, 11.4 KB (added by dd32, 15 months ago) |
|---|
-
wp-includes/l10n.php
540 540 } 541 541 542 542 return $languages; 543 } 544 545 // retrieves the date/generator/project-id headers from a po file relative to WP_LANG_DIR 546 function get_translation_file_data( $file ) { 547 // Just incase someone calls with the machine file instead of the textual version 548 $file = preg_replace( '!\.mo$!i', '.po', $file ); 549 550 // Lets just assume that it's within the WP_LANG_DIR for now 551 // if we keep track of the loaded text domains later, we can probably include a lookup for the location of the files instead. 552 $data = get_file_data( WP_LANG_DIR . '/' . $file, 553 array( 554 'date' => '"PO-Revision-Date', 555 'generator' => '"X-Generator', 556 'project-id' => '"Project-Id-Version' 557 ) 558 ); 559 560 // Strip the .po field endings off the values, which may, or may not, include a textual \n 561 foreach ( (array)$data as $key => $value ) 562 $data[$key] = preg_replace( '!(\\\n)?"$!', '', $value); 563 564 return $data; 543 565 } 566 No newline at end of file -
wp-admin/includes/update.php
229 229 return $update_themes; 230 230 } 231 231 232 function get_language_updates() { 233 234 //$current = get_site_transient('update_languages'); 235 // Uh ...Lets just hard code this for now. 236 237 return array( 238 (object)array( 239 'type' => 'core', 240 'lang' => 'de_DE', // The language it is.. This isn't currently used anywhere 241 'version' => '2012-02-18 08:48:04', // New Version - Nothing looks at this either. 242 'package' => 'http://tools.dd32.id.au/wordpress/core-downloads/core-de_DE.zip' 243 ), 244 (object)array( 245 '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.. 246 'slug' => 'akismet', // not used. 247 'for' => 'akismet/akismet.php', // again, not used yet. 248 'lang' => 'de_DE', 249 'version' => '2012-02-18 08:48:04', 250 'package' => 'http://tools.dd32.id.au/wordpress/core-downloads/akismet-de_DE.zip' 251 ), 252 (object)array( 253 'type' => 'theme', 254 'slug' => 'twentytwelve', 255 'lang' => 'de_DE', 256 'version' => '2012-02-18 08:48:04', 257 '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. 258 ) 259 ); 260 } 261 232 262 function wp_update_theme($theme, $feedback = '') { 233 263 if ( !empty($feedback) ) 234 264 add_filter('update_feedback', $feedback); -
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 415 do_action( 'upgrader_process_complete', $this, 'install-plugin', $package ); 416 413 417 // Force refresh of plugin update information 414 418 delete_site_transient('update_plugins'); 415 419 … … 454 458 if ( ! $this->result || is_wp_error($this->result) ) 455 459 return $this->result; 456 460 461 do_action( 'upgrader_process_complete', $this, 'update-plugin', $plugin ); 462 457 463 // Force refresh of plugin update information 458 464 delete_site_transient('update_plugins'); 459 465 } … … 535 541 // Cleanup our hooks, in case something else does a upgrade on this connection. 536 542 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); 537 543 544 do_action( 'upgrader_process_complete', $this, 'bulk-upgrade-plugins', $plugins ); 545 538 546 // Force refresh of plugin update information 539 547 delete_site_transient('update_plugins'); 540 548 … … 685 693 if ( ! $this->result || is_wp_error($this->result) ) 686 694 return $this->result; 687 695 696 do_action( 'upgrader_process_complete', $this, 'install-theme', $package ); 697 688 698 // Force refresh of theme update information 689 699 delete_site_transient('update_themes'); 690 700 … … 731 741 if ( ! $this->result || is_wp_error($this->result) ) 732 742 return $this->result; 733 743 744 do_action( 'upgrader_process_complete', $this, 'upgrade-theme', $theme ); 745 734 746 // Force refresh of theme update information 735 747 delete_site_transient('update_themes'); 736 748 … … 818 830 remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); 819 831 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); 820 832 833 do_action( 'upgrader_process_complete', $this, 'bulk-upgrade-themes', $themes ); 834 821 835 // Force refresh of theme update information 822 836 delete_site_transient('update_themes'); 823 837 … … 985 999 986 1000 require(ABSPATH . 'wp-admin/includes/update-core.php'); 987 1001 1002 // @TODO: Add the upgrader_process_complete bizzo here somewhere 988 1003 return update_core($working_dir, $wp_dir); 989 1004 } 990 1005 991 1006 } 992 1007 1008 add_action( 'upgrader_process_complete', 'Language_Pack_Upgrader::async_upgrade', 10, 3); 1009 class Language_Pack_Upgrader extends WP_Upgrader { 1010 1011 var $result; 1012 var $bulk = true; 1013 1014 static function async_upgrade( $upgrader, $context, $package ) { 1015 // Don't do Language updates on language updates on language updates.. 1016 if ( $upgrader instanceof Language_Pack_Upgrader ) 1017 return; 1018 1019 echo '<!-- start languages --><div style="padding-left: 3em; border-left: 5px solid grey">'; 1020 1021 $lp_upgrader = new Language_Pack_Upgrader( new Headerless_Skin() ); 1022 1023 $lp_upgrader->upgrade(); 1024 1025 echo '</div><!-- end of languages -->'; 1026 } 1027 function upgrade_strings() { 1028 $this->strings['stating_upgrade'] = __( 'Some of your language files need updating, Sit tight for a few more seconds while we update them as well.' ); 1029 $this->strings['up_to_date'] = __('The language is up to date.'); // We need to silently skip this case 1030 $this->strings['no_package'] = __('Update package not available.'); 1031 $this->strings['downloading_package'] = __('Downloading language update from <span class="code">%s</span>…'); 1032 $this->strings['unpack_package'] = __('Unpacking the update…'); 1033 $this->strings['remove_old'] = __('Removing the old version of the language…'); 1034 $this->strings['remove_old_failed'] = __('Could not remove the old language.'); 1035 $this->strings['process_failed'] = __('Language update failed.'); 1036 $this->strings['process_success'] = __('Language updated successfully.'); 1037 } 1038 1039 function upgrade() { 1040 return $this->bulk_upgrade(); 1041 } 1042 1043 function bulk_upgrade() { 1044 1045 $this->init(); 1046 $this->upgrade_strings(); 1047 1048 $language_updates = get_language_updates(); 1049 1050 if ( empty($language_updates) ) 1051 return true; 1052 1053 $this->skin->feedback( 'starting_upgrade' ); 1054 1055 add_filter('upgrader_source_selection', array(&$this, 'check_package'), 10, 3 ); 1056 1057 $this->skin->header(); 1058 1059 // Connect to the Filesystem first. 1060 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_LANG_DIR) ); 1061 if ( ! $res ) { 1062 $this->skin->footer(); 1063 return false; 1064 } 1065 1066 $results = array(); 1067 1068 $this->update_count = count($language_updates); 1069 $this->update_current = 0; 1070 foreach ( $language_updates as $language_update ) { 1071 1072 $destination = WP_LANG_DIR; 1073 if ( 'plugin' == $language_update->type ) { 1074 $destination .= '/plugins'; 1075 } elseif ( 'theme' == $language_update->type ) { 1076 $destination .= '/themes'; 1077 } 1078 1079 $this->update_current++; 1080 1081 $options = array( 1082 'package' => $language_update->package, 1083 'destination' => $destination, 1084 'clear_destination' => false, 1085 'abort_if_destination_exists' => false, // We expect the destination to exist. 1086 'clear_working' => true, 1087 'is_multi' => true, 1088 'hook_extra' => array( 1089 'language_update_type' => $language_update->type, 1090 'language_update' => $language_update, 1091 ) 1092 ); 1093 1094 $result = $this->run($options); 1095 1096 $results[] = $this->result; 1097 1098 // Prevent credentials auth screen from displaying multiple times 1099 if ( false === $result ) 1100 break; 1101 } //end foreach $language_updates 1102 1103 // Cleanup our hooks, in case something else does a upgrade on this connection. 1104 remove_filter('upgrader_source_selection', array(&$this, 'check_package'), 10, 2 ); 1105 1106 // Force refresh of language update information 1107 delete_site_transient('update_languages'); 1108 1109 return $results; 1110 } 1111 1112 function check_package( $source, $remote_source ) { 1113 global $wp_filesystem; 1114 1115 if ( is_wp_error($source) ) 1116 return $source; 1117 1118 // Check the folder contains a valid language 1119 $files = $wp_filesystem->dirlist( $remote_source ); 1120 1121 // Check to see if a .po and .mo exist in the folder.. check they're named right? 1122 $po = $mo = false; 1123 foreach ( (array)$files as $file => $filedata ) { 1124 if ( '.po' == substr( $file, -3) ) 1125 $po = true; 1126 elseif ( '.mo' == substr($file, -3) ) 1127 $mo = true; 1128 } 1129 1130 if ( ! $mo || ! $po ) 1131 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.' ) ); 1132 1133 return $source; 1134 } 1135 1136 } 1137 993 1138 /** 994 1139 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. 995 1140 * … … 1078 1223 } 1079 1224 1080 1225 /** 1226 * A basic Upgrader skin which doesn't have any Header/Footers 1227 * 1228 * @package WordPress 1229 * @subpackage Upgrader 1230 * @since 3.4.0 1231 */ 1232 class Headerless_Skin extends WP_Upgrader_Skin { 1233 function before() {} 1234 function after() {} 1235 function header() {} 1236 function footer() {} 1237 } 1238 1239 /** 1081 1240 * Plugin Upgrader Skin for WordPress Plugin Upgrades. 1082 1241 * 1083 1242 * @TODO More Detailed docs, for methods as well.
