<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[25566] trunk/src: Add a language pack upgrader class.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/25566">25566</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2013-09-23 02:07:51 +0000 (Mon, 23 Sep 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add a language pack upgrader class.
At the conclusion of any upgrade, after the transients are refreshed from the API, pending translations are downloaded and installed to wp-content/languages.
props dd32.
see <a href="http://core.trac.wordpress.org/ticket/18200">#18200</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesclasswpupgraderskinsphp">trunk/src/wp-admin/includes/class-wp-upgrader-skins.php</a></li>
<li><a href="#trunksrcwpadminincludesclasswpupgraderphp">trunk/src/wp-admin/includes/class-wp-upgrader.php</a></li>
<li><a href="#trunksrcwpadminincludesupdatephp">trunk/src/wp-admin/includes/update.php</a></li>
<li><a href="#trunksrcwpincludesupdatephp">trunk/src/wp-includes/update.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesclasswpupgraderskinsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader-skins.php (25565 => 25566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader-skins.php 2013-09-23 00:37:34 UTC (rev 25565)
+++ trunk/src/wp-admin/includes/class-wp-upgrader-skins.php 2013-09-23 02:07:51 UTC (rev 25566)
</span><span class="lines">@@ -608,4 +608,18 @@
</span><span class="cx"> function bulk_footer() {}
</span><span class="cx"> function before() {}
</span><span class="cx"> function after() {}
</span><del>-}
</del><span class="cx">\ No newline at end of file
</span><ins>+}
+
+/**
+ * A basic Upgrader skin which doesn't have any headers or footers.
+ *
+ * @package WordPress
+ * @subpackage Upgrader
+ * @since 3.7.0
+ */
+class Headerless_Upgrader_Skin extends WP_Upgrader_Skin {
+ function before() {}
+ function after() {}
+ function header() {}
+ function footer() {}
+}
</ins></span></pre></div>
<a id="trunksrcwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader.php (25565 => 25566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader.php 2013-09-23 00:37:34 UTC (rev 25565)
+++ trunk/src/wp-admin/includes/class-wp-upgrader.php 2013-09-23 02:07:51 UTC (rev 25566)
</span><span class="lines">@@ -1073,6 +1073,127 @@
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3 );
+class Language_Pack_Upgrader extends WP_Upgrader {
+
+ var $result;
+ var $bulk = true;
+
+ static function async_upgrade( $upgrader, $context, $package ) {
+ // Avoid recursion.
+ if ( $upgrader instanceof Language_Pack_Upgrader )
+ return;
+
+ $lp_upgrader = new Language_Pack_Upgrader( new Headerless_Upgrader_Skin() );
+ $lp_upgrader->upgrade();
+ }
+
+ function upgrade_strings() {
+ $this->strings['starting_upgrade'] = __( 'Some of your language files need updating. Sit tight for a few more seconds while we update them as well.' );
+ $this->strings['up_to_date'] = __( 'The language is up to date.' ); // We need to silently skip this case
+ $this->strings['no_package'] = __( 'Update package not available.' );
+ $this->strings['downloading_package'] = __( 'Downloading language update from <span class="code">%s</span>…' );
+ $this->strings['unpack_package'] = __( 'Unpacking the update…' );
+ $this->strings['process_failed'] = __( 'Language update failed.' );
+ $this->strings['process_success'] = __( 'Language updated successfully.' );
+ }
+
+ function upgrade() {
+ return $this->bulk_upgrade();
+ }
+
+ function bulk_upgrade() {
+
+ $this->init();
+ $this->upgrade_strings();
+
+ $language_updates = wp_get_translation_updates();
+
+ if ( empty( $language_updates ) )
+ return true;
+
+ $this->skin->feedback( 'starting_upgrade' );
+
+ add_filter( 'upgrader_source_selection', array( &$this, 'check_package' ), 10, 3 );
+
+ $this->skin->header();
+
+ // Connect to the Filesystem first.
+ $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );
+ if ( ! $res ) {
+ $this->skin->footer();
+ return false;
+ }
+
+ $results = array();
+
+ $this->update_count = count( $language_updates );
+ $this->update_current = 0;
+ foreach ( $language_updates as $language_update ) {
+
+ $destination = WP_LANG_DIR;
+ if ( 'plugin' == $language_update->type )
+ $destination .= '/plugins';
+ elseif ( 'theme' == $language_update->type )
+ $destination .= '/themes';
+
+ $this->update_current++;
+
+ $options = array(
+ 'package' => $language_update->package,
+ 'destination' => $destination,
+ 'clear_destination' => false,
+ 'abort_if_destination_exists' => false, // We expect the destination to exist.
+ 'clear_working' => true,
+ 'is_multi' => true,
+ 'hook_extra' => array(
+ 'language_update_type' => $language_update->type,
+ 'language_update' => $language_update,
+ )
+ );
+
+ $result = $this->run( $options );
+
+ $results[] = $this->result;
+
+ // Prevent credentials auth screen from displaying multiple times.
+ if ( false === $result )
+ break;
+ }
+
+ // Clean up our hooks, in case something else does an upgrade on this connection.
+ remove_filter( 'upgrader_source_selection', array( &$this, 'check_package' ), 10, 2 );
+
+ return $results;
+ }
+
+ function check_package( $source, $remote_source ) {
+ global $wp_filesystem;
+
+ if ( is_wp_error( $source ) )
+ return $source;
+
+ // Check that the folder contains a valid language.
+ $files = $wp_filesystem->dirlist( $remote_source );
+
+ // Check to see if a .po and .mo exist in the folder.
+ $po = $mo = false;
+ foreach ( (array) $files as $file => $filedata ) {
+ if ( '.po' == substr( $file, -3 ) )
+ $po = true;
+ elseif ( '.mo' == substr( $file, -3 ) )
+ $mo = true;
+ }
+
+ if ( ! $mo || ! $po )
+ 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.' ) );
+
+ return $source;
+ }
+
+}
+
</ins><span class="cx"> /**
</span><span class="cx"> * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combination with the wp-admin/includes/update-core.php file
</span><span class="cx"> *
</span></span></pre></div>
<a id="trunksrcwpadminincludesupdatephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/update.php (25565 => 25566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/update.php 2013-09-23 00:37:34 UTC (rev 25565)
+++ trunk/src/wp-admin/includes/update.php 2013-09-23 02:07:51 UTC (rev 25566)
</span><span class="lines">@@ -379,3 +379,25 @@
</span><span class="cx"> echo "<div class='update-nag'>$msg</div>";
</span><span class="cx"> }
</span><span class="cx"> add_action( 'admin_notices', 'maintenance_nag' );
</span><ins>+
+/**
+ * Retrieves a list of all language updates available.
+ *
+ * @since 3.7.0
+ */
+function wp_get_translation_updates() {
+ $updates = array();
+ $transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' );
+ foreach ( $transients as $transient => $type ) {
+
+ $transient = get_site_transient( $transient );
+ if ( empty( $transient->translations ) )
+ continue;
+
+ foreach ( $transient->translations as $translation ) {
+ $updates[] = (object) $translation;
+ }
+ }
+
+ return $updates;
+}
</ins></span></pre></div>
<a id="trunksrcwpincludesupdatephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/update.php (25565 => 25566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/update.php 2013-09-23 00:37:34 UTC (rev 25565)
+++ trunk/src/wp-includes/update.php 2013-09-23 02:07:51 UTC (rev 25566)
</span><span class="lines">@@ -158,6 +158,9 @@
</span><span class="cx">
</span><span class="cx"> // Check for update on a different schedule, depending on the page.
</span><span class="cx"> switch ( current_filter() ) {
</span><ins>+ case 'upgrader_process_complete' :
+ $timeout = 0;
+ break;
</ins><span class="cx"> case 'load-update-core.php' :
</span><span class="cx"> $timeout = MINUTE_IN_SECONDS;
</span><span class="cx"> break;
</span><span class="lines">@@ -283,6 +286,9 @@
</span><span class="cx">
</span><span class="cx"> // Check for update on a different schedule, depending on the page.
</span><span class="cx"> switch ( current_filter() ) {
</span><ins>+ case 'upgrader_process_complete' :
+ $timeout = 0;
+ break;
</ins><span class="cx"> case 'load-update-core.php' :
</span><span class="cx"> $timeout = MINUTE_IN_SECONDS;
</span><span class="cx"> break;
</span><span class="lines">@@ -485,18 +491,21 @@
</span><span class="cx">
</span><span class="cx"> add_action( 'admin_init', '_maybe_update_core' );
</span><span class="cx"> add_action( 'wp_version_check', 'wp_version_check' );
</span><ins>+add_action( 'upgrader_process_complete', 'wp_version_check' );
</ins><span class="cx">
</span><span class="cx"> add_action( 'load-plugins.php', 'wp_update_plugins' );
</span><span class="cx"> add_action( 'load-update.php', 'wp_update_plugins' );
</span><span class="cx"> add_action( 'load-update-core.php', 'wp_update_plugins' );
</span><span class="cx"> add_action( 'admin_init', '_maybe_update_plugins' );
</span><span class="cx"> add_action( 'wp_update_plugins', 'wp_update_plugins' );
</span><ins>+add_action( 'upgrader_process_complete', 'wp_update_plugins' );
</ins><span class="cx">
</span><span class="cx"> add_action( 'load-themes.php', 'wp_update_themes' );
</span><span class="cx"> add_action( 'load-update.php', 'wp_update_themes' );
</span><span class="cx"> add_action( 'load-update-core.php', 'wp_update_themes' );
</span><span class="cx"> add_action( 'admin_init', '_maybe_update_themes' );
</span><span class="cx"> add_action( 'wp_update_themes', 'wp_update_themes' );
</span><ins>+add_action( 'upgrader_process_complete', 'wp_update_themes' );
</ins><span class="cx">
</span><span class="cx"> // Automatic Updates - Cron callback
</span><span class="cx"> add_action( 'wp_auto_updates_maybe_update', 'wp_auto_updates_maybe_update' );
</span></span></pre>
</div>
</div>
</body>
</html>