<!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>[5339] sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc: Rosetta: Add admin page to manage locale associations.</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/5339">5339</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/5339","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>2017-04-15 15:01:20 +0000 (Sat, 15 Apr 2017)</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'>Rosetta: Add admin page to manage locale associations.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincclasspluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/class-plugin.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincsiteclassglobalwordpressorgphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-global-wordpress-org.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincadminclassadminpageviewphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/class-admin-page-view.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincadminclassadminpagephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/class-admin-page.php</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincadminnetworkclasslocaleassociationsviewphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/class-locale-associations-view.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincadminnetworkclasslocaleassociationsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/class-locale-associations.php</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/database/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincdatabaseclasstablesphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/database/class-tables.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincadminclassadminpageviewphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/class-admin-page-view.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/rosetta/inc/admin/class-admin-page-view.php                              (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/class-admin-page-view.php        2017-04-15 15:01:20 UTC (rev 5339)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,25 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Rosetta\Admin;
+
+interface Admin_Page_View {
+
+       /**
+        * Gets the title of the admin page.
+        *
+        * @return string The title.
+        */
+       public function get_title();
+
+       /**
+        * Renders the admin page.
+        */
+       public function render();
+
+       /**
+        * Sets associated page controller.
+        *
+        * @param \WordPressdotorg\Rosetta\Admin\Admin_Page $page The page instance.
+        */
+       public function set_page( Admin_Page $page );
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincadminclassadminpagephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/class-admin-page.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/rosetta/inc/admin/class-admin-page.php                           (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/class-admin-page.php     2017-04-15 15:01:20 UTC (rev 5339)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,11 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Rosetta\Admin;
+
+interface Admin_Page {
+
+       /**
+        * Registers a new admin page.
+        */
+       public function register();
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincadminnetworkclasslocaleassociationsviewphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/class-locale-associations-view.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/rosetta/inc/admin/network/class-locale-associations-view.php                             (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/class-locale-associations-view.php       2017-04-15 15:01:20 UTC (rev 5339)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,180 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Rosetta\Admin\Network;
+
+use WordPressdotorg\Rosetta\Admin\Admin_Page;
+use WordPressdotorg\Rosetta\Admin\Admin_Page_View;
+
+class Locale_Associations_View implements Admin_Page_View {
+
+       /**
+        * @var \WordPressdotorg\Rosetta\Admin\Network\Locale_Associations;
+        */
+       private $page;
+
+       /**
+        * Gets the title of the admin page.
+        *
+        * @return string The title.
+        */
+       public function get_title() {
+               return __( 'Locale Associations', 'rosetta' );
+       }
+
+       /**
+        * Sets associated page controller.
+        *
+        * @param \WordPressdotorg\Rosetta\Admin\Admin_Page $page The page instance.
+        */
+       public function set_page( Admin_Page $page ) {
+               $this->page = $page;
+       }
+
+       /**
+        * Renders the admin page.
+        */
+       public function render() {
+               ?>
+               <div class="wrap">
+                       <h1><?php echo esc_html( $this->get_title() ); ?></h1>
+
+                       <?php
+                       $this->render_message();
+                       $this->render_form();
+                       $this->render_table();
+                       ?>
+               </div>
+               <?php
+       }
+
+       /**
+        * Renders a message for errors/updates.
+        */
+       private function render_message() {
+               if ( ! isset( $_GET['performed_action'] ) || ( ! isset( $_GET['updated'] ) && ! isset( $_GET['error'] ) ) ) {
+                       return;
+               }
+
+               $code = sprintf(
+                       '%s|%s',
+                       $_GET['performed_action'],
+                       isset( $_GET['updated'] ) ? $_GET['updated'] : $_GET['error']
+               );
+
+               switch ( $code ) {
+                       case 'add-association|nonce_failure' :
+                       case 'delete-association|nonce_failure' :
+                       case 'delete-association|delete_failure' :
+                               printf(
+                                       '<div class="notice notice-error"><p>%s</p></div>',
+                                       __( 'An error occurred. Please try again.', 'rosetta' )
+                               );
+                               break;
+                       case 'add-association|missing_data' :
+                               printf(
+                                       '<div class="notice notice-error"><p>%s</p></div>',
+                                       __( 'Please provide a locale and a subdomain.', 'rosetta' )
+                               );
+                               break;
+                       case 'add-association|success' :
+                               printf(
+                                       '<div class="notice notice-success"><p>%s</p></div>',
+                                       __( 'The new association has been added.', 'rosetta' )
+                               );
+                               break;
+                       case 'delete-association|missing_data' :
+                               printf(
+                                       '<div class="notice notice-error"><p>%s</p></div>',
+                                       __( 'The ID of the association is missing. Please try again.', 'rosetta' )
+                               );
+                               break;
+                       case 'delete-association|success' :
+                               printf(
+                                       '<div class="notice notice-success"><p>%s</p></div>',
+                                       __( 'The association has been deleted.', 'rosetta' )
+                               );
+                               break;
+               }
+       }
+
+       /**
+        * Renders the add new form.
+        */
+       private function render_form() {
+               ?>
+               <h2><?php _e( 'Add New Association', 'rosetta' ); ?></h2>
+               <form action="" method="post">
+                       <?php wp_nonce_field( 'add-association' ); ?>
+                       <input type="hidden" name="action" value="add-association" />
+
+                       <p>
+                               <label for="locale"><?php _e( 'Locale:', 'rosetta' ); ?></label>
+                               <input type="text" id="locale" name="locale" />
+
+                               <label for="subdomain"><?php _e( 'Subdomain:', 'rosetta' ); ?></label>
+                               <input type="text" id="subdomain" name="subdomain" />
+                       </p>
+
+                       <p>
+                               <input type="submit" class="button button-primary" value="<?php esc_attr_e( 'Add New Association', 'rosetta' ); ?>" />
+                       </p>
+               </form>
+               <?php
+       }
+
+       /**
+        * Renders the associations table.
+        */
+       private function render_table() {
+               ?>
+               <h2><?php _e( 'Existing Associations', 'rosetta' ); ?></h2>
+               <table class="widefat striped">
+                       <thead>
+                               <tr>
+                                       <th><?php _e( 'Locale', 'rosetta' ); ?></th>
+                                       <th><?php _e( 'Subdomain', 'rosetta' ); ?></th>
+                                       <th><?php _e( 'Sites', 'rosetta' ); ?></th>
+                                       <th>&mdash;</th>
+                               </tr>
+                       </thead>
+                       <tbody id="the-list">
+                               <?php foreach ( $this->page->get_associations() as $association ) : ?>
+                                       <tr>
+                                               <td><?php echo esc_html( $association->locale ); ?></td>
+                                               <td><?php echo esc_html( $association->subdomain ); ?></td>
+                                               <td>
+                                                       <?php
+                                                       $sites = get_sites( [
+                                                               'lang_id'    => $association->locale_id,
+                                                               'network_id' => get_current_network_id(),
+                                                               'orderby'    => 'path_length',
+                                                       ] );
+                                                       if ( $sites ) {
+                                                               echo '<ul>';
+                                                               foreach ( $sites as $site ) {
+                                                                       printf(
+                                                                               '<li><a href="%s">%s (%s)</a>',
+                                                                               esc_url( $site->home ),
+                                                                               esc_html( $site->blogname ),
+                                                                               esc_html( $site->domain . $site->path )
+                                                                       );
+                                                               }
+                                                               echo '</ul>';
+                                                       }
+                                                       ?>
+                                               </td>
+                                               <td>
+                                                       <form action="" method="post">
+                                                               <?php wp_nonce_field( 'delete-association-' . $association->locale_id ); ?>
+                                                               <input type="hidden" name="action" value="delete-association" />
+                                                               <input type="hidden" name="id" value="<?php echo esc_attr( $association->locale_id ); ?>"/>
+                                                               <input type="submit" class="button delete" value="<?php esc_attr_e( 'Delete', 'rosetta' ); ?>" />
+                                                       </form>
+                                               </td>
+                                       </tr>
+                               <?php endforeach; ?>
+                       </tbody>
+               </table>
+               <?php
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincadminnetworkclasslocaleassociationsphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/class-locale-associations.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/rosetta/inc/admin/network/class-locale-associations.php                          (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/class-locale-associations.php    2017-04-15 15:01:20 UTC (rev 5339)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,230 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Rosetta\Admin\Network;
+
+use WordPressdotorg\Rosetta\Admin\Admin_Page;
+use WordPressdotorg\Rosetta\Admin\Admin_Page_View;
+use WordPressdotorg\Rosetta\Database\Tables;
+use WP_Error;
+
+class Locale_Associations implements Admin_Page {
+
+       /**
+        * Holds the slug of the page.
+        *
+        * @var string
+        */
+       protected $page_slug = 'locale-associations';
+
+       /**
+        * Holds the hook suffix of the page.
+        *
+        * @var string
+        */
+       protected $page_hook;
+
+       /**
+        * Holds the associated view.
+        *
+        * @var \WordPressdotorg\Rosetta\Admin\Admin_Page_View
+        */
+       protected $view;
+
+       /**
+        * Holds the admin URL of the page.
+        *
+        * @var string
+        */
+       protected $url;
+
+       /**
+        * Constructor.
+        *
+        * @param \WordPressdotorg\Rosetta\Admin\Admin_Page_View $view The view.
+        */
+       public function __construct( Admin_Page_View $view ) {
+               $this->view = $view;
+               $this->view->set_page( $this );
+       }
+
+       /**
+        * Registers a new admin page.
+        */
+       public function register() {
+               $this->page_hook = add_submenu_page(
+                       'sites.php',
+                       $this->view->get_title(),
+                       $this->view->get_title(),
+                       'manage_sites',
+                       $this->page_slug,
+                       [ $this->view, 'render' ]
+               );
+
+               add_action( 'load-' . $this->page_hook, [ $this, 'action' ] );
+       }
+
+       /**
+        * Handles actions like adding/deleting locale associations.
+        */
+       public function action() {
+               if ( ! isset( $_POST['_wpnonce'] ) || ! isset( $_POST['action'] ) || ! in_array( $_POST['action'], [ 'add-association', 'delete-association' ], true ) ) {
+                       return;
+               }
+
+               $current_action = $_POST['action'];
+               $result = null;
+
+               switch ( $current_action ) {
+                       case 'add-association' :
+                               $result = $this->action_add_association();
+                               break;
+                       case 'delete-association' :
+                               $result = $this->action_delete_association();
+                               break;
+                       default :
+                               return;
+               }
+
+               $query_args = [
+                       'performed_action' => $current_action,
+               ];
+
+               if ( is_wp_error( $result ) ) {
+                       $query_args['error'] = $result->get_error_code();
+               } else {
+                       $query_args['updated'] = 'success';
+               }
+
+               wp_safe_redirect( add_query_arg( $query_args, $this->url() ) );
+               exit;
+       }
+
+       /**
+        * Handles adding a new locale association.
+        *
+        * @return true|\WP_Error True on success, WP_Error on failure.
+        */
+       private function action_add_association() {
+               global $wpdb;
+
+               if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'add-association' ) ) {
+                       return new WP_Error( 'nonce_failure' );
+               }
+
+               if ( empty( $_POST['locale'] ) || empty( $_POST['locale'] ) ) {
+                       return new WP_Error( 'missing_data' );
+               }
+
+               $locale = sanitize_text_field( $_POST['locale'] );
+               $subdomain = sanitize_text_field( $_POST['subdomain'] );
+
+               $result = $wpdb->insert( Tables::LOCALES, [
+                       'locale'    => $locale,
+                       'subdomain' => $subdomain,
+               ] );
+
+               if ( ! $result ) {
+                       return new WP_Error( 'insert_failure' );
+               }
+
+               $lang_id = $wpdb->insert_id;
+
+               $site_ids = get_sites( [
+                       'domain'     => "{$subdomain}.wordpress.org",
+                       'network_id' => get_current_network_id(),
+                       'fields'     => 'ids',
+               ] );
+
+               foreach ( $site_ids as $site_id ) {
+                       update_blog_details( $site_id, [ 'lang_id' => $lang_id ] );
+               }
+
+               $this->delete_cache();
+
+               return true;
+       }
+
+       /**
+        * Handles deleting a locale association.
+        *
+        * @return true|\WP_Error True on success, WP_Error on failure.
+        */
+       public function action_delete_association() {
+               global $wpdb;
+
+               if ( empty( $_POST['id'] ) ) {
+                       return new WP_Error( 'missing_data' );
+               }
+
+               $id = (int) $_POST['id'];
+
+               if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'delete-association-' . $id ) ) {
+                       return new WP_Error( 'nonce_failure' );
+               }
+
+               // Reset 'lang_id' of associated sites.
+               $site_ids = get_sites( [
+                       'lang_id'    => $id,
+                       'network_id' => get_current_network_id(),
+                       'fields'     => 'ids',
+               ] );
+
+               foreach ( $site_ids as $site_id ) {
+                       update_blog_details( $site_id, [ 'lang_id' => '0' ] );
+               }
+
+               // Remove locale from global table.
+               $result = $wpdb->delete( Tables::LOCALES, [
+                       'locale_id' => $id,
+               ], [ '%d' ] );
+
+               if ( ! $result ) {
+                       return new WP_Error( 'delete_failure' );
+               }
+
+               $this->delete_cache();
+
+               return true;
+       }
+
+       /**
+        * Deletes the cache for locale associations.
+        */
+       private function delete_cache() {
+               wp_cache_add_global_groups( [ 'locale-associations' ] );
+
+               wp_cache_delete( 'subdomains', 'locale-associations' );
+               wp_cache_delete( 'local-sites', 'locale-associations' );
+               wp_cache_delete( 'id-locale', 'locale-associations' );
+       }
+
+       /**
+        * Retrieves all associations.
+        *
+        * @return array List of associations.
+        */
+       public function get_associations() {
+               global $wpdb;
+
+               $associations = $wpdb->get_results( 'SELECT * FROM ' . Tables::LOCALES . ' ORDER BY locale' );
+               if ( ! is_array( $associations ) ) {
+                       $associations = [];
+               }
+
+               return $associations;
+       }
+
+       /**
+        * Gets the admin URL of the page.
+        *
+        * @return string Admin URL of the page.
+        */
+       public function url() {
+               if ( ! isset( $this->url ) ) {
+                       $url = add_query_arg( 'page', $this->page_slug, 'sites.php' );
+                       $this->url = network_admin_url( $url );
+               }
+
+               return $this->url;
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincclasspluginphp"></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/rosetta/inc/class-plugin.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/rosetta/inc/class-plugin.php     2017-04-15 10:47:44 UTC (rev 5338)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/class-plugin.php       2017-04-15 15:01:20 UTC (rev 5339)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5,7 +5,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class Plugin {
</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">-         * @var Plugin The singleton instance.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @var \WordPressdotorg\Rosetta\Plugin The singleton instance.
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        private static $instance;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,7 +19,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Returns always the same instance of this plugin.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @return Plugin
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @return \WordPressdotorg\Rosetta\Plugin
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public static function get_instance() {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! ( self::$instance instanceof Plugin ) ) {
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincdatabaseclasstablesphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/database/class-tables.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/rosetta/inc/database/class-tables.php                            (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/database/class-tables.php      2017-04-15 15:01:20 UTC (rev 5339)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,7 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Rosetta\Database;
+
+abstract class Tables {
+
+       const LOCALES = 'wporg_locales';
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsrosettaincsiteclassglobalwordpressorgphp"></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/rosetta/inc/site/class-global-wordpress-org.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/rosetta/inc/site/class-global-wordpress-org.php  2017-04-15 10:47:44 UTC (rev 5338)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-global-wordpress-org.php    2017-04-15 15:01:20 UTC (rev 5339)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Rosetta\Site;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Rosetta\Admin\Network\Locale_Associations;
+use WordPressdotorg\Rosetta\Admin\Network\Locale_Associations_View;
+use WordPressdotorg\Rosetta\Database\Tables;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Rosetta\Jetpack;
</span><span class="cx" style="display: block; padding: 0 10px"> use WP_Site;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -42,5 +45,31 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $jetpack_connector = new Jetpack\Connector();
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'wpmu_new_blog', [ $jetpack_connector, 'schedule_connect_event' ], 20, 1 );
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( $jetpack_connector->get_connect_event_name(), [ $jetpack_connector, 'connect_site' ] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               add_action( 'wpmu_new_blog', [ $this, 'set_new_blog_lang_id' ], 30, 1 );
+
+               add_action( 'network_admin_menu', function() {
+                       $locale_associations = new Locale_Associations( new Locale_Associations_View() );
+                       $locale_associations->register();
+               } );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * Sets 'lang_id' for new sites.
+        *
+        * @param int $blog_id ID of the new site.
+        */
+       public function set_new_blog_lang_id( $blog_id ) {
+               global $wpdb;
+
+               $site = get_site( $blog_id );
+               $subdomain = strtok( $site->domain, '.' );
+
+               $lang_id = $wpdb->get_var( $wpdb->prepare( 'SELECT locale_id FROM ' . Tables::LOCALES . ' WHERE subdomain = %s', $subdomain ) );
+               if ( ! $lang_id ) {
+                       return;
+               }
+
+               update_blog_details( $blog_id, [ 'lang_id' => $lang_id ] );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>