Ticket #18200: lp.2.diff
| File lp.2.diff, 15.0 KB (added by dd32, 15 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; … … 193 196 $current->last_checked = time(); 194 197 set_site_transient( 'update_plugins', $current ); 195 198 199 $installed_languages = get_installed_language_files( 'plugins' ); 200 196 201 $to_send = (object) compact('plugins', 'active'); 197 202 198 203 $options = array( 199 204 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), 200 'body' => array( 'plugins' => serialize( $to_send ) ),205 'body' => array( 'plugins' => serialize( $to_send ), 'installed_languages' => serialize( $installed_languages ) ), 201 206 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 202 207 ); 203 208 … … 302 307 $last_update->last_checked = time(); 303 308 set_site_transient( 'update_themes', $last_update ); 304 309 310 $installed_languages = get_installed_language_files( 'themes' ); 311 305 312 $options = array( 306 313 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), 307 'body' => array( 'themes' => serialize( $themes ) ),314 'body' => array( 'themes' => serialize( $themes ), 'installed_languages' => serialize( $installed_languages ) ), 308 315 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 309 316 ); 310 317 -
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 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 … … 761 769 if ( ! $this->result || is_wp_error($this->result) ) 762 770 return $this->result; 763 771 772 do_action( 'upgrader_process_complete', $this, 'install-theme', $package ); 773 764 774 // Force refresh of theme update information 765 775 delete_site_transient('update_themes'); 766 776 … … 807 817 if ( ! $this->result || is_wp_error($this->result) ) 808 818 return $this->result; 809 819 820 do_action( 'upgrader_process_complete', $this, 'upgrade-theme', $theme ); 821 810 822 // Force refresh of theme update information 811 823 delete_site_transient('update_themes'); 812 824 … … 894 906 remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); 895 907 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); 896 908 909 do_action( 'upgrader_process_complete', $this, 'bulk-upgrade-themes', $themes ); 910 897 911 // Force refresh of theme update information 898 912 delete_site_transient('update_themes'); 899 913 … … 1064 1078 1065 1079 require(ABSPATH . 'wp-admin/includes/update-core.php'); 1066 1080 1081 // @TODO: Add the upgrader_process_complete bizzo here somewhere 1067 1082 return update_core($working_dir, $wp_dir); 1068 1083 } 1069 1084 1070 1085 } 1071 1086 1087 add_action( 'upgrader_process_complete', 'Language_Pack_Upgrader::async_upgrade', 10, 3); 1088 class Language_Pack_Upgrader extends WP_Upgrader { 1089 1090 var $result; 1091 var $bulk = true; 1092 1093 static function async_upgrade( $upgrader, $context, $package ) { 1094 // Don't do Language updates on language updates on language updates.. 1095 if ( $upgrader instanceof Language_Pack_Upgrader ) 1096 return; 1097 1098 echo '<!-- start languages --><div style="padding-left: 3em; border-left: 5px solid grey">'; 1099 1100 $lp_upgrader = new Language_Pack_Upgrader( new Headerless_Skin() ); 1101 1102 $lp_upgrader->upgrade(); 1103 1104 echo '</div><!-- end of languages -->'; 1105 } 1106 function upgrade_strings() { 1107 $this->strings['starting_upgrade'] = __( 'Some of your language files need updating, Sit tight for a few more seconds while we update them as well.' ); 1108 $this->strings['up_to_date'] = __('The language is up to date.'); // We need to silently skip this case 1109 $this->strings['no_package'] = __('Update package not available.'); 1110 $this->strings['downloading_package'] = __('Downloading language update from <span class="code">%s</span>…'); 1111 $this->strings['unpack_package'] = __('Unpacking the update…'); 1112 $this->strings['remove_old'] = __('Removing the old version of the language…'); 1113 $this->strings['remove_old_failed'] = __('Could not remove the old language.'); 1114 $this->strings['process_failed'] = __('Language update failed.'); 1115 $this->strings['process_success'] = __('Language updated successfully.'); 1116 } 1117 1118 function upgrade() { 1119 return $this->bulk_upgrade(); 1120 } 1121 1122 function bulk_upgrade() { 1123 1124 $this->init(); 1125 $this->upgrade_strings(); 1126 1127 $language_updates = get_language_updates(); 1128 1129 if ( empty($language_updates) ) 1130 return true; 1131 1132 $this->skin->feedback( 'starting_upgrade' ); 1133 1134 add_filter('upgrader_source_selection', array(&$this, 'check_package'), 10, 3 ); 1135 1136 $this->skin->header(); 1137 1138 // Connect to the Filesystem first. 1139 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_LANG_DIR) ); 1140 if ( ! $res ) { 1141 $this->skin->footer(); 1142 return false; 1143 } 1144 1145 $results = array(); 1146 1147 $this->update_count = count($language_updates); 1148 $this->update_current = 0; 1149 foreach ( $language_updates as $language_update ) { 1150 1151 $destination = WP_LANG_DIR; 1152 if ( 'plugin' == $language_update->type ) { 1153 $destination .= '/plugins'; 1154 } elseif ( 'theme' == $language_update->type ) { 1155 $destination .= '/themes'; 1156 } 1157 1158 $this->update_current++; 1159 1160 $options = array( 1161 'package' => $language_update->package, 1162 'destination' => $destination, 1163 'clear_destination' => false, 1164 'abort_if_destination_exists' => false, // We expect the destination to exist. 1165 'clear_working' => true, 1166 'is_multi' => true, 1167 'hook_extra' => array( 1168 'language_update_type' => $language_update->type, 1169 'language_update' => $language_update, 1170 ) 1171 ); 1172 1173 $result = $this->run($options); 1174 1175 $results[] = $this->result; 1176 1177 // Prevent credentials auth screen from displaying multiple times 1178 if ( false === $result ) 1179 break; 1180 } //end foreach $language_updates 1181 1182 // Cleanup our hooks, in case something else does a upgrade on this connection. 1183 remove_filter('upgrader_source_selection', array(&$this, 'check_package'), 10, 2 ); 1184 1185 // Force refresh of language update information 1186 delete_site_transient('update_languages'); 1187 1188 return $results; 1189 } 1190 1191 function check_package( $source, $remote_source ) { 1192 global $wp_filesystem; 1193 1194 if ( is_wp_error($source) ) 1195 return $source; 1196 1197 // Check the folder contains a valid language 1198 $files = $wp_filesystem->dirlist( $remote_source ); 1199 1200 // Check to see if a .po and .mo exist in the folder.. 1201 $po = $mo = false; 1202 foreach ( (array)$files as $file => $filedata ) { 1203 if ( '.po' == substr( $file, -3) ) 1204 $po = true; 1205 elseif ( '.mo' == substr($file, -3) ) 1206 $mo = true; 1207 } 1208 1209 if ( ! $mo || ! $po ) 1210 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.' ) ); 1211 1212 return $source; 1213 } 1214 1215 } 1216 1072 1217 /** 1073 1218 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. 1074 1219 * … … 1157 1302 } 1158 1303 1159 1304 /** 1305 * A basic Upgrader skin which doesn't have any Header/Footers 1306 * 1307 * @package WordPress 1308 * @subpackage Upgrader 1309 * @since 3.4.0 1310 */ 1311 class Headerless_Skin extends WP_Upgrader_Skin { 1312 function before() {} 1313 function after() {} 1314 function header() {} 1315 function footer() {} 1316 } 1317 1318 /** 1160 1319 * Plugin Upgrader Skin for WordPress Plugin Upgrades. 1161 1320 * 1162 1321 * @TODO More Detailed docs, for methods as well.