<!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>[4929] sites/trunk: Translate/Rosetta: Add infrastructure for Cross-Locale PTEs.</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/4929">4929</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/4929","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-02-18 21:57:45 +0000 (Sat, 18 Feb 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'>Translate/Rosetta: Add infrastructure for Cross-Locale PTEs.
Props akirk.
See <a href="http://meta.trac.wordpress.org/ticket/2000">#2000</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesjsrosettarolesjs">sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/js/rosetta-roles.js</a></li>
<li><a href="#sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesrosettarolesphp">sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggprosettarolesincclasspluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/inc/class-plugin.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolescrosslocaleptephp">sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/cross-locale-pte.php</a></li>
<li><a href="#sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesviewscrosslocaleptephp">sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/cross-locale-pte.php</a></li>
<li><a href="#sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesviewseditcrosslocaleptephp">sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/edit-cross-locale-pte.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolescrosslocaleptephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/cross-locale-pte.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/cross-locale-pte.php (rev 0)
+++ sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/cross-locale-pte.php 2017-02-18 21:57:45 UTC (rev 4929)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,446 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Class used to implement a user that can approve and import translations in all
+ * translation-sets of a project but cannot overwrite current translations by others.
+ */
+class Cross_Locale_PTE {
+
+ /**
+ * The special locale name.
+ */
+ const ALL_LOCALES = 'all-locales';
+
+ /**
+ * The capability the user needs to have to manage Cross-Locale PTEs.
+ */
+ const MANAGE_CROSS_LOCALE_PTES_CAP = 'manage_network_users';
+
+ /**
+ * Cache group.
+ *
+ * @var string
+ */
+ public static $cache_group = 'wporg-translate';
+
+ /**
+ * The admin page hook suffix.
+ *
+ * @var string
+ */
+ private static $admin_page;
+
+ /**
+ * The user that is being administered.
+ *
+ * @var WP_User
+ */
+ private static $user;
+
+ /**
+ * Init Admin hooks.
+ */
+ public static function init_admin() {
+ if ( current_user_can( self::MANAGE_CROSS_LOCALE_PTES_CAP ) ) {
+ add_action( 'admin_menu', array( __CLASS__, 'register_admin_page' ) );
+ }
+ }
+
+ /**
+ * Register the Cross-Locale PTE Admin page in wp-admin.
+ */
+ public static function register_admin_page() {
+ self::$admin_page = add_menu_page(
+ __( 'Cross-Locale PTE', 'rosetta' ),
+ __( 'Cross-Locale PTE', 'rosetta' ),
+ self::MANAGE_CROSS_LOCALE_PTES_CAP,
+ 'cross-locale-pte',
+ array( __CLASS__, 'render_admin_page' ),
+ 'dashicons-translation',
+ 71 // After Users.
+ );
+
+ add_action( 'load-' . self::$admin_page, array( __CLASS__, 'handle_admin_post' ) );
+ add_action( 'admin_print_scripts-' . self::$admin_page, array( 'Rosetta_Roles', 'enqueue_scripts' ) );
+ add_action( 'admin_footer-' . self::$admin_page, array( 'Rosetta_Roles', 'print_js_templates' ) );
+ add_action( 'admin_print_styles-' . self::$admin_page, array( 'Rosetta_Roles', 'enqueue_styles' ) );
+ }
+
+ /**
+ * Handle POST requests for the admin page.
+ */
+ public static function handle_admin_post() {
+ $redirect = menu_page_url( 'cross-locale-pte', false );
+
+ if ( ! current_user_can( self::MANAGE_CROSS_LOCALE_PTES_CAP ) ) {
+ wp_redirect( $redirect );
+ exit;
+ }
+
+ if ( ! empty( $_REQUEST['user'] ) ) {
+ check_admin_referer( 'cross-locale-pte', '_nonce_cross-locale-pte' );
+
+ self::$user = get_user_by( 'login', $_REQUEST['user'] );
+ if ( ! self::$user ) {
+ self::$user = get_user_by( 'email', $_REQUEST['user'] );
+ }
+
+ if ( self::$user ) {
+ wp_redirect( add_query_arg( array( 'user_id' => self::$user->ID ), $redirect ) );
+ } else {
+ wp_redirect( add_query_arg( array( 'error' => 'no-user-found' ), $redirect ) );
+ }
+ exit;
+ }
+
+ if ( ! empty( $_REQUEST['user_id'] ) ) {
+ self::$user = get_user_by( 'id', $_REQUEST['user_id'] );
+ if ( ! self::$user ) {
+ wp_redirect( add_query_arg( array( 'error' => 'no-user-found' ), $redirect ) );
+ exit;
+ }
+ }
+
+ if ( ! empty( $_REQUEST['action'] ) ) {
+ switch ( $_REQUEST['action'] ) {
+ case 'update-cross-locale-pte':
+ check_admin_referer( 'update-cross-locale-pte_' . self::$user->ID );
+ return self::update_cross_locale_pte();
+ }
+
+ return self::render_edit_page();
+ }
+ }
+
+ /**
+ * Render the Cross-Locale PTE overview page in the admin.
+ */
+ public static function render_admin_page() {
+ if ( ! empty( $_REQUEST['user_id'] ) ) {
+ return self::render_edit_page( $_REQUEST['user_id'] );
+ }
+
+ $feedback_message = '';
+ $cross_locale_pte_users = self::get_all_users();
+ require __DIR__ . '/views/cross-locale-pte.php';
+ }
+
+ /**
+ * Update the projects for the Cross-Locale PTE.
+ */
+ public static function update_cross_locale_pte() {
+ global $wpdb;
+
+ $projects = array_map( 'strval', explode( ',', $_REQUEST['projects'] ) );
+ $current_projects = self::get_users_projects( self::$user->ID );
+
+ $projects_to_remove = array_diff( $current_projects, $projects );
+ $projects_to_add = array_diff( $projects, $current_projects );
+
+ $now = current_time( 'mysql', 1 );
+
+ $values_to_add = array();
+ foreach ( $projects_to_add as $project_id ) {
+ $values_to_add[] = $wpdb->prepare( '(%d, %d, %s, %s)',
+ self::$user->ID,
+ $project_id,
+ self::ALL_LOCALES,
+ $now
+ );
+ }
+
+ if ( $values_to_add ) {
+ $wpdb->query( "
+ INSERT INTO {$wpdb->wporg_translation_editors}
+ ( `user_id`,`project_id`, `locale`, `date_added` )
+ VALUES " . implode( ', ', $values_to_add )
+ );
+ }
+
+ $values_to_remove = array_map( 'intval', $projects_to_remove );
+ if ( $values_to_remove ) {
+ $wpdb->query( $wpdb->prepare( "
+ DELETE FROM {$wpdb->wporg_translation_editors}
+ WHERE `user_id` = %d AND `locale` = %s
+ AND project_id IN (" . implode( ', ', $values_to_remove ) . ')',
+ self::$user->ID, self::ALL_LOCALES ) );
+ }
+
+ wp_redirect( add_query_arg( array( 'user_id' => self::$user->ID ), menu_page_url( 'cross-locale-pte', false ) ) );
+ exit;
+ }
+
+ /**
+ * Render the page to edit a single Cross-Locale PTE.
+ */
+ public static function render_edit_page() {
+ $user = self::$user;
+ $project_access_list = self::get_users_projects( $user->ID );
+ $last_updated = get_blog_option( WPORG_TRANSLATE_BLOGID, 'wporg_projects_last_updated' );
+
+ wp_localize_script( 'rosetta-roles', '_rosettaProjectsSettings', array(
+ 'l10n' => array(
+ 'searchPlaceholder' => esc_attr__( 'Search...', 'rosetta' ),
+ ),
+ 'lastUpdated' => $last_updated,
+ 'accessList' => $project_access_list,
+ ) );
+
+ $feedback_message = '';
+ require __DIR__ . '/views/edit-cross-locale-pte.php';
+ }
+
+ /**
+ * Retrieves the projects for which a user has cross-locale PTE permissions.
+ *
+ * @param int $user_id User ID.
+ * @return array List of project IDs.
+ */
+ public static function get_users_projects( $user_id ) {
+ global $wpdb;
+
+ $projects = $wpdb->get_col( $wpdb->prepare( "
+ SELECT project_id FROM
+ {$wpdb->wporg_translation_editors}
+ WHERE user_id = %d AND locale = %s
+ ", $user_id, self::ALL_LOCALES ) );
+
+ return $projects;
+ }
+ /**
+ * Retrieves the projects for which a user has cross-locale PTE permissions.
+ *
+ * @return array List of User IDs.
+ */
+ public static function get_all_users() {
+ global $wpdb;
+
+ $rows = $wpdb->get_results( $wpdb->prepare( "
+ SELECT te.user_id, te.project_id, p.name AS project_name FROM
+ {$wpdb->wporg_translation_editors} te
+ JOIN translate_projects p ON te.project_id = p.id
+ WHERE te.locale = %s
+ ", self::ALL_LOCALES ) );
+
+ $user_ids = array();
+ foreach ( $rows as $row ) {
+ if ( ! isset( $user_ids[ $row->user_id ] ) ) {
+ $user = get_user_by( 'id', $row->user_id );
+ if ( ! $user ) {
+ continue;
+ }
+ $row->user_login = $user->user_login;
+ $row->email = $user->user_email;
+ $row->display_name = $user->display_name;
+ $row->projects = array( $row->project_id => $row->project_name );
+ $user_ids[ $row->user_id ] = $row;
+ } else {
+ $user_ids[ $row->user_id ]->projects[ $row->project_id ] = $row->project_name;
+ }
+ }
+
+ return $user_ids;
+ }
+
+ /**
+ * Check for the Cross-Locale PTE permission for the project.
+ *
+ * @param WP_User $user The user.
+ * @param int $project_id The Project ID.
+ * @return string|bool The verdict.
+ */
+ public static function user_has_cross_locale_permission( $user, $project_id ) {
+ static $cache = null;
+
+ if ( null === $cache ) {
+ $cache = array();
+ }
+
+ $user_id = intval( $user->ID );
+ $project_id = intval( $project_id );
+
+ if ( isset( $cache[ $user_id ][ $project_id ] ) ) {
+ return $cache[ $user_id ][ $project_id ];
+ }
+
+ if ( ! isset( $cache[ $user_id ] ) ) {
+ $cache[ $user_id ] = array();
+ }
+
+ global $wpdb;
+ $result = $wpdb->get_col( $wpdb->prepare( "
+ SELECT te.user_id FROM
+ {$wpdb->wporg_translation_editors} te
+ JOIN translate_projects p ON ( te.project_id = p.id OR te.project_id = p.parent_project_id )
+ WHERE te.user_id = %d AND p.id = %d AND te.locale = %s
+ ", $user_id, $project_id, self::ALL_LOCALES ) );
+
+ if ( $result && intval( $result[0] ) === $user_id ) {
+ return $cache[ $user_id ][ $project_id ] = true;
+ }
+
+ return $cache[ $user_id ][ $project_id ] = false;
+ }
+
+ /**
+ * Enforce not-overwriting current translation by others while importing.
+ *
+ * @param string $status The desired status.
+ * @param GP_Translation $new_translation The new translation.
+ * @param GP_Translation $old_translation The old translation.
+ * @return string The new status.
+ */
+ public static function gp_translation_set_import_status( $status, $new_translation, $old_translation ) {
+ if ( ! isset( $old_translation->translation_set_id ) ) {
+ return $status;
+ }
+
+ if ( 'current' !== $old_translation->translation_status ) {
+ return $status;
+ }
+
+ if ( GP::$permission->current_user_can( 'cross-pte', 'translation-set', $old_translation->translation_set_id ) ) {
+ // Set to waiting if a current translation exists by another user.
+ if ( intval( $old_translation->user_id ) !== intval( get_current_user_id() ) ) {
+ return 'waiting';
+ }
+ }
+ return $status;
+ }
+
+ /**
+ * The GlotPress filter for Cross-Locale PTE.
+ *
+ * A Cross-Locale PTE is defined through an entry in the permission table 'cross-pte' with the
+ * object_id referring to a project id.
+ * A user with this permission will have 'approve' rights for all translation-sets within this
+ * project. Usually having approval rights for a translation-set also means that the user has
+ * approval rights for all translations, but not a Cross-Locale PTE:
+ * If a current translation exists by another user then overwriting (through UI or import) is not
+ * possible.
+ *
+ * @param string|bool $verdict The verdict from an earlier filter.
+ * @param array $args Arguments that describe the object to judge for.
+ * @return string|bool The verdict for the object.
+ */
+ public static function gp_pre_can_user( $verdict, $args ) {
+ if ( 'cross-pte' === $args['action'] ) {
+ $verdict = self::gp_pre_can_user_cross_pte( $verdict, $args );
+
+ if ( is_bool( $verdict ) ) {
+ return $verdict;
+ }
+ }
+
+ if ( 'approve' === $args['action'] ) {
+ if ( 'translation' === $args['object_type'] ) {
+ $verdict = self::gp_pre_can_user_approve_translation( $verdict, $args );
+ } elseif ( 'translation-set' === $args['object_type'] ) {
+ $verdict = self::gp_pre_can_user_approve_translation_set( $verdict, $args );
+ }
+ }
+
+ return $verdict;
+
+ }
+
+ /**
+ * A GlotPress sub-filter for the permission 'cross-lte'.
+ *
+ * @param string|bool $verdict The verdict from an earlier filter.
+ * @param array $args Arguments that describe the object to judge for.
+ * @return string|bool The verdict for the object.
+ */
+ public static function gp_pre_can_user_cross_pte( $verdict, $args ) {
+ if ( GP::$permission->user_can( $args['user'], 'admin' ) ) {
+ // Admins shouldn't have this because it will end up restricting them.
+ return false;
+ }
+
+ if ( 'translation-set' === $args['object_type'] ) {
+ if ( isset( $args['extra']['set']->id ) && intval( $args['extra']['set']->id ) === intval( $args['object_id'] ) ) {
+ $set = $args['extra']['set'];
+ } else {
+ $set = GP::$translation_set->get( $args['object_id'] );
+ }
+
+ // Allow on all translation-sets within the project.
+ if ( $set ) {
+ return GP::$permission->user_can( $args['user'], 'cross-pte', 'project', $set->project_id );
+ }
+ } elseif ( 'project' === $args['object_type'] ) {
+ return self::user_has_cross_locale_permission( $args['user'], $args['object_id'] );
+ }
+
+ return $verdict;
+ }
+
+ /**
+ * A GlotPress sub-filter for the permission 'approve' and object 'translation'.
+ *
+ * @param string|bool $verdict The verdict from an earlier filter.
+ * @param array $args Arguments that describe the object to judge for.
+ * @return string|bool The verdict for the object.
+ */
+ public static function gp_pre_can_user_approve_translation( $verdict, $args ) {
+ if ( isset( $args['extra']['translation']->translation_set_id ) && intval( $args['extra']['translation']->id ) === intval( $args['object_id'] ) ) {
+ $translation = $args['extra']['translation'];
+ } else {
+ $translation = GP::$translation->get( $args['object_id'] );
+ }
+
+ if ( ! $translation ) {
+ return $verdict;
+ }
+
+ static $current_translation_by_user;
+ $cache_key = $args['user']->ID . '_' . $translation->original_id;
+
+ if ( isset( $current_translation_by_user[ $cache_key ] ) ) {
+ return $current_translation_by_user[ $cache_key ];
+ }
+
+ if ( GP::$permission->user_can( $args['user'], 'cross-pte', 'translation-set', $translation->translation_set_id ) ) {
+ $current_translation = GP::$translation->find_one( array( 'translation_set_id' => $translation->translation_set_id, 'original_id' => $translation->original_id, 'status' => 'current' ) );
+ if ( $current_translation && intval( $current_translation->user_id ) !== $args['user']->ID ) {
+ // Current translation was authored by someone else. Disallow setting to current.
+ return $current_translation_by_user[ $cache_key ] = false;
+ }
+
+ // No current translation exists or it was translated by me: allow.
+ return $current_translation_by_user[ $cache_key ] = true;
+ }
+
+ // Allows usage of the re-implementation below.
+ if ( GP::$permission->user_can( $args['user'], 'approve', 'translation-set', $translation->translation_set_id ) ) {
+ return true;
+ }
+
+ return $verdict;
+ }
+
+ /**
+ * A GlotPress sub-filter for the permission 'approve' and object 'translation-set'.
+ *
+ * @param string|bool $verdict The verdict from an earlier filter.
+ * @param array $args Arguments that describe the object to judge for.
+ * @return string|bool The verdict for the object.
+ */
+ public static function gp_pre_can_user_approve_translation_set( $verdict, $args ) {
+ // Re-implementation of gp_route_translation_set_permissions_to_validator_permissions().
+ if ( isset( $args['extra']['set']->id ) && intval( $args['extra']['set']->id ) === intval( $args['object_id'] ) ) {
+ $set = $args['extra']['set'];
+ } else {
+ $set = GP::$translation_set->get( $args['object_id'] );
+ }
+
+ if ( $set ) {
+ if ( GP::$permission->user_can( $args['user'], 'cross-pte', 'project', $set->project_id ) ) {
+ return true;
+ }
+
+ return GP::$permission->user_can( $args['user'], 'approve', GP::$validator_permission->object_type, GP::$validator_permission->object_id( $set->project_id, $set->locale, $set->slug ) );
+ }
+
+ return $verdict;
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesjsrosettarolesjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/js/rosetta-roles.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/js/rosetta-roles.js 2017-02-18 21:26:45 UTC (rev 4928)
+++ sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/js/rosetta-roles.js 2017-02-18 21:57:45 UTC (rev 4929)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -254,6 +254,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $( '#project-loading' ).remove();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Mark the first item as active.
+ var $firstActive = view.$el.find( 'li.active' );
+ if ( ! $firstActive.length ) {
+ $firstActive = view.$el.find( 'li input[type=radio]' );
+ }
+ if ( ! $firstActive.length ) {
+ $firstActive = view.$el.find( 'li:first-child' );
+ }
+ $firstActive.closest( 'li' ).addClass( 'active' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> this.views.ready();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return this;
</span></span></pre></div>
<a id="sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesrosettarolesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php 2017-02-18 21:26:45 UTC (rev 4928)
+++ sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php 2017-02-18 21:57:45 UTC (rev 4929)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,6 +11,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require_once GLOTPRESS_LOCALES_PATH;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+require __DIR__ . '/cross-locale-pte.php';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> class Rosetta_Roles {
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Endpoint for profiles.wordpress.org updates.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -67,13 +69,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->gp_locale = $gp_locale;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_action( 'admin_menu', array( $this, 'register_translation_editors_page' ) );
- add_filter( 'set-screen-option', array( $this, 'save_custom_screen_options' ), 10, 3 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_main_site() ) {
+ add_action( 'admin_menu', array( $this, 'register_translation_editors_page' ) );
+ add_filter( 'set-screen-option', array( $this, 'save_custom_screen_options' ), 10, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_action( 'translation_editor_added', array( $this, 'update_wporg_profile_badge' ) );
- add_action( 'translation_editor_removed', array( $this, 'update_wporg_profile_badge' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_action( 'translation_editor_added', array( $this, 'update_wporg_profile_badge' ) );
+ add_action( 'translation_editor_removed', array( $this, 'update_wporg_profile_badge' ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_ajax_rosetta-get-projects', array( $this, 'ajax_rosetta_get_projects' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ Cross_Locale_PTE::init_admin();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -92,23 +98,23 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'load-' . $this->translation_editors_page, array( $this, 'load_translation_editors_page' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'load-' . $this->translation_editors_page, array( $this, 'register_screen_options' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_action( 'admin_print_scripts-' . $this->translation_editors_page, array( $this, 'enqueue_scripts' ) );
- add_action( 'admin_footer-' . $this->translation_editors_page, array( $this, 'print_js_templates' ) );
- add_action( 'admin_print_styles-' . $this->translation_editors_page, array( $this, 'enqueue_styles' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_action( 'admin_print_scripts-' . $this->translation_editors_page, array( __CLASS__, 'enqueue_scripts' ) );
+ add_action( 'admin_footer-' . $this->translation_editors_page, array( __CLASS__, 'print_js_templates' ) );
+ add_action( 'admin_print_styles-' . $this->translation_editors_page, array( __CLASS__, 'enqueue_styles' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Enqueues scripts.
</span><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 enqueue_scripts() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function enqueue_scripts() {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_script( 'string_score', plugins_url( '/js/string_score.min.js', __FILE__ ), array(), '0.1.22', true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_enqueue_script( 'rosetta-roles', plugins_url( '/js/rosetta-roles.js', __FILE__ ), array( 'jquery', 'wp-backbone', 'string_score' ), '9', true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_enqueue_script( 'rosetta-roles', plugins_url( '/js/rosetta-roles.js', __FILE__ ), array( 'jquery', 'wp-backbone', 'string_score' ), '10', true );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Enqueues styles.
</span><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 enqueue_styles() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function enqueue_styles() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $suffix = is_rtl() ? '-rtl' : '';
</span><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_style( 'rosetta-roles', plugins_url( "/css/rosetta-roles$suffix.css", __FILE__ ), array(), '4' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -116,7 +122,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Prints JavaScript templates.
</span><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 print_js_templates() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function print_js_templates() {
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <script id="tmpl-project-checkbox" type="text/html">
</span><span class="cx" style="display: block; padding: 0 10px"> <# if ( ! data.checkedSubProjects ) {
</span></span></pre></div>
<a id="sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesviewscrosslocaleptephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/cross-locale-pte.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/cross-locale-pte.php (rev 0)
+++ sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/cross-locale-pte.php 2017-02-18 21:57:45 UTC (rev 4929)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,57 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<div class="wrap">
+ <h2>
+ <?php _e( 'Cross-Locale PTEs', 'rosetta' ); ?>
+ </h2>
+
+ <?php echo $feedback_message; ?>
+
+ <p><?php _e( 'This is the list of our current Cross-Locale PTEs.', 'rosetta' ); ?></p>
+ <table class="wp-list-table widefat fixed striped translation-editors">
+ <thead>
+ <tr>
+ <th scope="col" id="username" class="column-username column-primary">Username</th>
+ <th scope="col" id="name" class="column-name">Name</th>
+ <th scope="col" id="email" class="column-email">E-mail</th>
+ <th scope="col" id="projects" class="column-projects">Projects</th></tr>
+ </thead>
+
+ <tbody id="the-list">
+ <?php $url = menu_page_url( 'cross-locale-pte', false ); ?>
+ <?php foreach ( $cross_locale_pte_users as $user_id => $user ) : ?>
+ <tr>
+ <td class="username column-username column-primary">
+ <?php echo get_avatar( $user_id, 32 ); ?>
+ <a href="<?php echo esc_url( add_query_arg( array( 'user_id' => $user_id ), $url ) ); ?>"><?php echo esc_html( $user->user_login ); ?></a>
+ </td>
+ <td class="name column-name">
+ <?php echo esc_html( $user->display_name ); ?>
+ </td>
+ <td class="email column-email">
+ <a href="mailto:<?php echo esc_attr( $user->email ); ?>"><?php echo esc_html( $user->email ); ?></a>
+ </td>
+ <td class="projects column-projects"><?php
+ asort( $user->projects );
+ echo implode( ', ', array_map( 'esc_html', $user->projects ) );
+ ?>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+ </table>
+
+ <?php if ( current_user_can( Rosetta_Roles::MANAGE_TRANSLATION_EDITORS_CAP ) ) : ?>
+ <h3><?php _e( 'Add Cross-Locale PTE', 'rosetta' ); ?></h3>
+ <p><?php _e( 'Enter the email address or username of an existing user on wordpress.org.', 'rosetta' ); ?></p>
+ <form action="" method="post">
+ <table class="form-table">
+ <tr>
+ <th scope="row"><label for="user"><?php _e( 'E-mail or Username', 'rosetta' ); ?></label></th>
+ <td><input type="text" class="regular-text" name="user" id="user"></td>
+ </tr>
+ </table>
+ <input type="hidden" name="action" value="cross-locale-pte">
+ <?php wp_nonce_field( 'cross-locale-pte', '_nonce_cross-locale-pte' ) ?>
+ <?php submit_button( __( 'Add Cross-Locale PTE', 'rosetta' ) ); ?>
+ </form>
+ <?php endif; ?>
+</div>
</ins></span></pre></div>
<a id="sitestrunkglobalwordpressorgpublic_htmlwpcontentmupluginsrolesviewseditcrosslocaleptephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/edit-cross-locale-pte.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/edit-cross-locale-pte.php (rev 0)
+++ sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/edit-cross-locale-pte.php 2017-02-18 21:57:45 UTC (rev 4929)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,45 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<div class="wrap">
+ <h2><?php _e( 'Edit Cross-Locale PTE', 'rosetta' ); ?></h2>
+
+ <?php echo $feedback_message; ?>
+
+ <p><?php
+ printf(
+ /* translators: %s: username */
+ __( 'You are currently editing the user %s.', 'rosetta' ),
+ '<em>' . $user->user_login . '</em>'
+ );
+ ?></p>
+
+ <form method="post">
+ <table class="form-table">
+ <tbody>
+ <tr>
+ <th scope="row">
+ <?php _e( 'Add cross-locale PTE access for:', 'rosetta' ); ?><br>
+ </th>
+ <td>
+ <fieldset id="projects">
+ <legend class="screen-reader-text"><span><?php _e( 'Add cross-locale PTE access for:', 'rosetta' ); ?></span></legend>
+
+ <ul id="projects-list" class="projects-list">
+ <li id="project-loading" class="loading">
+ <?php _e( 'Loading…', 'rosetta' ); ?>
+ </li>
+ </ul>
+ </fieldset>
+ <p class="description"><?php _e( 'Each project includes sub projects and newly-added sub projects.', 'rosetta' ); ?></p>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+
+ <input type="hidden" id="project-access-list" name="projects" value="<?php esc_attr( implode( ',', $project_access_list ) ); ?>">
+ <input type="hidden" name="action" value="update-cross-locale-pte" />
+ <input type="hidden" name="user_id" value="<?php echo esc_attr( $user->ID ); ?>" />
+ <?php
+ wp_nonce_field( 'update-cross-locale-pte_' . $user->ID );
+ submit_button( _x( 'Update', 'translation editor', 'rosetta' ) );
+ ?>
+ </form>
+</div>
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggprosettarolesincclasspluginphp"></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-rosetta-roles/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/wporg-gp-rosetta-roles/inc/class-plugin.php 2017-02-18 21:26:45 UTC (rev 4928)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/inc/class-plugin.php 2017-02-18 21:57:45 UTC (rev 4929)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,7 +4,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> use GP;
</span><span class="cx" style="display: block; padding: 0 10px"> use GP_Locales;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use Cross_Locale_PTE;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+require_once WPMU_PLUGIN_DIR . '/rosetta-network/roles/cross-locale-pte.php';
+
</ins><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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -67,6 +70,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'gp_pre_can_user', array( $this, 'pre_can_user' ), 9 , 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'gp_project_created', array( $this, 'project_created' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'gp_project_saved', array( $this, 'project_saved' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_filter( 'gp_translation_set_import_status', array( 'Cross_Locale_PTE', 'gp_translation_set_import_status' ), 9, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_admin() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $users = new Admin\Translators();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -98,6 +102,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Grant permissions to Cross-Locale PTEs.
+ $cross_locale_pte_verdict = Cross_Locale_PTE::gp_pre_can_user( $verdict, $args );
+ # var_dump($cross_locale_pte_verdict);
+ if ( is_bool( $cross_locale_pte_verdict ) ) {
+ return $cross_locale_pte_verdict;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // No permissions for unknown object types.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! in_array( $args['object_type'], array( 'project|locale|set-slug', 'translation-set', 'translation' ), true ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span></span></pre>
</div>
</div>
</body>
</html>