<!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>[2881] sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory: Translate, Plugin Directory: Switch to using namespaces and an autoloader.</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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/2881">2881</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/2881","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-04-02 15:59:41 +0000 (Sat, 02 Apr 2016)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Translate, Plugin Directory: Switch to using namespaces and an autoloader.

The autoloader is copied from the Plugin Directory plugin: https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-autoloader.php

See <a href="http://meta.trac.wordpress.org/ticket/1636">#1636</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectorywporggpplugindirectoryphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/wporg-gp-plugin-directory.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/</li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cache-purge/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccachepurgeclasscachepurgerphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cache-purge/class-cache-purger.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryincclasspluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/class-plugin.php</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccliclassdeletepluginprojectphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-delete-plugin-project.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccliclassimportplugintranslationsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-import-plugin-translations.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccliclasssetpluginprojectphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-set-plugin-project.php</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/vendor/</li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/vendor/wordpressdotorg/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryvendorwordpressdotorgclassautoloaderphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/vendor/wordpressdotorg/class-autoloader.php</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/cli/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryincclideletepluginprojectphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/delete-plugin-project.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccliimportplugintranslationsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/import-plugin-translations.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryincclisetpluginprojectphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/set-plugin-project.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccachepurgeclasscachepurgerphpfromrev2880sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectorywporggpplugindirectoryphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cache-purge/class-cache-purger.php (from rev 2880, sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/wporg-gp-plugin-directory.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cache-purge/class-cache-purger.php                         (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cache-purge/class-cache-purger.php   2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,185 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\GlotPress\Plugin_Directory\Cache_Purge;
+
+use GP;
+
+class Cache_Purger {
+       public $master_project   = 'wp-plugins';
+       public $i18n_cache_group = 'plugins-i18n';
+
+       private $translation_edits_queue = array();
+
+       /**
+        * Registers actions and filters.
+        */
+       public function register_events() {
+               add_action( 'init', array( $this, 'add_global_cache_group' ) );
+               add_action( 'gp_originals_imported', array( $this, 'originals_imported' ) );
+               add_action( 'gp_translation_created', array( $this, 'queue_translation_for_cache_purge' ) );
+               add_action( 'gp_translation_saved', array( $this, 'queue_translation_for_cache_purge' ) );
+
+               // Cache purging is delayed until shutdown to prevent multiple purges for the same project.
+               add_action( 'shutdown', array( $this, 'delete_plugin_i18n_cache_on_translation_edits' ) );
+       }
+
+       /**
+        * Registers the global cache group wordpress.org/plugins/ uses for its display cache.
+        */
+       public function add_global_cache_group() {
+               wp_cache_add_global_groups( $this->i18n_cache_group );
+       }
+
+       /**
+        * Triggers a cache purge when a new originals were imported.
+        *
+        * @param int $project_id The project ID.
+        */
+       public function originals_imported( $project_id ) {
+               $project = GP::$project->get( $project_id );
+               if ( empty( $project->path ) || ! $this->project_is_plugin( $project->path ) ) {
+                       return;
+               }
+
+               $this->delete_plugin_i18n_cache_keys_for_project( $project_id );
+       }
+
+       /**
+        * Adds a translation to a cache purge queue when a translation was created
+        * or updated.
+        *
+        * @param \GP_Translation $translation Created/updated translation.
+        */
+       public function queue_translation_for_cache_purge( $translation ) {
+               if ( ! $this->project_is_plugin( $_SERVER['REQUEST_URI'] ) ) {
+                       return;
+               }
+
+               $this->translation_edits_queue[ $translation->original_id ][ $translation->translation_set_id ] = true;
+       }
+
+       /**
+        * Deletes the cache on a translation edits.
+        */
+       public function delete_plugin_i18n_cache_on_translation_edits() {
+               if ( empty( $this->translation_edits_queue ) ) {
+                       return;
+               }
+
+               $purged = array();
+               foreach ( $this->translation_edits_queue as $original_id => $set_ids ) {
+                       $original = GP::$original->get( $original_id );
+                       if ( ! $original ) {
+                               return;
+                       }
+
+                       foreach ( array_keys( $set_ids ) as $set_id ) {
+                               if ( in_array( "{$original->project_id}-{$set_id}", $purged ) ) {
+                                       continue;
+                               }
+
+                               $translation_set = GP::$translation_set->get( $set_id );
+                               if ( ! $translation_set ) {
+                                       return;
+                               }
+
+                               $this->delete_plugin_i18n_cache_keys_for_locale( $original->project_id, $translation_set->locale );
+                               $purged[] = "{$original->project_id}-{$set_id}";
+                       }
+               }
+       }
+
+       /**
+        * Returns whether a project path belongs to the plugins project.
+        *
+        * @param string $path Path of a project.
+        *
+        * @return bool True if it's a plugin, false if not.
+        */
+       private function project_is_plugin( $path ) {
+               if ( empty( $path ) ) {
+                       return false;
+               }
+
+               $path = '/' . trim( $path, '/' ) . '/';
+               if ( false === strpos( $path, "/{$this->master_project}/" ) ) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       /**
+        * Builds the cache prefix for a plugin.
+        *
+        * @param int $project_id The project ID.
+        *
+        * @return string The cache prefix, empty if project isn't a plugin.
+        */
+       private function get_plugin_i18n_cache_prefix( $project_id ) {
+               $project = GP::$project->get( $project_id );
+               if ( empty( $project->path ) || ! $this->project_is_plugin( $project->path ) ) {
+                       return '';
+               }
+
+               $project_dirs = explode( '/', trim( $project->path, '/' ) );
+               if ( empty( $project_dirs ) || 3 !== count( $project_dirs ) || $project_dirs[0] !== $this->master_project ) {
+                       return '';
+               }
+
+               return "{$this->master_project}:{$project_dirs[1]}:{$project_dirs[2]}";
+       }
+
+       /**
+        * Deletes a set of known cache keys for a plugin.
+        *
+        * @param string $prefix Cache key prefix, such as 'plugin:livejournal-importer:readme-stable'.
+        * @param string $set    Set, such as 'original', 'fr', 'de'.
+        */
+       private function delete_plugin_i18n_cache_keys_for( $prefix, $set ) {
+               $suffixes = array(
+                       'translation_set_id', 'title', 'short_description', 'installation', 'description',
+                       'faq', 'screenshots', 'changelog', 'other_notes',
+               );
+               foreach ( $suffixes as $suffix ) {
+                       $cache_key = "{$prefix}:{$set}:{$suffix}";
+                       wp_cache_delete( $cache_key, $this->i18n_cache_group );
+               }
+       }
+
+       /**
+        * Deletes the cached originals of a plugin.
+        *
+        * @param int $project_id The project ID.
+        */
+       private function delete_plugin_i18n_cache_keys_for_project( $project_id ) {
+               $prefix = $this->get_plugin_i18n_cache_prefix( (int) $project_id );
+               if ( ! $prefix ) {
+                       return;
+               }
+
+               wp_cache_delete( "{$prefix}:originals", $this->i18n_cache_group );
+               wp_cache_delete( "{$prefix}:branch_id", $this->i18n_cache_group );
+               $this->delete_plugin_i18n_cache_keys_for( $prefix, 'original' );
+
+               $translation_sets = (array) GP::$translation_set->by_project_id( $project_id );
+               foreach ( $translation_sets as $translation_set ) {
+                       $this->delete_plugin_i18n_cache_keys_for( $prefix, $translation_set->locale );
+               }
+       }
+
+       /**
+        * Deletes a cache keys of a locale for a plugin.
+        *
+        * @param int    $project_id The project ID.
+        * @param string $locale     GlotPress slug of a locale.
+        */
+       private function delete_plugin_i18n_cache_keys_for_locale( $project_id, $locale ) {
+               $prefix = $this->get_plugin_i18n_cache_prefix( (int) $project_id );
+               if ( ! $prefix ) {
+                       return;
+               }
+
+               $this->delete_plugin_i18n_cache_keys_for( $prefix, $locale );
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryincclasspluginphpfromrev2880sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectorywporggpplugindirectoryphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/class-plugin.php (from rev 2880, sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/wporg-gp-plugin-directory.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/class-plugin.php                           (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/class-plugin.php     2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,53 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\GlotPress\Plugin_Directory;
+
+use WP_CLI;
+
+class Plugin {
+
+       /**
+        * @var Plugin The singleton instance.
+        */
+       private static $instance;
+
+       /**
+        * Returns always the same instance of this plugin.
+        *
+        * @return Plugin
+        */
+       public static function get_instance() {
+               if ( ! ( self::$instance instanceof Plugin ) ) {
+                       self::$instance = new Plugin();
+               }
+               return self::$instance;
+       }
+
+       /**
+        * Instantiates a new Plugin object.
+        */
+       private function __construct() {
+               add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
+       }
+
+       /**
+        * Initializes the plugin.
+        */
+       public function plugins_loaded() {
+               $cache_purger = new Cache_Purge\Cache_Purger();
+               $cache_purger->register_events();
+
+               if ( defined( 'WP_CLI' ) && WP_CLI ) {
+                       $this->register_cli_commands();
+               }
+       }
+
+       /**
+        * Registers CLI commands if WP-CLI is loaded.
+        */
+       function register_cli_commands() {
+               WP_CLI::add_command( 'wporg-translate import-plugin-translations', __NAMESPACE__ . '\CLI\Import_Plugin_Translations' );
+               WP_CLI::add_command( 'wporg-translate set-plugin-project', __NAMESPACE__ . '\CLI\Set_Plugin_Project' );
+               WP_CLI::add_command( 'wporg-translate delete-plugin-project', __NAMESPACE__ . '\CLI\Delete_Plugin_Project' );
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccliclassdeletepluginprojectphpfromrev2858sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryclideletepluginprojectphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-delete-plugin-project.php (from rev 2858, sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/cli/delete-plugin-project.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-delete-plugin-project.php                                (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-delete-plugin-project.php  2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,99 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\GlotPress\Plugin_Directory\CLI;
+
+use GP;
+use WP_CLI;
+use WP_CLI_Command;
+
+class Delete_Plugin_Project extends WP_CLI_Command {
+
+       /**
+        * Holds the path of the master project.
+        *
+        * @var string
+        */
+       private $master_project_path = 'wp-plugins';
+
+       /**
+        * Delete a plugin project and its translations.
+        *
+        * ## OPTIONS
+        *
+        * <slug>
+        * : Slug of a plugin
+        *
+        * [--force]
+        * : If set, the command will delete the plugin, without prompting
+        * for confirmation.
+        */
+       public function __invoke( $args, $assoc_args ) {
+               global $wpdb;
+
+               $project_path = sprintf( '%s/%s', $this->master_project_path, $args[0] );
+
+               $project = GP::$project->by_path( $project_path );
+               if ( ! $project ) {
+                       WP_CLI::error( sprintf( "There is no plugin project for '%s'.", $args[0] ) );
+               }
+
+               $sub_projects = $project->sub_projects();
+
+               if ( ! isset( $assoc_args['force'] ) ) {
+                       WP_CLI::confirm( sprintf( "Do you want to delete %s with %d sub-projects?", $project->name, ( $sub_projects ? count( $sub_projects ) : 0 ) ) );
+               }
+
+               // Handle sub-projects.
+               if ( $sub_projects ) {
+                       foreach ( $sub_projects as $sub_project ) {
+                               // Get translation sets...
+                               $sets = GP::$translation_set->by_project_id( $sub_project->id );
+
+                               if ( $sets ) {
+                                       foreach ( $sets as $set ) {
+                                               // ... and delete its translations.
+                                               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_translations} WHERE translation_set_id = %d", $set->id ) );
+                                               WP_CLI::line( sprintf( "%d translations for %s/%s deleted.", $result, $set->locale, $set->slug ) );
+
+                                               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_translation_sets} WHERE id = %d", $set->id ) );
+                                               WP_CLI::line( sprintf( "%d translation sets for %s/%s deleted.", $result, $set->locale, $set->slug ) );
+
+                                               gp_clean_translation_set_cache( $set->id );
+                                       }
+                               }
+
+                               // Delete originals.
+                               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_originals} WHERE project_id = %d", $sub_project->id ) );
+                               WP_CLI::line( sprintf( "%d originals for %s deleted.", $result, $sub_project->path ) );
+
+                               // Delete sub project.
+                               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_projects} WHERE id = %d", $sub_project->id ) );
+                               WP_CLI::line( sprintf( "%d sub project %s deleted.", $result, $sub_project->path ) );
+                       }
+               } else {
+                       // Get translation sets...
+                       $sets = GP::$translation_set->by_project_id( $project->id );
+
+                       if ( $sets ) {
+                               foreach ( $sets as $set ) {
+                                       // ... and delete its translations.
+                                       $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_translations} WHERE translation_set_id = %d", $set->id ) );
+                                       WP_CLI::line( sprintf( "%d translations for %s/%s deleted.", $result, $set->locale, $set->slug ) );
+
+                                       $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_translation_sets} WHERE id = %d", $set->id ) );
+                                       WP_CLI::line( sprintf( "%d translation sets for %s/%s deleted.", $result, $set->locale, $set->slug ) );
+
+                                       gp_clean_translation_set_cache( $set->id );
+                               }
+                       }
+
+                       // Delete originals.
+                       $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_originals} WHERE project_id = %d", $project->id ) );
+                       WP_CLI::line( sprintf( "%d originals for %s deleted.", $result, $project->path ) );
+               }
+
+               // Delete project.
+               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_projects} WHERE id = %d", $project->id ) );
+               WP_CLI::line( sprintf( "%d project %s deleted.", $result, $project->path ) );
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccliclassimportplugintranslationsphpfromrev2858sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectorycliimportplugintranslationsphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-import-plugin-translations.php (from rev 2858, sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/cli/import-plugin-translations.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-import-plugin-translations.php                           (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-import-plugin-translations.php     2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,95 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\GlotPress\Plugin_Directory\CLI;
+
+use GP;
+use GP_Locales;
+use WP_CLI;
+use WP_CLI_Command;
+
+class Import_Plugin_Translations extends WP_CLI_Command {
+
+       /**
+        * Import plugin translations.
+        *
+        * ## OPTIONS
+        *
+        * <project>
+        * : Project path
+        *
+        * <locale>
+        * : Locale to export
+        *
+        * <file>
+        * : File to import
+        *
+        * [--format=<format>]
+        * : Accepted values: po, mo. Default: po
+        *
+        * [--set=<set>]
+        * : Translation set slug: Default: "default"
+        *
+        * [--disable-propagating]
+        * : If set, propagation will be disabled.
+        */
+       public function __invoke( $args, $assoc_args ) {
+               $file = basename( $args[2] );
+
+               // Sanitize arguments.
+               $project = GP::$project->by_path( $args[0] );
+               if ( ! $project ) {
+                       WP_CLI::error( "Project not found! [$file]" );
+               }
+
+               $locale = GP_Locales::by_field( 'wp_locale', $args[1] );
+               if ( ! $locale ) {
+                       $locale = GP_Locales::by_field( 'slug', $args[1] );
+               }
+
+               if ( ! $locale ) {
+                       WP_CLI::error( "Locale not found! [$file]" );
+               }
+
+               $format = gp_array_get( GP::$formats, isset( $assoc_args['format'] ) ?  $assoc_args['format'] : 'po', null );
+               if ( ! $format ) {
+                       WP_CLI::error( "No such format! [$file]" );
+               }
+
+               $set_slug = isset( $assoc_args['set'] ) ? $assoc_args['set'] : 'default';
+               $translation_set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $set_slug, $locale->slug );
+               if ( ! $translation_set ) {
+                       WP_CLI::error( "Translation set not found! [$file]" );
+               }
+
+               // Load the translations into memory.
+               $translations = $format->read_translations_from_file( $args[2], $project );
+               if ( ! $translations ) {
+                       WP_CLI::error( "Couldn't load translations from file! [$file]" );
+               }
+
+               $disable_propagating = isset( $assoc_args['disable-propagating'] );
+
+               if ( $disable_propagating ) {
+                       add_filter( 'enable_propagate_translations_across_projects', '__return_false' );
+               }
+
+               add_filter( 'translation_set_import_over_existing', '__return_false' );
+               //add_filter( 'translation_set_import_status', array( $this, '__string_status_waiting' ) );
+
+               // Do the import.
+               $imported = $translation_set->import( $translations );
+
+               //remove_filter( 'translation_set_import_status', '__string_status_waiting' );
+               remove_filter( 'translation_set_import_over_existing', '__return_false' );
+
+               if ( $disable_propagating ) {
+                       remove_filter( 'enable_propagate_translations_across_projects', '__return_false' );
+               }
+
+               WP_CLI::success( "Imported $imported strings for {$locale->english_name} [$file]" );
+       }
+
+       public function __string_status_waiting() {
+               return 'waiting';
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccliclasssetpluginprojectphpfromrev2858sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryclisetpluginprojectphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-set-plugin-project.php (from rev 2858, sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/cli/set-plugin-project.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-set-plugin-project.php                           (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-set-plugin-project.php     2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,292 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\GlotPress\Plugin_Directory\CLI;
+
+use GP;
+use WP_CLI;
+use WP_CLI_Command;
+
+class Set_Plugin_Project extends WP_CLI_Command {
+
+       /**
+        * Holds the path of the master project.
+        *
+        * @var string
+        */
+       private $master_project_path = 'wp-plugins';
+
+       /**
+        * Holds the path of the projects to copy translation sets from.
+        *
+        * @var string
+        */
+       private $project_path_for_sets = 'wp/dev';
+
+       /**
+        * Add/update a plugin project.
+        *
+        * ## OPTIONS
+        *
+        * <slug>
+        * : Slug of a plugin
+        *
+        * <type>
+        * : Process type. Accepted values: dev, dev-readme, stable, stable-readme.
+        *
+        */
+       public function __invoke( $args, $assoc_args ) {
+               if ( ! preg_match( '/^[^\/]+$/', $args[0] ) ) {
+                       WP_CLI::line( sprintf( "The plugin slug '%s' contains invalid characters.", $args[0] ) );
+                       exit( 1 );
+               }
+
+               $plugin_slug         = $args[0];
+               $process_type        = $args[1];
+               $plugin_project_path = "{$this->master_project_path}/{$plugin_slug}";
+
+               // Get data for master parent project.
+               $master_project = GP::$project->by_path( $this->master_project_path );
+               if ( ! $master_project ) {
+                       WP_CLI::line( sprintf( "The master project '%s' couldn't be found.", $this->master_project_path ) );
+                       exit( 2 );
+               }
+
+               // Get plugin details like title and description.
+               $plugin_details = $this->get_plugin_details( $plugin_slug );
+               if ( ! $plugin_details ) {
+                       WP_CLI::line( "The plugin API couldn't be reached." );
+                       exit( 3 );
+               }
+
+               // Get or create the plugin GP project.
+               $project_args = array(
+                       'name'              => $plugin_details->name,
+                       'slug'              => $plugin_slug,
+                       'parent_project_id' => $master_project->id,
+                       'description'       => $plugin_details->short_description . "<br><br><a href='https://wordpress.org/plugins/{$plugin_slug}'>WordPress.org Plugin Page</a>",
+                       'active'            => 1,
+               );
+
+               $plugin_project = GP::$project->by_path( $plugin_project_path );
+
+               // Is this a new or an existing project?
+               $new_project_flag = true;
+
+               if ( ! $plugin_project ) {
+                       WP_CLI::line( "Creating project for {$plugin_project_path}." );
+
+                       $plugin_project = GP::$project->create_and_select( $project_args );
+                       if ( ! $plugin_project ) {
+                               WP_CLI::line( "Couldn't create project for {$plugin_project_path}." );
+                               exit( 5 );
+                       }
+               } else {
+                       WP_CLI::line( "Updating project for {$plugin_project_path}." );
+
+                       // This is an existing project.
+                       $new_project_flag = false;
+
+                       // Update the project details.
+                       $plugin_project->update( $project_args );
+               }
+
+               // The current stable SVN tag.
+               $stable_tag = empty( $plugin_details->stable_tag ) ? 'trunk' : $plugin_details->stable_tag;
+
+               // Deal with the always-existing dev|dev-readme branch.
+               $plugin_dev_branch_project = $this->handle_plugin_project_branches(
+                       $plugin_project_path,
+                       $plugin_slug,
+                       $plugin_details->name,
+                       $plugin_project->id,
+                       $process_type,
+                       $stable_tag,
+                       'dev'
+               );
+
+               // Deal with the stable|stable-readme branch, if needed.
+               $plugin_stable_branch_project = false;
+               if ( 'trunk' !== $stable_tag ) {
+                       $plugin_stable_branch_project = $this->handle_plugin_project_branches(
+                               $plugin_project_path,
+                               $plugin_slug,
+                               $plugin_details->name,
+                               $plugin_project->id,
+                               $process_type,
+                               $stable_tag,
+                               'stable'
+                       );
+               }
+
+               // Deal with initial translation sets.
+               $source_project = GP::$project->by_path( $this->project_path_for_sets );
+               if ( $source_project && $plugin_dev_branch_project ) {
+                       $translation_sets = (array) GP::$translation_set->by_project_id( $source_project->id );
+
+                       if ( $translation_sets ) {
+                               $this->add_translation_sets_to_branches( $translation_sets, $plugin_dev_branch_project );
+
+                               if ( $plugin_stable_branch_project ) {
+                                       $this->add_translation_sets_to_branches( $translation_sets, $plugin_stable_branch_project );
+                               }
+                       }
+               }
+
+               WP_CLI::line( ( $new_project_flag ? 'Created' : 'Updated' ) . " https://translate.wordpress.org/projects/{$plugin_project_path}" );
+               exit( 0 );
+       }
+
+       /**
+        * Creates/updates sub-projects for plugins.
+        *
+        * @param string $plugin_project_path Path to the plugin project.
+        * @param string $plugin_slug         Slug of the plugin.
+        * @param string $plugin_name         Name of the plugin.
+        * @param int    $parent_id           ID of the main project.
+        * @param string $process_type        Type of the project, 'code' or 'readme'.
+        * @param string $stable_tag          The stable SVN tag of the plugin.
+        * @param string $branch_slug         Slug of the project, 'dev' or 'stable'.
+        * @return GP_Project|null A GP_Project instance on success, null on failure.
+        */
+       private function handle_plugin_project_branches( $plugin_project_path, $plugin_slug, $plugin_name, $parent_id, $process_type, $stable_tag, $branch_slug ) {
+               if ( ! in_array( $branch_slug, array( 'dev', 'stable' ) ) ) {
+                       $branch_slug = 'dev';
+               }
+
+               $is_stable = 'stable' === $branch_slug;
+
+               if ( 'code' !== $process_type ) {
+                       $process_type = 'readme';
+               }
+
+               if ( 'code' === $process_type ) {
+                       $branch_project_path = "{$plugin_project_path}/{$branch_slug}";
+                       $source_url_template = sprintf(
+                               'https://plugins.trac.wordpress.org/browser/%s/%s/%s',
+                               $plugin_slug,
+                               $is_stable ? "tags/{$stable_tag}" : 'trunk',
+                               '%file%#L%line%'
+                       );
+
+                       $project_args = array(
+                               'name'                => $is_stable ? 'Stable (latest release)' : 'Development (trunk)',
+                               'slug'                => $branch_slug,
+                               'parent_project_id'   => $parent_id,
+                               'description'         => ( $is_stable ? 'Stable' : 'Development' ) . " version of the {$plugin_name} plugin.",
+                               'source_url_template' => $source_url_template,
+                               'active'              => 1,
+                       );
+
+                       $branch_project = GP::$project->by_path( $branch_project_path );
+                       if ( ! $branch_project ) {
+                               $branch_project = GP::$project->create_and_select( $project_args );
+                               if ( ! $branch_project ) {
+                                       WP_CLI::line( "Sorry, but couldn't create nonexistent https://translate.wordpress.org/projects/{$branch_project_path}." );
+                               } else {
+                                       WP_CLI::line( "Created https://translate.wordpress.org/projects/{$branch_project_path}." );
+                               }
+                       } else {
+                               $updated = $branch_project->update( $project_args );
+                               if ( ! $updated ) {
+                                       WP_CLI::line( "Sorry, but couldn't update https://translate.wordpress.org/projects/{$branch_project_path}." );
+                               } else {
+                                       WP_CLI::line( "Updated https://translate.wordpress.org/projects/{$branch_project_path}." );
+                               }
+                       }
+               } else {
+                       $branch_project_path = "{$plugin_project_path}/{$branch_slug}-readme";
+
+                       $project_args = array(
+                               'name'              => $is_stable ? 'Stable Readme (latest release)' : 'Development Readme (trunk)',
+                               'slug'              => "{$branch_slug}-readme",
+                               'parent_project_id' => $parent_id,
+                               'description'       => ( $is_stable ? 'Stable' : 'Development' ) . " version of the {$plugin_name} plugin's readme.txt file.",
+                               'active'            => 1,
+                       );
+
+                       $branch_project = GP::$project->by_path( $branch_project_path );
+                       if ( ! $branch_project ) {
+                               $branch_project = GP::$project->create_and_select( $project_args );
+                               if ( ! $branch_project ) {
+                                       WP_CLI::line( "Sorry, but couldn't create nonexistent https://translate.wordpress.org/projects/{$branch_project_path}." );
+                               } else {
+                                       WP_CLI::line( "Created https://translate.wordpress.org/projects/{$branch_project_path}." );
+                               }
+                       } else {
+                               $updated = $branch_project->update( $project_args );
+                               if ( ! $updated ) {
+                                       WP_CLI::line( "Sorry, but couldn't update https://translate.wordpress.org/projects/{$branch_project_path}." );
+                               } else {
+                                       WP_CLI::line( "Updated https://translate.wordpress.org/projects/{$branch_project_path}." );
+                               }
+                       }
+               }
+
+               return $branch_project;
+       }
+
+       /**
+        * Adds translation sets to a new plugin project.
+        *
+        * @param GP_Translation_Set[] $translation_sets Array of translation sets.
+        * @param GP_Project           $project          The project to add the sets to.
+        */
+       private function add_translation_sets_to_branches( $translation_sets, $project ) {
+               if ( empty( $project ) || empty( $project->id ) ) {
+                       return;
+               }
+
+               $existing_sets = array();
+               foreach ( GP::$translation_set->by_project_id( $project->id ) as $set ) {
+                       $existing_sets[ $set->locale . ':' . $set->slug ] = true;
+               }
+
+               foreach ( $translation_sets as $ts ) {
+                       if ( isset( $existing_sets[ $ts->locale . ':' . $ts->slug ] ) ) {
+                               // This translation set already exists.
+                               continue;
+                       }
+
+                       $new_ts = GP::$translation_set->create( array(
+                               'project_id' => $project->id,
+                               'name'       => $ts->name,
+                               'locale'     => $ts->locale,
+                               'slug'       => $ts->slug,
+                       ) );
+
+                       if ( empty( $new_ts ) ) {
+                               WP_CLI::line( "Sorry, but couldn't create nonexistent https://translate.wordpress.org/projects/{$project->path}/{$ts->locale}/{$ts->slug}." );
+                       } else {
+                               WP_CLI::line( "Created https://translate.wordpress.org/projects/{$project->path}/{$ts->locale}/{$ts->slug}." );
+                       }
+               }
+       }
+
+       /**
+        * Retrieves the details of a plugin from the wordpress.org API.
+        *
+        * @param string $slug Slug of a plugin
+        * @return object|null JSON object on success, null on failure.
+        */
+       private function get_plugin_details( $slug ) {
+               $http_context = $this->get_http_context();
+               $json = @file_get_contents( "https://api.wordpress.org/plugins/info/1.0/{$slug}.json?fields=stable_tag", false, $http_context );
+
+               $details = $json && '{' == $json[0] ? json_decode( $json ) : null;
+
+               return $details;
+       }
+
+       /**
+        * Creates a stream context with a default HTTP user-agent.
+        *
+        * @return resource Stream context with a default HTTP user-agent.
+        */
+       private function get_http_context() {
+               return stream_context_create( array(
+                       'http' => array(
+                               'user_agent' => 'WordPress.org Translate',
+                       ),
+               ) );
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryincclideletepluginprojectphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/delete-plugin-project.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/cli/delete-plugin-project.php  2016-03-31 08:59:24 UTC (rev 2858)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/delete-plugin-project.php        2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,93 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-class WPorg_GP_CLI_Delete_Plugin_Project extends WP_CLI_Command {
-
-       /**
-        * Holds the path of the master project.
-        *
-        * @var string
-        */
-       private $master_project_path = 'wp-plugins';
-
-       /**
-        * Delete a plugin project and its translations.
-        *
-        * ## OPTIONS
-        *
-        * <slug>
-        * : Slug of a plugin
-        *
-        * [--force]
-        * : If set, the command will delete the plugin, without prompting
-        * for confirmation.
-        */
-       public function __invoke( $args, $assoc_args ) {
-               global $wpdb;
-
-               $project_path = sprintf( '%s/%s', $this->master_project_path, $args[0] );
-
-               $project = GP::$project->by_path( $project_path );
-               if ( ! $project ) {
-                       WP_CLI::error( sprintf( "There is no plugin project for '%s'.", $args[0] ) );
-               }
-
-               $sub_projects = $project->sub_projects();
-
-               if ( ! isset( $assoc_args['force'] ) ) {
-                       WP_CLI::confirm( sprintf( "Do you want to delete %s with %d sub-projects?", $project->name, ( $sub_projects ? count( $sub_projects ) : 0 ) ) );
-               }
-
-               // Handle sub-projects.
-               if ( $sub_projects ) {
-                       foreach ( $sub_projects as $sub_project ) {
-                               // Get translation sets...
-                               $sets = GP::$translation_set->by_project_id( $sub_project->id );
-
-                               if ( $sets ) {
-                                       foreach ( $sets as $set ) {
-                                               // ... and delete its translations.
-                                               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_translations} WHERE translation_set_id = %d", $set->id ) );
-                                               WP_CLI::line( sprintf( "%d translations for %s/%s deleted.", $result, $set->locale, $set->slug ) );
-
-                                               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_translation_sets} WHERE id = %d", $set->id ) );
-                                               WP_CLI::line( sprintf( "%d translation sets for %s/%s deleted.", $result, $set->locale, $set->slug ) );
-
-                                               gp_clean_translation_set_cache( $set->id );
-                                       }
-                               }
-
-                               // Delete originals.
-                               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_originals} WHERE project_id = %d", $sub_project->id ) );
-                               WP_CLI::line( sprintf( "%d originals for %s deleted.", $result, $sub_project->path ) );
-
-                               // Delete sub project.
-                               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_projects} WHERE id = %d", $sub_project->id ) );
-                               WP_CLI::line( sprintf( "%d sub project %s deleted.", $result, $sub_project->path ) );
-                       }
-               } else {
-                       // Get translation sets...
-                       $sets = GP::$translation_set->by_project_id( $project->id );
-
-                       if ( $sets ) {
-                               foreach ( $sets as $set ) {
-                                       // ... and delete its translations.
-                                       $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_translations} WHERE translation_set_id = %d", $set->id ) );
-                                       WP_CLI::line( sprintf( "%d translations for %s/%s deleted.", $result, $set->locale, $set->slug ) );
-
-                                       $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_translation_sets} WHERE id = %d", $set->id ) );
-                                       WP_CLI::line( sprintf( "%d translation sets for %s/%s deleted.", $result, $set->locale, $set->slug ) );
-
-                                       gp_clean_translation_set_cache( $set->id );
-                               }
-                       }
-
-                       // Delete originals.
-                       $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_originals} WHERE project_id = %d", $project->id ) );
-                       WP_CLI::line( sprintf( "%d originals for %s deleted.", $result, $project->path ) );
-               }
-
-               // Delete project.
-               $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->gp_projects} WHERE id = %d", $project->id ) );
-               WP_CLI::line( sprintf( "%d project %s deleted.", $result, $project->path ) );
-       }
-}
</del></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryinccliimportplugintranslationsphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/import-plugin-translations.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/cli/import-plugin-translations.php     2016-03-31 08:59:24 UTC (rev 2858)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/import-plugin-translations.php   2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,88 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-class WPorg_GP_CLI_Import_Plugin_Translations extends WP_CLI_Command {
-
-       /**
-        * Import plugin translations.
-        *
-        * ## OPTIONS
-        *
-        * <project>
-        * : Project path
-        *
-        * <locale>
-        * : Locale to export
-        *
-        * <file>
-        * : File to import
-        *
-        * [--format=<format>]
-        * : Accepted values: po, mo. Default: po
-        *
-        * [--set=<set>]
-        * : Translation set slug: Default: "default"
-        *
-        * [--disable-propagating]
-        * : If set, propagation will be disabled.
-        */
-       public function __invoke( $args, $assoc_args ) {
-               $file = basename( $args[2] );
-
-               // Sanitize arguments.
-               $project = GP::$project->by_path( $args[0] );
-               if ( ! $project ) {
-                       WP_CLI::error( "Project not found! [$file]" );
-               }
-
-               $locale = GP_Locales::by_field( 'wp_locale', $args[1] );
-               if ( ! $locale ) {
-                       $locale = GP_Locales::by_field( 'slug', $args[1] );
-               }
-
-               if ( ! $locale ) {
-                       WP_CLI::error( "Locale not found! [$file]" );
-               }
-
-               $format = gp_array_get( GP::$formats, isset( $assoc_args['format'] ) ?  $assoc_args['format'] : 'po', null );
-               if ( ! $format ) {
-                       WP_CLI::error( "No such format! [$file]" );
-               }
-
-               $set_slug = isset( $assoc_args['set'] ) ? $assoc_args['set'] : 'default';
-               $translation_set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $set_slug, $locale->slug );
-               if ( ! $translation_set ) {
-                       WP_CLI::error( "Translation set not found! [$file]" );
-               }
-
-               // Load the translations into memory.
-               $translations = $format->read_translations_from_file( $args[2], $project );
-               if ( ! $translations ) {
-                       WP_CLI::error( "Couldn't load translations from file! [$file]" );
-               }
-
-               $disable_propagating = isset( $assoc_args['disable-propagating'] );
-
-               if ( $disable_propagating ) {
-                       add_filter( 'enable_propagate_translations_across_projects', '__return_false' );
-               }
-
-               add_filter( 'translation_set_import_over_existing', '__return_false' );
-               //add_filter( 'translation_set_import_status', array( $this, '__string_status_waiting' ) );
-
-               // Do the import.
-               $imported = $translation_set->import( $translations );
-
-               //remove_filter( 'translation_set_import_status', '__string_status_waiting' );
-               remove_filter( 'translation_set_import_over_existing', '__return_false' );
-
-               if ( $disable_propagating ) {
-                       remove_filter( 'enable_propagate_translations_across_projects', '__return_false' );
-               }
-
-               WP_CLI::success( "Imported $imported strings for {$locale->english_name} [$file]" );
-       }
-
-       public function __string_status_waiting() {
-               return 'waiting';
-       }
-}
</del></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryincclisetpluginprojectphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/set-plugin-project.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/cli/set-plugin-project.php     2016-03-31 08:59:24 UTC (rev 2858)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/set-plugin-project.php   2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,286 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-
-class WPorg_GP_CLI_Set_Plugin_Project extends WP_CLI_Command {
-
-       /**
-        * Holds the path of the master project.
-        *
-        * @var string
-        */
-       private $master_project_path = 'wp-plugins';
-
-       /**
-        * Holds the path of the projects to copy translation sets from.
-        *
-        * @var string
-        */
-       private $project_path_for_sets = 'wp/dev';
-
-       /**
-        * Add/update a plugin project.
-        *
-        * ## OPTIONS
-        *
-        * <slug>
-        * : Slug of a plugin
-        *
-        * <type>
-        * : Process type. Accepted values: dev, dev-readme, stable, stable-readme.
-        *
-        */
-       public function __invoke( $args, $assoc_args ) {
-               if ( ! preg_match( '/^[^\/]+$/', $args[0] ) ) {
-                       WP_CLI::line( sprintf( "The plugin slug '%s' contains invalid characters.", $args[0] ) );
-                       exit( 1 );
-               }
-
-               $plugin_slug         = $args[0];
-               $process_type        = $args[1];
-               $plugin_project_path = "{$this->master_project_path}/{$plugin_slug}";
-
-               // Get data for master parent project.
-               $master_project = GP::$project->by_path( $this->master_project_path );
-               if ( ! $master_project ) {
-                       WP_CLI::line( sprintf( "The master project '%s' couldn't be found.", $this->master_project_path ) );
-                       exit( 2 );
-               }
-
-               // Get plugin details like title and description.
-               $plugin_details = $this->get_plugin_details( $plugin_slug );
-               if ( ! $plugin_details ) {
-                       WP_CLI::line( "The plugin API couldn't be reached." );
-                       exit( 3 );
-               }
-
-               // Get or create the plugin GP project.
-               $project_args = array(
-                       'name'              => $plugin_details->name,
-                       'slug'              => $plugin_slug,
-                       'parent_project_id' => $master_project->id,
-                       'description'       => $plugin_details->short_description . "<br><br><a href='https://wordpress.org/plugins/{$plugin_slug}'>WordPress.org Plugin Page</a>",
-                       'active'            => 1,
-               );
-
-               $plugin_project = GP::$project->by_path( $plugin_project_path );
-
-               // Is this a new or an existing project?
-               $new_project_flag = true;
-
-               if ( ! $plugin_project ) {
-                       WP_CLI::line( "Creating project for {$plugin_project_path}." );
-
-                       $plugin_project = GP::$project->create_and_select( $project_args );
-                       if ( ! $plugin_project ) {
-                               WP_CLI::line( "Couldn't create project for {$plugin_project_path}." );
-                               exit( 5 );
-                       }
-               } else {
-                       WP_CLI::line( "Updating project for {$plugin_project_path}." );
-
-                       // This is an existing project.
-                       $new_project_flag = false;
-
-                       // Update the project details.
-                       $plugin_project->update( $project_args );
-               }
-
-               // The current stable SVN tag.
-               $stable_tag = empty( $plugin_details->stable_tag ) ? 'trunk' : $plugin_details->stable_tag;
-
-               // Deal with the always-existing dev|dev-readme branch.
-               $plugin_dev_branch_project = $this->handle_plugin_project_branches(
-                       $plugin_project_path,
-                       $plugin_slug,
-                       $plugin_details->name,
-                       $plugin_project->id,
-                       $process_type,
-                       $stable_tag,
-                       'dev'
-               );
-
-               // Deal with the stable|stable-readme branch, if needed.
-               $plugin_stable_branch_project = false;
-               if ( 'trunk' !== $stable_tag ) {
-                       $plugin_stable_branch_project = $this->handle_plugin_project_branches(
-                               $plugin_project_path,
-                               $plugin_slug,
-                               $plugin_details->name,
-                               $plugin_project->id,
-                               $process_type,
-                               $stable_tag,
-                               'stable'
-                       );
-               }
-
-               // Deal with initial translation sets.
-               $source_project = GP::$project->by_path( $this->project_path_for_sets );
-               if ( $source_project && $plugin_dev_branch_project ) {
-                       $translation_sets = (array) GP::$translation_set->by_project_id( $source_project->id );
-
-                       if ( $translation_sets ) {
-                               $this->add_translation_sets_to_branches( $translation_sets, $plugin_dev_branch_project );
-
-                               if ( $plugin_stable_branch_project ) {
-                                       $this->add_translation_sets_to_branches( $translation_sets, $plugin_stable_branch_project );
-                               }
-                       }
-               }
-
-               WP_CLI::line( ( $new_project_flag ? 'Created' : 'Updated' ) . " https://translate.wordpress.org/projects/{$plugin_project_path}" );
-               exit( 0 );
-       }
-
-       /**
-        * Creates/updates sub-projects for plugins.
-        *
-        * @param string $plugin_project_path Path to the plugin project.
-        * @param string $plugin_slug         Slug of the plugin.
-        * @param string $plugin_name         Name of the plugin.
-        * @param int    $parent_id           ID of the main project.
-        * @param string $process_type        Type of the project, 'code' or 'readme'.
-        * @param string $stable_tag          The stable SVN tag of the plugin.
-        * @param string $branch_slug         Slug of the project, 'dev' or 'stable'.
-        * @return GP_Project|null A GP_Project instance on success, null on failure.
-        */
-       private function handle_plugin_project_branches( $plugin_project_path, $plugin_slug, $plugin_name, $parent_id, $process_type, $stable_tag, $branch_slug ) {
-               if ( ! in_array( $branch_slug, array( 'dev', 'stable' ) ) ) {
-                       $branch_slug = 'dev';
-               }
-
-               $is_stable = 'stable' === $branch_slug;
-
-               if ( 'code' !== $process_type ) {
-                       $process_type = 'readme';
-               }
-
-               if ( 'code' === $process_type ) {
-                       $branch_project_path = "{$plugin_project_path}/{$branch_slug}";
-                       $source_url_template = sprintf(
-                               'https://plugins.trac.wordpress.org/browser/%s/%s/%s',
-                               $plugin_slug,
-                               $is_stable ? "tags/{$stable_tag}" : 'trunk',
-                               '%file%#L%line%'
-                       );
-
-                       $project_args = array(
-                               'name'                => $is_stable ? 'Stable (latest release)' : 'Development (trunk)',
-                               'slug'                => $branch_slug,
-                               'parent_project_id'   => $parent_id,
-                               'description'         => ( $is_stable ? 'Stable' : 'Development' ) . " version of the {$plugin_name} plugin.",
-                               'source_url_template' => $source_url_template,
-                               'active'              => 1,
-                       );
-
-                       $branch_project = GP::$project->by_path( $branch_project_path );
-                       if ( ! $branch_project ) {
-                               $branch_project = GP::$project->create_and_select( $project_args );
-                               if ( ! $branch_project ) {
-                                       WP_CLI::line( "Sorry, but couldn't create nonexistent https://translate.wordpress.org/projects/{$branch_project_path}." );
-                               } else {
-                                       WP_CLI::line( "Created https://translate.wordpress.org/projects/{$branch_project_path}." );
-                               }
-                       } else {
-                               $updated = $branch_project->update( $project_args );
-                               if ( ! $updated ) {
-                                       WP_CLI::line( "Sorry, but couldn't update https://translate.wordpress.org/projects/{$branch_project_path}." );
-                               } else {
-                                       WP_CLI::line( "Updated https://translate.wordpress.org/projects/{$branch_project_path}." );
-                               }
-                       }
-               } else {
-                       $branch_project_path = "{$plugin_project_path}/{$branch_slug}-readme";
-
-                       $project_args = array(
-                               'name'              => $is_stable ? 'Stable Readme (latest release)' : 'Development Readme (trunk)',
-                               'slug'              => "{$branch_slug}-readme",
-                               'parent_project_id' => $parent_id,
-                               'description'       => ( $is_stable ? 'Stable' : 'Development' ) . " version of the {$plugin_name} plugin's readme.txt file.",
-                               'active'            => 1,
-                       );
-
-                       $branch_project = GP::$project->by_path( $branch_project_path );
-                       if ( ! $branch_project ) {
-                               $branch_project = GP::$project->create_and_select( $project_args );
-                               if ( ! $branch_project ) {
-                                       WP_CLI::line( "Sorry, but couldn't create nonexistent https://translate.wordpress.org/projects/{$branch_project_path}." );
-                               } else {
-                                       WP_CLI::line( "Created https://translate.wordpress.org/projects/{$branch_project_path}." );
-                               }
-                       } else {
-                               $updated = $branch_project->update( $project_args );
-                               if ( ! $updated ) {
-                                       WP_CLI::line( "Sorry, but couldn't update https://translate.wordpress.org/projects/{$branch_project_path}." );
-                               } else {
-                                       WP_CLI::line( "Updated https://translate.wordpress.org/projects/{$branch_project_path}." );
-                               }
-                       }
-               }
-
-               return $branch_project;
-       }
-
-       /**
-        * Adds translation sets to a new plugin project.
-        *
-        * @param GP_Translation_Set[] $translation_sets Array of translation sets.
-        * @param GP_Project           $project          The project to add the sets to.
-        */
-       private function add_translation_sets_to_branches( $translation_sets, $project ) {
-               if ( empty( $project ) || empty( $project->id ) ) {
-                       return;
-               }
-
-               $existing_sets = array();
-               foreach ( GP::$translation_set->by_project_id( $project->id ) as $set ) {
-                       $existing_sets[ $set->locale . ':' . $set->slug ] = true;
-               }
-
-               foreach ( $translation_sets as $ts ) {
-                       if ( isset( $existing_sets[ $ts->locale . ':' . $ts->slug ] ) ) {
-                               // This translation set already exists.
-                               continue;
-                       }
-
-                       $new_ts = GP::$translation_set->create( array(
-                               'project_id' => $project->id,
-                               'name'       => $ts->name,
-                               'locale'     => $ts->locale,
-                               'slug'       => $ts->slug,
-                       ) );
-
-                       if ( empty( $new_ts ) ) {
-                               WP_CLI::line( "Sorry, but couldn't create nonexistent https://translate.wordpress.org/projects/{$project->path}/{$ts->locale}/{$ts->slug}." );
-                       } else {
-                               WP_CLI::line( "Created https://translate.wordpress.org/projects/{$project->path}/{$ts->locale}/{$ts->slug}." );
-                       }
-               }
-       }
-
-       /**
-        * Retrieves the details of a plugin from the wordpress.org API.
-        *
-        * @param string $slug Slug of a plugin
-        * @return object|null JSON object on success, null on failure.
-        */
-       private function get_plugin_details( $slug ) {
-               $http_context = $this->get_http_context();
-               $json = @file_get_contents( "https://api.wordpress.org/plugins/info/1.0/{$slug}.json?fields=stable_tag", false, $http_context );
-
-               $details = $json && '{' == $json[0] ? json_decode( $json ) : null;
-
-               return $details;
-       }
-
-       /**
-        * Creates a stream context with a default HTTP user-agent.
-        *
-        * @return resource Stream context with a default HTTP user-agent.
-        */
-       private function get_http_context() {
-               return stream_context_create( array(
-                       'http' => array(
-                               'user_agent' => 'WordPress.org Translate',
-                       ),
-               ) );
-       }
-}
</del></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectoryvendorwordpressdotorgclassautoloaderphpfromrev2858sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassautoloaderphp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/vendor/wordpressdotorg/class-autoloader.php (from rev 2858, sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-autoloader.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/vendor/wordpressdotorg/class-autoloader.php                            (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/vendor/wordpressdotorg/class-autoloader.php      2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,93 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Autoload;
+
+/**
+ * An Autoloader which respects WordPress's filename standards.
+ *
+ * @package WordPressdotorg\Autoload
+ */
+class Autoloader {
+
+       /**
+        * Namespace separator.
+        */
+       const NS_SEPARATOR = '\\';
+
+       /**
+        * The prefix to compare classes against.
+        *
+        * @var string
+        * @access protected
+        */
+       protected $prefix;
+
+       /**
+        * Length of the prefix string.
+        *
+        * @var int
+        * @access protected
+        */
+       protected $prefix_length;
+
+       /**
+        * Path to the file to be loaded.
+        *
+        * @var string
+        * @access protected
+        */
+       protected $path;
+
+       /**
+        * Constructor.
+        *
+        * @param string $prefix Prefix all classes have in common.
+        * @param string $path   Path to the files to be loaded.
+        */
+       public function __construct( $prefix, $path ) {
+               $this->prefix        = $prefix;
+               $this->prefix_length = strlen( $prefix );
+               $this->path          = trailingslashit( $path );
+       }
+
+       /**
+        * Loads a class if it starts with `$this->prefix`.
+        *
+        * @param string $class The class to be loaded.
+        */
+       public function load( $class ) {
+               if ( strpos( $class, $this->prefix . self::NS_SEPARATOR ) !== 0 ) {
+                       return;
+               }
+
+               // Strip prefix from the start (ala PSR-4)
+               $class = substr( $class, $this->prefix_length + 1 );
+               $class = strtolower( $class );
+               $file  = '';
+
+               if ( false !== ( $last_ns_pos = strripos( $class, self::NS_SEPARATOR ) ) ) {
+                       $namespace = substr( $class, 0, $last_ns_pos );
+                       $namespace = str_replace( '_', '-', $namespace );
+                       $class     = substr( $class, $last_ns_pos + 1 );
+                       $file      = str_replace( self::NS_SEPARATOR, DIRECTORY_SEPARATOR, $namespace ) . DIRECTORY_SEPARATOR;
+               }
+
+               $file .= 'class-' . str_replace( '_', '-', $class ) . '.php';
+
+               $path = $this->path . $file;
+
+               if ( file_exists( $path ) ) {
+                       require $path;
+               }
+       }
+}
+
+/**
+ * Registers Autoloader's autoload function.
+ *
+ * @param string $prefix
+ * @param string $path
+ */
+function register_class_path( $prefix, $path ) {
+       $loader = new Autoloader( $prefix, $path );
+       spl_autoload_register( array( $loader, 'load' ) );
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpplugindirectorywporggpplugindirectoryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/wporg-gp-plugin-directory.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/wporg-gp-plugin-directory.php  2016-04-02 10:24:29 UTC (rev 2880)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/wporg-gp-plugin-directory.php    2016-04-02 15:59:41 UTC (rev 2881)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,215 +2,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Plugin name: GlotPress: Plugin Directory Bridge
</span><span class="cx" style="display: block; padding: 0 10px">  * Description: Clears the content translation cache for plugins (readme/code) hosted on wordpress.org based on actions taken withing translate.wordpress.org.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Version:     1.1
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Version:     2.0
</ins><span class="cx" style="display: block; padding: 0 10px">  * Author:      WordPress.org
</span><span class="cx" style="display: block; padding: 0 10px">  * Author URI:  http://wordpress.org/
</span><span class="cx" style="display: block; padding: 0 10px">  * License:     GPLv2 or later
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-class WPorg_GP_Plugin_Directory {
-       public $master_project   = 'wp-plugins';
-       public $i18n_cache_group = 'plugins-i18n';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+namespace WordPressdotorg\GlotPress\Plugin_Directory;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        private $translation_edits_queue = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Autoload;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function __construct() {
-               add_action( 'init', array( $this, 'add_global_cache_group' ) );
-               add_action( 'gp_originals_imported', array( $this, 'originals_imported' ) );
-               add_action( 'gp_translation_created', array( $this, 'queue_translation_for_cache_purge' ) );
-               add_action( 'gp_translation_saved', array( $this, 'queue_translation_for_cache_purge' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Store the root plugin file for usage with functions which use the plugin basename.
+define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Cache purging is delayed until shutdown to prevent multiple purges for the same project.
-               add_action( 'shutdown', array( $this, 'delete_plugin_i18n_cache_on_translation_edits' ) );
-
-               if ( defined( 'WP_CLI' ) && WP_CLI ) {
-                       $this->register_cli_commands();
-               }
-       }
-
-       /**
-        * Registers CLI commands if WP-CLI is loaded.
-        */
-       function register_cli_commands() {
-               require_once __DIR__ . '/cli/import-plugin-translations.php';
-               require_once __DIR__ . '/cli/set-plugin-project.php';
-               require_once __DIR__ . '/cli/delete-plugin-project.php';
-
-               WP_CLI::add_command( 'wporg-translate import-plugin-translations', 'WPorg_GP_CLI_Import_Plugin_Translations' );
-               WP_CLI::add_command( 'wporg-translate set-plugin-project', 'WPorg_GP_CLI_Set_Plugin_Project' );
-               WP_CLI::add_command( 'wporg-translate delete-plugin-project', 'WPorg_GP_CLI_Delete_Plugin_Project' );
-       }
-
-       /**
-        * Registers the global cache group wordpress.org/plugins/ uses for its display cache.
-        */
-       public function add_global_cache_group() {
-               wp_cache_add_global_groups( $this->i18n_cache_group );
-       }
-
-       /**
-        * Triggers a cache purge when a new originals were imported.
-        *
-        * @param int $project_id The project ID.
-        */
-       public function originals_imported( $project_id ) {
-               $project = GP::$project->get( $project_id );
-               if ( empty( $project->path ) || ! $this->project_is_plugin( $project->path ) ) {
-                       return;
-               }
-
-               $this->delete_plugin_i18n_cache_keys_for_project( $project_id );
-       }
-
-       /**
-        * Adds a translation to a cache purge queue when a translation was created
-        * or updated.
-        *
-        * @param GP_Translation $translation Created/updated translation.
-        */
-       public function queue_translation_for_cache_purge( $translation ) {
-               if ( ! $this->project_is_plugin( $_SERVER['REQUEST_URI'] ) ) {
-                       return;
-               }
-
-               $this->translation_edits_queue[ $translation->original_id ][ $translation->translation_set_id ] = true;
-       }
-
-       /**
-        * Deletes the cache on a translation edits.
-        *
-        * @param GP_Translation $translation The edited translation.
-        */
-       public function delete_plugin_i18n_cache_on_translation_edits() {
-               if ( empty( $this->translation_edits_queue ) ) {
-                       return;
-               }
-
-               $purged = array();
-               foreach ( $this->translation_edits_queue as $original_id => $set_ids ) {
-                       $original = GP::$original->get( $original_id );
-                       if ( ! $original ) {
-                               return;
-                       }
-
-                       foreach ( array_keys( $set_ids ) as $set_id ) {
-                               if ( in_array( "{$original->project_id}-{$set_id}", $purged ) ) {
-                                       continue;
-                               }
-
-                               $translation_set = GP::$translation_set->get( $set_id );
-                               if ( ! $translation_set ) {
-                                       return;
-                               }
-
-                               $this->delete_plugin_i18n_cache_keys_for_locale( $original->project_id, $translation_set->locale );
-                               $purged[] = "{$original->project_id}-{$set_id}";
-                       }
-               }
-       }
-
-       /**
-        * Returns whether a project path belongs to the plugins project.
-        *
-        * @param string $path Path of a project.
-        *
-        * @return bool True if it's a plugin, false if not.
-        */
-       private function project_is_plugin( $path ) {
-               if ( empty( $path ) ) {
-                       return false;
-               }
-
-               $path = '/' . trim( $path, '/' ) . '/';
-               if ( false === strpos( $path, "/{$this->master_project}/" ) ) {
-                       return false;
-               }
-
-               return true;
-       }
-
-       /**
-        * Builds the cache prefix for a plugin.
-        *
-        * @param int $project_id The project ID.
-        *
-        * @return string The cache prefix, empty if project isn't a plugin.
-        */
-       private function get_plugin_i18n_cache_prefix( $project_id ) {
-               $project = GP::$project->get( $project_id );
-               if ( empty( $project->path ) || !$this->project_is_plugin( $project->path ) ) {
-                       return '';
-               }
-
-               $project_dirs = explode( '/', trim( $project->path, '/' ) );
-               if ( empty( $project_dirs ) || 3 !== count( $project_dirs ) || $project_dirs[0] !== $this->master_project ) {
-                       return '';
-               }
-
-               return "{$this->master_project}:{$project_dirs[1]}:{$project_dirs[2]}";
-       }
-
-       /**
-        * Deletes a set of known cache keys for a plugin.
-        *
-        * @param string $prefix Cache key prefix, such as 'plugin:livejournal-importer:readme-stable'.
-        * @param string $set    Set, such as 'original', 'fr', 'de'.
-        */
-       private function delete_plugin_i18n_cache_keys_for( $prefix, $set ) {
-               $suffixes = array(
-                       'translation_set_id', 'title', 'short_description', 'installation', 'description',
-                       'faq', 'screenshots', 'changelog', 'other_notes',
-               );
-               foreach ( $suffixes as $suffix ) {
-                       $cache_key = "{$prefix}:{$set}:{$suffix}";
-                       wp_cache_delete( $cache_key, $this->i18n_cache_group );
-               }
-       }
-
-       /**
-        * Deletes the cached originals of a plugin.
-        *
-        * @param int $project_id The project ID.
-        */
-       private function delete_plugin_i18n_cache_keys_for_project( $project_id ) {
-               $prefix = $this->get_plugin_i18n_cache_prefix( (int) $project_id );
-               if ( ! $prefix ) {
-                       return;
-               }
-
-               wp_cache_delete( "{$prefix}:originals", $this->i18n_cache_group );
-               wp_cache_delete( "{$prefix}:branch_id", $this->i18n_cache_group );
-               $this->delete_plugin_i18n_cache_keys_for( $prefix, 'original' );
-
-               $translation_sets = (array) GP::$translation_set->by_project_id( $project_id );
-               foreach ( $translation_sets as $translation_set ) {
-                       $this->delete_plugin_i18n_cache_keys_for( $prefix, $translation_set->locale );
-               }
-       }
-
-       /**
-        * Deletes a cache keys of a locale for a plugin.
-        *
-        * @param int    $project_id The project ID.
-        * @param string $locale     GlotPress slug of a locale.
-        */
-       private function delete_plugin_i18n_cache_keys_for_locale( $project_id, $locale ) {
-               $prefix = $this->get_plugin_i18n_cache_prefix( (int) $project_id );
-               if ( ! $prefix ) {
-                       return;
-               }
-
-               $this->delete_plugin_i18n_cache_keys_for( $prefix, $locale );
-       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( ! class_exists( '\WordPressdotorg\Autoload\Autoloader', false ) ) {
+       include __DIR__ . '/vendor/wordpressdotorg/class-autoloader.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wporg_gp_plugin_directory() {
-       global $wporg_gp_plugin_directory;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Register an Autoloader for all files.
+Autoload\register_class_path( __NAMESPACE__, __DIR__ . '/inc' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( ! isset( $wporg_gp_plugin_directory ) ) {
-               $wporg_gp_plugin_directory = new WPorg_GP_Plugin_Directory();
-       }
-
-       return $wporg_gp_plugin_directory;
-}
-add_action( 'plugins_loaded', 'wporg_gp_plugin_directory' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Instantiate the Plugin.
+Plugin::get_instance();
</ins></span></pre>
</div>
</div>

</body>
</html>