<!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>[11362] sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher: Trac / SVN / Make: Monitor develop.svn.wordpress.org & meta.svn.wordpress.org and import revisions into a custom table, parsing out prop'd users.</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 { white-space: pre-line; 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/11362">11362</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/11362","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-12-13 05:41:15 +0000 (Mon, 13 Dec 2021)</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'>Trac / SVN / Make: Monitor develop.svn.wordpress.org & meta.svn.wordpress.org and import revisions into a custom table, parsing out prop'd users.
Included are various reports and some work to capture typo's of prop'd users.
The code is definitely not DRY, clean, or named properly - but it works.
See <a href="http://meta.trac.wordpress.org/ticket/5978">#5978</a>.</pre>
<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/</li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradminlisttablephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/list-table.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradminpostphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/post.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradminreportspagephp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/reports-page.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradmintracwatchcss">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/trac-watch.css</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradmintracwatchjs">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/trac-watch.js</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradminuiphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/ui.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcherpropsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/props.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatchersvnphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/svn.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatchertracwatchphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/trac-watch.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatchertracphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/trac.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradminlisttablephp"></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/wporg-trac-watcher/admin/list-table.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-trac-watcher/admin/list-table.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/list-table.php 2021-12-13 05:41:15 UTC (rev 11362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,391 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Trac\Watcher;
+use function WordPressdotorg\Trac\Watcher\Trac\format_trac_markup as format_for_trac;
+use WP_List_Table;
+
+if ( ! class_exists( 'WP_List_Table' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
+}
+
+class Commits_List_Table extends WP_List_Table {
+
+ protected $svn;
+
+ public function __construct( $svn_details ) {
+ $this->svn = $svn_details;
+
+ parent::__construct();
+ }
+
+ public function prepare_items( $args = array() ) {
+ global $wpdb;
+
+ $this->_column_headers = [
+ $this->get_columns(),
+ $this->get_hidden_columns(),
+ $this->get_sortable_columns()
+ ];
+
+ $rev_table = $this->svn['rev_table'];
+ $props_table = $this->svn['props_table'];
+ $page = max( 0, ($args['paged'] ?? 0) -1 );
+ $screen = get_current_screen();
+ $per_page = $screen ? $screen->get_option( 'per_page', 'default' ) : 200;
+ $offset = $per_page * $page;
+
+ $o_field = 'id';
+ $o_order = 'DESC';
+ if ( isset( $args['orderby'] ) && !empty( $this->get_sortable_columns()[ $args['orderby'] ] ) ) {
+ $o_field = $args['orderby'];
+ }
+ if ( isset( $args['order'] ) && strtoupper( $args['order'] ) === 'ASC' ) {
+ $o_order = 'ASC';
+ }
+
+ $join = '';
+ $where = '';
+
+ // Filter to unknown props only.
+ if ( ! empty( $args['unknown-props'] ) ) {
+ $join .= "LEFT JOIN {$props_table} p ON r.id = p.revision";
+ $where .= "AND p.id IS NOT NULL AND p.user_id IS NULL";
+ }
+
+ if ( ! empty( $args['revision'] ) ) {
+ $where .= $wpdb->prepare( ' AND r.id = %d ', $args['revision'] );
+ }
+
+ if ( ! empty( $args['version'] ) ) {
+ $where .= $wpdb->prepare( ' AND version LIKE %s', $wpdb->esc_like( $args['version'] ) . '%' );
+ }
+ if ( ! empty( $args['branch'] ) ) {
+ $where .= $wpdb->prepare( ' AND branch LIKE %s', $wpdb->esc_like( $args['branch'] ) );
+ }
+
+ if ( ! empty( $args['revisions'] ) && preg_match( '!(?P<start>\d+):(?P<end>\d+)!', $args['revisions'], $m ) ) {
+ $where .= $wpdb->prepare( ' AND id BETWEEN %d AND %d', $m['start'], $m['end'] );
+ }
+ if ( ! empty( $args['revisions'] ) && preg_match( '!^[\d,]+$!', $args['revisions'], $m ) ) {
+ $ids = implode(',', array_map( 'intval', explode( ',', $args['revisions'] ) ) );
+ $where .= " AND id IN({$ids})";
+ }
+
+ if ( ! empty( $args['author'] ) ) {
+ $where .= $wpdb->prepare( ' AND author = %s', $args['author'] );
+ }
+
+ if ( ! empty( $args['s'] ) ) {
+ if ( ! $join ) {
+ $join .= "LEFT JOIN {$props_table} p ON r.id = p.revision";
+ }
+ $where .= $wpdb->prepare(
+ ' AND ( message LIKE %s OR p.prop_name LIKE %s )',
+ '%' . $wpdb->esc_like( $args['s'] ) . '%',
+ '%' . $wpdb->esc_like( $args['s'] ) . '%',
+ );
+ }
+
+ // $where .= ' AND r.id IN( 46290, 51195, 50933, 50810 )';
+
+ $this->items = $wpdb->get_results(
+ "SELECT SQL_CALC_FOUND_ROWS r.* FROM {$rev_table} r
+ {$join}
+ WHERE 1=1 {$where}
+ GROUP BY r.id
+ ORDER BY r.{$o_field} {$o_order}
+ LIMIT {$offset},{$per_page}"
+ );
+ $total_items = $wpdb->get_var( 'SELECT FOUND_ROWS()' );
+ $this->fill_props();
+
+ $this->set_pagination_args( [
+ 'total_items' => $total_items,
+ 'per_page' => $per_page,
+ ] );
+ }
+
+ protected function fill_props() {
+ global $wpdb;
+
+ if ( ! $this->items ) {
+ return;
+ }
+
+ $props_table = $this->svn['props_table'];
+
+ $revisions = wp_list_pluck( $this->items, 'id' );
+ $revisions = implode( ',', array_map( 'intval', $revisions ) );
+
+ $props_list = $wpdb->get_results( $wpdb->prepare(
+ "SELECT revision,user_id,prop_name
+ FROM {$props_table}
+ WHERE revision IN({$revisions})
+ ORDER BY LENGTH(prop_name) DESC
+ "
+ ) );
+
+ foreach ( $this->items as $i => $details ) {
+ $this->items[$i]->props = wp_list_pluck(
+ wp_list_filter(
+ $props_list,
+ [
+ 'revision' => $details->id,
+ ]
+ ),
+ 'user_id',
+ 'prop_name'
+ );
+ }
+
+ }
+
+ public function extra_tablenav( $which ) {
+ global $wpdb;
+ $views = $this->get_views();
+
+ if ( empty( $views ) )
+ return;
+
+ $this->views();
+
+ if ( 'top' === $which ) {
+ echo '<div class="actions alignleft">';
+ if ( 'core' === $this->svn['slug'] ) {
+ echo '<select name="version"><option value="">Version</option>';
+ foreach ( get_wordpress_versions() as $v ) {
+ printf(
+ '<option value="%s" %s>%s</option>',
+ esc_attr( $v ),
+ selected( $_REQUEST['version'] ?? '', $v ),
+ esc_html( $v )
+ );
+ }
+
+ echo '</select>';
+ }
+
+ $branches = get_branches_for( $this->svn );
+ if ( $branches ) {
+ echo '<select name="branch"><option value="">Branch</option>';
+ foreach ( $branches as $b ) {
+ printf(
+ '<option value="%s" %s>%s</option>',
+ esc_attr( $b ),
+ selected( $_REQUEST['branch'] ?? '', $b ),
+ esc_html( $b )
+ );
+ }
+ echo '</select>';
+ }
+
+ echo '<select name="author"><option value="">Author</option>';
+ $authors = get_transient( $this->svn['slug'] . '_authors' );
+ if ( ! $authors ) {
+ $authors = $wpdb->get_results( 'SELECT author, count(*) as count, max(date), max(date) > DATE_SUB( NOW(), INTERVAL 1 YEAR) as active FROM ' . $this->svn['rev_table'] . ' GROUP BY author ORDER BY author ASC' );
+ set_transient( $this->svn['slug'] . '_authors', $authors, DAY_IN_SECONDS );
+ }
+ $last = 1;
+
+ foreach ( [ 1 => 'Recently Active', 0 => 'Inactive' ] as $active_val => $group ) {
+ printf( '<optgroup label="%s">', esc_attr( $group ) );
+ $_authors = wp_list_filter( $authors, [ 'active' => $active_val ] );
+ foreach ( $_authors as $a ) {
+ printf(
+ '<option value="%s" %s>%s (%s)</option>',
+ esc_attr( $a->author ),
+ selected( $_REQUEST['author'] ?? '', $a->author ),
+ esc_html( $a->author ),
+ esc_html( number_format_i18n( $a->count ) )
+ );
+ }
+ echo '</optgroup>';
+ }
+ echo '</select>';
+
+ echo '<input type="text" name="revisions" placeholder="Revs: 1:HEAD or 1,2,4,5" value="' . esc_attr( $_REQUEST['revisions'] ?? '' ) .'">';
+
+ echo '<input type="submit" class="button button-secondary" value="Filter">';
+ echo '</div>';
+ }
+ }
+
+ function get_views() {
+ $url = add_query_arg( 'page', $_REQUEST['page'], admin_url( 'admin.php' ) );
+
+ $views = [
+ 'all' => '<a href="' . esc_url( $url ) . '">All</a>',
+ 'unknown-props' => '<a href="' . esc_url( add_query_arg( [ 'unknown-props' => 1 ], $url ) ) . '">Unknown Props</a>',
+ ];
+
+ if ( defined( 'WP_CORE_LATEST_RELEASE' ) && 'core' === $this->svn['slug'] ) {
+ $v = sprintf( '%.1f', ((float)WP_CORE_LATEST_RELEASE+0.1) );
+ $views['commits-to-trunk'] = '<a href="' . esc_url( add_query_arg( [ 'version' => $v ], $url ) ) . '">Commits to ' . $v .'</a>';
+ }
+
+ return $views;
+ }
+
+
+ public function get_columns() {
+ $columns = array(
+ 'id' => 'Revision',
+ 'author' => 'Author',
+ 'message' => 'Message',
+ 'date' => 'Date',
+ 'props' => 'Props',
+ 'branch' => 'Branch',
+ 'version' => 'Version'
+ );
+
+ return $columns;
+ }
+
+ public function get_hidden_columns() {
+ return [
+ 'date',
+ 'author',
+ 'branch',
+ 'version',
+ ];
+ }
+
+ public function get_sortable_columns() {
+ return [
+ 'id' => [
+ 'id',
+ false
+ ]
+ ];
+ }
+
+ public function single_row( $item ) {
+ printf(
+ '<tr class="%s" data-revision="%d" data-svn="%s">',
+ esc_attr( 'revision-' . $item->id ),
+ esc_attr( $item->id ),
+ esc_attr( $this->svn['slug'] )
+ );
+
+ $this->single_row_columns( $item );
+ echo '</tr>';
+ }
+
+ public function column_default( $item, $column_name ) {
+ switch( $column_name ) {
+ case 'id':
+ $output = '';
+ $output .= sprintf(
+ "<p><a href='%s'>%s</a></p>",
+ esc_url( $this->svn['trac'] . '/changeset/' . $item->id ),
+ "[{$item->id}]",
+ );
+ foreach ( [ 'date', 'branch', 'version' ] as $field ) {
+ if ( !empty( $item->{$field} ) ) {
+ $output .= sprintf(
+ '<p><strong>%s</strong> %s</p>',
+ $field,
+ esc_html( $item->{$field} )
+ );
+ }
+ }
+
+ $user = get_user_by( 'login', $item->author );
+ $output .= sprintf(
+ '<br><a href="https://profiles.wordpress.org/%s/">%s %s<br>%s</a>',
+ $user->user_nicename,
+ get_avatar( $user, 32 ),
+ esc_html( $user->display_name ),
+ esc_html( $user->user_login )
+ );
+
+
+ return $output;
+
+ case 'author':
+ $user = get_user_by( 'login', $item->author );
+ return sprintf(
+ '<a href="https://profiles.wordpress.org/%s">%s %s</a>',
+ $user->user_nicename,
+ get_avatar( $user, 32 ),
+ $user->display_name
+ );
+
+ case 'message':
+ $message = format_for_trac( $item->message );
+
+ // Highlight props.
+ foreach ( $item->props as $prop => $user_id ) {
+ $user = $user_id ? get_user_by( 'ID', $user_id ) : false;
+
+ if ( false === stripos( $message, $prop ) ) {
+ $message .= "<em>Missed Prop: $prop</em> ";
+ }
+
+ if ( $user && strtolower( $prop ) != strtolower( $user->user_login ) && strtolower( $prop ) != strtolower( $user->user_nicename ) ) {
+ // User is a typo or mis-prop.
+ $message = str_ireplace( $prop, "<del class='replace'>{$prop}</del><ins>{$user->user_nicename}</ins>", $message );
+ } else {
+ // All else.
+ $tag = $user ? 'ins' : 'del';
+ $message = str_ireplace( $prop, "<{$tag}>{$prop}</{$tag}>", $message );
+ }
+ }
+
+ return "<div>{$message}</div>";
+
+ case 'props':
+ $output = '<div class="propslist">';
+
+ foreach ( $item->props as $prop => $user_id ) {
+ $user = $user_id ? get_user_by( 'ID', $user_id ) : false;
+ $avatar = $user_id ? get_avatar( $user, 32 ) : '<span class="dashicons dashicons-editor-help"></span>';
+ $profile = $user ? 'https://profiles.wordpress.org/' . $user->user_nicename . '/' : '';
+
+ $output .= sprintf(
+ '<span class="user" data-prop="%s" data-user="%s">',
+ esc_attr( $prop ),
+ esc_attr( $user->user_login )
+ );
+ if ( $user ) {
+ $output .= '<a href="' . esc_url( $profile ) . '" target="_blank">';
+ }
+
+ $prop_is_different_from_user = ( $user && strtolower( $prop ) != strtolower( $user->user_login ) && strtolower( $prop ) != strtolower( $user->user_nicename ) );
+ $prop_display_name_different = ( $user && $user->display_name != $prop );
+
+ $output .= $avatar;
+ $output .= $user ? $user->display_name : $prop;
+
+ if ( $prop_is_different_from_user ) {
+ $output .= " <em>typo</em>";
+ } elseif ( false === stripos( $item->message, $prop ) ) {
+ $output .= " <em>missed</em>";
+ }
+
+ if ( $user ) {
+ $output .= '</a>';
+ }
+ $output .= '<div class="overlay"><div class="actions"><a href="#" class="edit dashicons dashicons-edit"></a></div></div>';
+
+ if ( $prop_is_different_from_user || $prop_display_name_different ) {
+ $output .= sprintf(
+ '<br><a href="%s" target="_blank">%s</a>',
+ esc_url( $profile ),
+ esc_html( $user->user_login )
+ );
+ }
+
+ $output .= '</span>';
+ }
+ $output .= '<span class="user add"><a href="#" class="add dashicons dashicons-plus"></a> <a href="#" class="add">Add new</a></span>';
+ $output .= '</div>';
+
+ $output .= '<p class="actions"><a href="#" class="reparse">Reparse</a></p>';
+
+ return $output;
+
+ default:
+ return esc_html( $item->{$column_name} );
+ }
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/list-table.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradminpostphp"></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/wporg-trac-watcher/admin/post.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-trac-watcher/admin/post.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/post.php 2021-12-13 05:41:15 UTC (rev 11362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,172 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Trac\Watcher;
+
+add_action( 'admin_post_svn_save', function() {
+ global $wpdb;
+
+ if ( ! current_user_can( 'edit_posts' ) ) {
+ die( '-1' );
+ }
+ check_admin_referer( 'edit_svn_prop' );
+
+ $svns = SVN\get_svns();
+ $svn = $svns[ $_REQUEST['svn'] ] ?? false;
+ $rev = $_REQUEST['revision'] ?? false;
+
+ if ( empty( $svn ) ) {
+ die( -1 );
+ }
+
+ $action = $_REQUEST['what'] ?? false;
+ if ( ! in_array( $action, [ 'add', 'edit', 'delete' ] ) ) {
+ die( -1 );
+ }
+
+ $user = Props\find_user_id( wp_unslash( $_REQUEST['user_id'] ?? '' ) ) ?: null;
+
+ // Operation save. Step one, find the prop.
+ $props = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$svn['props_table']} WHERE revision = %d", $rev ) );
+
+ $the_prop = false;
+ if ( ! empty( $_REQUEST['prop_name_orig'] ) ) {
+ $the_prop = wp_list_filter( $props, [ 'prop_name' => wp_unslash( $_REQUEST['prop_name_orig'] ) ] );
+ $the_prop = $the_prop ? array_shift( $the_prop ) : false;
+ }
+
+ if ( 'delete' == $action && $the_prop ) {
+ $wpdb->delete(
+ $svn['props_table'],
+ [
+ 'id' => $the_prop->id,
+ 'revision' => $rev,
+ ]
+ );
+ } elseif ( 'edit' === $action && $the_prop ) {
+ if ( ! isset( $_REQUEST['prop_name'] ) ) {
+ die( -1 );
+ }
+
+ $prop_name = wp_unslash( $_REQUEST['prop_name'] );
+ if ( ! $user && $prop_name != $the_prop->prop_name ) {
+ $user = Props\find_user_id( $prop_name );
+ }
+
+ // Updating one.
+ $wpdb->update(
+ $svn['props_table'],
+ [
+ 'prop_name' => $prop_name,
+ 'user_id' => $user ?: null,
+ ],
+ [
+ 'id' => $the_prop->id,
+ ]
+ );
+
+ // Maybe update other occurences of this typo.
+ if ( $prop_name === $the_prop->prop_name && ! $the_prop->user_id && $user ) {
+ $wpdb->update(
+ $svn['props_table'],
+ [
+ 'user_id' => $user,
+ ],
+ [
+ 'prop_name' => $the_prop->prop_name,
+ 'user_id' => null
+ ]
+ );
+ }
+
+ // If editing, and cleared the prop, Delete instead.
+ if ( empty( $prop_name ) ) {
+ $wpdb->delete(
+ $svn['props_table'],
+ [
+ 'id' => $the_prop->id,
+ 'revision' => $rev,
+ ]
+ );
+ }
+
+ } elseif ( 'add' === $action ) {
+ // Adding one?
+
+ if ( empty( $_REQUEST['prop_name'] ) ) {
+ die( -1 );
+ }
+
+ $prop_name = wp_unslash( $_REQUEST['prop_name'] );
+ if ( ! $user ) {
+ $user = Props\find_user_id( $prop_name );
+ }
+
+ $wpdb->insert(
+ $svn['props_table'],
+ [
+ 'revision' => $rev,
+ 'prop_name' => $prop_name,
+ 'user_id' => $user,
+ ]
+ );
+ }
+
+ // Output the replacement `<td>`'s
+ $table = new Commits_List_Table( $svn );
+ $table->prepare_items( [ 'revision' => $rev ] );
+ $table->single_row_columns( $table->items[0] );
+
+} );
+
+add_action( 'admin_post_svn_reparse', function() {
+ global $wpdb;
+
+ if ( ! current_user_can( 'edit_posts' ) ) {
+ die( '-1' );
+ }
+ check_admin_referer( 'reparse_svn' );
+
+ $svns = SVN\get_svns();
+ $svn = $svns[ $_REQUEST['svn'] ] ?? false;
+ $rev = $_REQUEST['revision'] ?? false;
+
+ if ( empty( $svn ) || empty( $rev ) ) {
+ die( -1 );
+ }
+
+ // Get the commit details.
+ $details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$svn['rev_table']} WHERE id = %d", $rev ) );
+ if ( ! $details ) {
+ die( -1 );
+ }
+
+ // Remove the props for the commit first.
+ $wpdb->delete(
+ $svn['props_table'],
+ [
+ 'revision' => $rev
+ ]
+ );
+
+ // Reparse
+ $props = Props\from_log( $details->message );
+
+ // Reinsert
+ foreach ( $props as $prop ) {
+ $data = [
+ 'revision' => $rev,
+ 'prop_name' => $prop,
+ ];
+
+ $user_id = Props\find_user_id( $prop, $svn );
+ if ( $user_id ) {
+ $data['user_id'] = $user_id;
+ }
+
+ $wpdb->insert( $svn['props_table'], $data );
+ }
+
+ // Output the replacement `<td>`'s
+ $table = new Commits_List_Table( $svn );
+ $table->prepare_items( [ 'revision' => $rev ] );
+ $table->single_row_columns( $table->items[0] );
+} );
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/post.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradminreportspagephp"></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/wporg-trac-watcher/admin/reports-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/wporg-trac-watcher/admin/reports-page.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/reports-page.php 2021-12-13 05:41:15 UTC (rev 11362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,309 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Trac\Watcher;
+
+function display_reports_page( $details ) {
+ global $wpdb;
+ $url = add_query_arg( 'page', $_REQUEST['page'], admin_url( 'admin.php' ) );
+ $what = $_REQUEST['what'] ?? '';
+ $version = $_REQUEST['version'] ?? (WP_CORE_LATEST_RELEASE+0.1);
+ $revisions = $_REQUEST['revisions'] ?? '';
+ $branch = $_REQUEST['branch'] ?? '';
+
+ $url = add_query_arg( 'version', $version, $url );
+ ?>
+ <div class="wrap">
+ <h2>Reports: <?php echo esc_html( $details['name'] ); ?></h2>
+ <ol>
+ <li><a href="<?php echo $url; ?>&what=contributors">All props matching filter</a></li>
+ <li><a href="<?php echo $url; ?>&what=committers">All Committers matching filter</a></li>
+ <li><a href="<?php echo $url; ?>&what=cloud">Cloud of Props matching filter</a></li>
+ <li><a href="<?php echo $url; ?>&what=typos">Props typos matching filter</a></li>
+ <li><a href="<?php echo $url; ?>&what=raw-contributors-and-committers">All Props+Committers matching filter grouped together</a></li>
+
+ <li><a href="<?php echo $url; ?>&what=versions-contributed">Versions which users have contributed to. Ignores filter.</a></li>
+ </ol>
+
+ <form>
+ <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>">
+ <input type="hidden" name="what" value="<?php echo esc_attr( $what ); ?>">
+
+ <?php
+ if ( 'core' === $details['slug'] ) {
+ echo '<select name="version"><option value="">Version</option>';
+ foreach ( get_wordpress_versions() as $v ) {
+ printf(
+ '<option value="%s" %s>%s</option>',
+ esc_attr( $v ),
+ selected( $version ?? '', $v ),
+ esc_html( $v )
+ );
+ }
+ echo '</select>';
+ }
+
+ $branches = get_branches_for( $details );
+ if ( $branches ) {
+ echo '<select name="branch"><option value="">Branch</option>';
+ foreach ( $branches as $b ) {
+ printf(
+ '<option value="%s" %s>%s</option>',
+ esc_attr( $b ),
+ selected( $branch, $b ),
+ esc_html( $b )
+ );
+ }
+ echo '</select>';
+ }
+
+ // Revision range.
+ echo '<input type="text" name="revisions" placeholder="Revs: 1:50 or 1,2,4,5" value="' . esc_attr( $revisions ) .'">';
+
+ echo '<input type="submit" class="button button-primary" value="Filter">';
+
+ echo '</form>';
+
+ $where = '1=1';
+ if ( ! empty( $version ) ) {
+ $where .= $wpdb->prepare( ' AND r.version LIKE %s', $wpdb->esc_like( $version ) . '%' );
+ }
+
+ // Revisions.
+ if ( ! empty( $revisions ) ) {
+ if ( false !== strpos( $revisions, ':' ) || false !== strpos( $revisions, '-' ) ) {
+ $where .= $wpdb->prepare( ' AND r.id BETWEEN %d AND %d', preg_split( '![-:]!', $revisions ) );
+ } elseif ( false !== strpos( $revisions, ',' ) ) {
+ $ids = implode( ',', array_map( 'intval', explode( ',', $revisions ) ) );
+ $where .= " AND r.id IN({$ids})";
+ }
+ }
+
+ switch( $what ) {
+ case 'cloud':
+ // Get all contributors by Name & Count.
+ $details = $wpdb->get_results(
+ "SELECT u.user_nicename, u.display_name, u.ID, count(*) as count
+ FROM {$details['props_table']} p
+ LEFT JOIN {$details['rev_table']} r ON p.revision = r.id
+ JOIN $wpdb->users u ON p.user_id = u.ID
+ WHERE $where
+ GROUP BY p.user_id"
+ );
+
+ $counts = [];
+ foreach ( $details as $r ) {
+ $counts[] = (object)[
+ 'id' => $r->id,
+ 'name' => $r->display_name ?: $r->user_nicename,
+ 'link' => 'https://profiles.wordpress.org/' . $r->user_nicename,
+ 'count' => $r->count
+ ];
+ }
+
+ echo wp_generate_tag_cloud( $counts );
+ break;
+ case 'committers':
+ $details = $wpdb->get_results(
+ "SELECT ifnull(u.user_login,r.author) as user_login, ifnull(u.user_nicename,r.author) as user_nicename, u.display_name, u.ID, count(*) as count
+ FROM {$details['rev_table']} r
+ LEFT JOIN $wpdb->users u ON r.author = u.user_login
+ WHERE $where
+ GROUP BY r.author
+ ORDER BY count DESC"
+ );
+
+ echo '<table class="widefat striped">';
+ echo '<thead><tr><th>Comitter</th><th>Count</th></tr></thead>';
+ foreach ( $details as $c ) {
+ $link = add_query_arg(
+ [
+ 'page' => str_replace( 'reports', 'edit', $_REQUEST['page'] ),
+ 'author' => $c->user_login,
+ ],
+ admin_url( 'admin.php' )
+ );
+
+ printf(
+ '<tr><td><a href="%s">%s</a></td><td><a href="%s">%s</a></td></tr>',
+ 'https://profiles.wordpress.org/' . $c->user_nicename . '/',
+ get_avatar( $c->ID, 32 ) . ' ' . ( $c->display_name ?: $c->user_nicename ),
+ $link,
+ $c->count,
+ );
+ }
+ echo '</table>';
+
+
+ break;
+ case 'contributors':
+ $details = $wpdb->get_results(
+ "SELECT p.prop_name, u.user_nicename, u.display_name, u.ID, count(*) as count,
+ GROUP_CONCAT( p.revision ORDER BY p.revision ASC ) as revisions,
+ IFNULL(p.user_id,p.prop_name) as _groupby
+ FROM {$details['props_table']} p
+ LEFT JOIN {$details['rev_table']} r ON p.revision = r.id
+ LEFT JOIN $wpdb->users u ON p.user_id = u.ID
+ WHERE $where
+ GROUP BY _groupby
+ ORDER BY count DESC"
+ );
+
+ echo '<table class="widefat striped">';
+ echo '<thead><tr><th>Contributor</th><th>Count</th><th>Revisions</th></tr></thead>';
+ foreach ( $details as $c ) {
+ $link = add_query_arg(
+ [
+ 'page' => str_replace( 'reports', 'edit', $_REQUEST['page'] ),
+ 'revisions' => $c->revisions
+ ],
+ admin_url( 'admin.php' )
+ );
+ if ( ! $c->ID ) {
+ printf(
+ '<tr><td>%s</td><td>%s</td><td><a href="%s">%s</a></td></tr>',
+ $c->prop_name,
+ $c->count,
+ $link,
+ '[' . str_replace( ',', '] [', $c->revisions ) . ']'
+ );
+ continue;
+ }
+ printf(
+ '<tr><td><a href="%s">%s</a></td><td>%s</td><td><a href="%s">%s</a></td></tr>',
+ 'https://profiles.wordpress.org/' . $c->user_nicename . '/',
+ get_avatar( $c->ID, 32 ) . ' ' . ($c->display_name ?: $c->user_nicename),
+ $c->count,
+ $link,
+ '[' . str_replace( ',', '] [', $c->revisions ) . ']'
+ );
+ }
+ echo '</table>';
+
+ break;
+ case 'versions-contributed':
+ $details = $wpdb->get_results(
+ "SELECT prop_name, user_id, COUNT(*) as count, group_concat( version ORDER BY version ASC SEPARATOR ', ' ) as versions FROM (
+ SELECT distinct LEFT(version, 3) as version, prop_name, p.user_id
+ FROM {$details['props_table']} p
+ JOIN {$details['rev_table']} r ON p.revision = r.id
+ group by prop_name, version
+ ) a
+ group by prop_name HAVING COUNT(*) > 2
+ ORDER BY COUNT(*) DESC"
+ );
+
+ echo '<table class="widefat striped">';
+ echo '<thead><tr><th>Prop</th><th>Count</th><th>Versions</th></tr></thead>';
+ foreach ( $details as $p ) {
+ $link = add_query_arg(
+ [
+ 'page' => str_replace( 'reports', 'edit', $_REQUEST['page'] ),
+ 's' => $p->prop_name,
+ ],
+ admin_url( 'admin.php' )
+ );
+
+ $profile = $p->prop_name;
+ if ( $p->user_id ) {
+ $u = get_user_by( 'ID', $p->user_id );
+ $profile = "<A href='https://profiles.wordpress.org/{$u->user_nicename}/'>" . ( $u->display_name ?: $u->user_login ) . "</a>";
+ }
+
+ printf(
+ '<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
+ $profile,
+ $p->count,
+ $p->versions
+ );
+ }
+ echo '</table>';
+ case 'typos':
+ $details = $wpdb->get_results(
+ "SELECT u.user_login, u.user_nicename,
+ COUNT( * ) as count,
+ group_concat( distinct p.prop_name SEPARATOR ', ' ) as typos,
+ group_concat( p.revision ORDER BY p.revision ASC ) as revisions
+ FROM {$details['props_table']} p
+ LEFT JOIN {$details['rev_table']} r ON p.revision = r.id
+ LEFT JOIN {$wpdb->users} u ON p.user_id = u.ID
+ WHERE $where AND p.prop_name != u.user_login AND p.prop_name != u.user_nicename AND p.prop_name != u.display_name
+ GROUP BY p.user_id
+ ORDER BY count DESC"
+ );
+
+ echo "<p>Props where what's in the commit doesn't match the user Login, Slug, or Display Name.</p>";
+
+ echo '<table class="widefat striped">';
+ echo '<thead><tr><th>Contributor</th><th>Typos</th><th>Count</th><th>Revisions</th></tr></thead>';
+ foreach ( $details as $c ) {
+ $link = add_query_arg(
+ [
+ 'page' => str_replace( 'reports', 'edit', $_REQUEST['page'] ),
+ 'revisions' => $c->revisions
+ ],
+ admin_url( 'admin.php' )
+ );
+ printf(
+ '<tr><td><a href="%s">%s</a></td><td>%s</td><td>%s</td><td><a href="%s">%s</a></td></tr>',
+ 'https://profiles.wordpress.org/' . $c->user_nicename . '/',
+ $c->display_name ?: $c->user_nicename,
+ $c->typos,
+ $c->count,
+ $link,
+ '[' . str_replace( ',', '] [', $c->revisions ) . ']'
+ );
+ }
+ echo '</table>';
+
+ break;
+ case 'raw-contributors-and-committers':
+ $details = $wpdb->get_results(
+ "SELECT p.prop_name, u.user_nicename, u.display_name, u.ID,
+ IFNULL(p.user_id,p.prop_name) as _groupby
+ FROM {$details['props_table']} p
+ LEFT JOIN {$details['rev_table']} r ON p.revision = r.id
+ LEFT JOIN {$wpdb->users} u ON p.user_id = u.ID
+ WHERE $where
+ GROUP BY _groupby
+ UNION
+ SELECT r.author as prop_name, u.user_nicename, u.display_name, u.ID, u.ID as _groupby
+ FROM {$details['rev_table']} r
+ LEFT JOIN {$wpdb->users} u ON r.author = u.user_login
+ WHERE $where
+ ORDER BY prop_name ASC"
+ );
+
+
+ echo "<p>Props (Contributors + Committers bunched together) designed to be copy-pasted elsewhere. Set gravatar size via adding <a href='$url&size=96'>&size=96</a> to this URL.</p>";
+
+ echo '<table class="widefat striped">';
+ echo '<thead><tr><th>ID</th><th>Name</th><th>DisplayName</th><th>Profile URL</th><th>Gravatar</th><th>GravURL</th></tr></thead>';
+ foreach ( $details as $c ) {
+ $link = add_query_arg(
+ [
+ 'page' => str_replace( 'reports', 'edit', $_REQUEST['page'] ),
+ 'revisions' => $c->revisions
+ ],
+ admin_url( 'admin.php' )
+ );
+ printf(
+ '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
+ $c->ID,
+ $c->prop_name,
+ $c->display_name,
+ make_clickable( $c->user_nicename ? 'https://profile.wordpress.org/' . $c->user_nicename . '/' : '' ),
+ $c->ID ? get_avatar( $c->ID, min( 96, $_GET['size'] ?? 32 ) ) : '',
+ make_clickable( $c->ID ? get_avatar_url( $c->ID, [ 'size' => $_GET['size'] ?? 64 ] ) : '' )
+ );
+ }
+ echo '</table>';
+
+ break;
+ default:
+ echo '<p>Nothing but fishies here today.</p>';
+ break;
+ }
+
+ ?>
+ </div>
+ <?php
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/reports-page.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradmintracwatchcss"></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/wporg-trac-watcher/admin/trac-watch.css</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-trac-watcher/admin/trac-watch.css (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/trac-watch.css 2021-12-13 05:41:15 UTC (rev 11362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,115 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.propstable tr.disabled {
+ opacity: 0.2;
+
+}
+.propstable th.column-message {
+ width: 40%;
+}
+.propstable th.column-props {
+ width: 35%;
+}
+.propstable td.message div.max-height {
+ max-height: 40em;
+ overflow: scroll;
+}
+.propstable td.message ins {
+ color: green;
+ text-decoration: none;
+}
+.propstable td.message del {
+ color: red;
+ text-decoration: none;
+}
+.propstable td.message del.replace {
+ text-decoration: line-through;
+}
+.propstable td.message blockquote {
+ border-left: 0.5em solid #ddd;
+ padding-left: 0.5em;
+ margin-left: 0px;
+}
+.propstable td.props .propslist {
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+ margin-bottom: 1.5em;
+}
+
+.propstable td.props {
+ position: relative;
+}
+.propstable td.props p.actions {
+ position: absolute;
+ bottom: 0;
+ margin-top: -1em;
+ visibility: hidden;
+}
+.propstable td.props:hover p.actions {
+ visibility: visible;
+}
+
+.propstable .tablenav .actions {
+ clear: left;
+}
+
+.propstable img.avatar {
+ margin-right: 5px;
+ border-radius: 50%;
+ vertical-align: text-top;
+ float: left;
+}
+.propstable .user {
+ margin: 5px;
+ padding: 3px;
+ width: 45%;
+ min-height: 2.5em;
+ border: 1px solid lightblue;
+ border-radius: 5px;
+ position: relative;
+}
+.propstable .user.add {
+ width: auto;
+}
+.propstable .user .dashicons-editor-help,
+.propstable .user .dashicons-plus {
+ font-size: 3em;
+ line-height: 1.5;
+ color: red;
+ margin-right: 18px;
+ margin-top: -13px;
+}
+.propstable .user .overlay {
+ display: none;
+ position: absolute;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ width: 20%;
+ background: rgba(0,0,0,0.1);
+}
+.propstable .user:hover .overlay,
+.propstable .user .overlay:hover {
+ display: block;
+}
+
+.propstable .user .overlay .actions,
+.propstable .user .overlay .actions a {
+ position: absolute;
+ right: 0;
+ top: 0;
+ bottom: 0;
+ width: 100%;
+ margin: 0;
+}
+.propstable .user .overlay .actions a {
+ margin: auto;
+ width: 100%;
+ color: white;
+}
+.propstable .user .overlay .actions a:before {
+ width: 100%;
+ height: 100%;
+}
+.propstable .user .overlay .actions {
+ background-color: rgba(123,123,123,0.4);
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/trac-watch.css
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradmintracwatchjs"></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/wporg-trac-watcher/admin/trac-watch.js</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-trac-watcher/admin/trac-watch.js (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/trac-watch.js 2021-12-13 05:41:15 UTC (rev 11362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,90 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+jQuery(document).ready( function($) {
+ var row;
+
+ $('.propstable').on( 'click', '.user .add, .user .edit, .user .delete', function(e) {
+ e.preventDefault();
+
+ var template = $('#propedit-template'),
+ user = $(this).parents( '.user' ),
+ what = $(this).hasClass('add') ? 'add' : 'edit';
+
+ row = user.parents('tr');
+
+ // Reset
+ template.find('input').prop('disabled', '').val( '' );
+
+ // Fill, these could be done at POST time, but easier to just have them in the form.
+ template.find('input[name="revision"]').val( row.data('revision') );
+ template.find('input[name="svn"]').val( row.data('svn') );
+ template.find('input[name="what"]').val( what );
+ template.find('input[name="_wpnonce"]').val( TracWatchData.edit_nonce );
+
+ // Maybe hide the delete button.
+ template.find('button.delete').toggle( !! user.data('prop') );
+
+ if ( user.data('prop' ) ) {
+ template.find('input[name="prop_name"], input[name="prop_name_orig"]').val( user.data('prop') );
+ template.find('input[name="user_id"]').val( user.data('user') );
+ } else if ( 'add' === what ) {
+ template.find('input[name="prop_name"], input[name="prop_name_orig"]').val( window.getSelection().toString() );
+ }
+
+ tb_show( '', '#TB_inline?height=350&width=500&inlineId=propedit-template&modal=true' );
+ } );
+
+ $(document).on( 'click', '#TB_ajaxContent button.save, #TB_ajaxContent button.delete', function() {
+ var form = $('#TB_ajaxContent form');
+ if ( $(this).hasClass('delete') ) {
+ form.find('input[name="what"]').val( 'delete' );
+ }
+
+ // Fetch the form before we disable it.
+ var payload = form.serialize();
+
+ // Disable the form during HTTP request.
+ form.find('input').prop('disabled', 'disabled' );
+
+ form.parent().css( 'opacity', 0.3 );
+
+ $.post( 'admin-post.php?action=svn_save', payload, function( data ) {
+
+ if ( data ) {
+ row.html( data );
+ } else {
+ alert( 'Something went wrong.. Better check that..' );
+ }
+
+ row = false;
+ tb_remove();
+ } );
+ } );
+
+ $(document).on( 'click', '#TB_ajaxContent button.cancel', function() {
+ row = false;
+ tb_remove();
+ } );
+
+ $('.propstable').on( 'click', '.actions .reparse', function(e) {
+ e.preventDefault();
+
+ var row = $(this).parents('tr');
+ row.addClass( 'disabled' );
+
+ var payload = {
+ svn: row.data('svn'),
+ revision: row.data('revision'),
+ _wpnonce: TracWatchData.reparse_nonce,
+ };
+
+ $.post( 'admin-post.php?action=svn_reparse', payload, function( data ) {
+
+ if ( data ) {
+ row.html( data );
+ } else {
+ alert( 'Something went wrong.. Better check that..' );
+ }
+
+ row.removeClass( 'disabled' );
+ } );
+ } );
+} );
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcheradminuiphp"></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/wporg-trac-watcher/admin/ui.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-trac-watcher/admin/ui.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/ui.php 2021-12-13 05:41:15 UTC (rev 11362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,148 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Trac\Watcher;
+
+/*
+ * This is a suuuuper basic admin UI, that's not actually as minimal as I intended...
+ */
+
+include __DIR__ . '/list-table.php';
+include __DIR__ . '/post.php';
+
+add_action( 'admin_menu', function() {
+ $svns = SVN\get_svns();
+
+ // Limit the display to just this make sites revisions if possible.
+ if (
+ is_multisite() &&
+ ( $path = trim( parse_url( home_url('/'), PHP_URL_PATH ), '/' ) ) &&
+ isset( $svns[ $path ] )
+ ) {
+ $svns = [ $path => $svns[ $path ] ];
+ }
+
+ foreach ( $svns as $slug => $details ) {
+ $name = sprintf( "%s Props", $details['name'] );
+ $hook = add_menu_page(
+ $name,
+ $name,
+ 'edit_posts',
+ 'props-edit-' . $slug,
+ function() use ( $details ) {
+ display_list_table( $details );
+ }
+ );
+ add_action( 'load-' . $hook, __NAMESPACE__ . '\load_page' );
+
+ $hook = add_submenu_page(
+ 'props-edit-' . $slug,
+ 'Reports', 'Reports',
+ 'edit_posts',
+ 'props-reports-' . $slug,
+ function() use ( $details ) {
+ include __DIR__ . '/reports-page.php';
+ display_reports_page( $details );
+ }
+ );
+ add_action( 'load-' . $hook, __NAMESPACE__ . '\load_page' );
+ }
+
+} );
+
+function load_page() {
+ add_screen_option(
+ 'per_page',
+ [
+ 'default' => 100,
+ ]
+ );
+
+ // Run the import upon loading the page if it hasn't run recently.
+ if ( wp_next_scheduled( 'import_revisions_from_svn' ) < time() + 5*MINUTE_IN_SECONDS ) {
+ ob_start();
+ do_action( 'import_revisions_from_svn' );
+ ob_end_clean();
+ }
+
+ wp_enqueue_script( 'trac-watch', plugins_url( 'admin/trac-watch.js', PLUGIN ), [ 'jquery', 'thickbox' ], filemtime( __DIR__ . '/trac-watch.js' ) );
+ wp_enqueue_style( 'trac-watch', plugins_url( 'admin/trac-watch.css', PLUGIN ), [ 'thickbox' ], filemtime( __DIR__ . '/trac-watch.css' ) );
+
+ wp_localize_script(
+ 'trac-watch',
+ 'TracWatchData',
+ [
+ 'edit_nonce' => wp_create_nonce( 'edit_svn_prop' ),
+ 'reparse_nonce' => wp_create_nonce( 'reparse_svn' ),
+ ]
+ );
+}
+
+function display_list_table( $details ) {
+ $table = new Commits_List_Table( $details );
+ $table->prepare_items( $_REQUEST );
+ ?>
+ <div class="wrap propstable">
+ <h2><?php echo esc_html( $details['name'] ); ?> Props</h2>
+ <form method="GET" action="<?php echo esc_url( add_query_arg() ); ?>">
+ <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
+ <?php $table->search_box( 'Search', 's' ); ?>
+ <?php $table->display(); ?>
+ </form>
+ </div>
+
+ <div style="display:none" id="propedit-template">
+ <h3>Edit Prop</h3>
+ <form>
+ <input type="hidden" name="prop_name_orig" value="" />
+ <input type="hidden" name="svn" value="" />
+ <input type="hidden" name="revision" value="" />
+ <input type="hidden" name="what" value="" />
+ <input type="hidden" name="_wpnonce" value="" />
+ <label>
+ Name in Commit message:<br>
+ <input type="text" class="widefat" name="prop_name" value="" />
+ </label>
+ <br>
+ <label>
+ User ID, login, nicename, or profile URL:<br>
+ <input type="text" class="widefat" name="user_id" value="" />
+ </label>
+ <p>
+ <button type="button" class="save button button-primary">Save</button>
+ <button type="button" class="cancel button button-secondary">Cancel</button>
+ <button type="button" class="delete button button-secondary button-link-delete">Delete</button>
+ </p>
+ </form>
+ <p>
+ <em>Adding a missing prop? Fill out at least the first field..</em><br>
+ <em>Typo made? Leave the Name in the commit as-is, just fill in the correct user. Future typo's will be then understand.</em><br>
+ <em>Invalid prop? Prop Parser fail? Hit delete for required matches.</em>
+ </p>
+ </div>
+ <?php
+}
+
+function get_wordpress_versions() {
+ $versions = [];
+ if ( function_exists( 'wporg_get_secure_versions' ) ) {
+ $versions = array_map( 'floatval', wporg_get_secure_versions() );
+ }
+ if ( defined( 'WP_CORE_LATEST_RELEASE' ) ) {
+ array_unshift( $versions, ((float)WP_CORE_LATEST_RELEASE)+0.1 );
+ }
+
+ return array_map( function( $v ) {
+ return sprintf( '%.1f', $v );
+ }, $versions );
+}
+
+function get_branches_for( $svn ) {
+ global $wpdb;
+
+ $branches = get_transient( $svn['slug'] . '_branches' );
+ if ( ! $branches ) {
+ $branches = $wpdb->get_col( 'SELECT branch FROM ' . $svn['rev_table'] . ' WHERE branch NOT LIKE "tag%" GROUP BY branch ORDER BY max(date) > DATE_SUB( NOW(), INTERVAL 1 YEAR ) DESC, branch DESC' );
+ set_transient( $svn['slug'] . '_branches', $branches, DAY_IN_SECONDS );
+ }
+
+ return array_filter( (array)$branches );
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/ui.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatcherpropsphp"></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/wporg-trac-watcher/props.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-trac-watcher/props.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/props.php 2021-12-13 05:41:15 UTC (rev 11362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,276 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Trac\Watcher\Props;
+use function WordPressdotorg\Trac\Watcher\SVN\get_svns;
+
+function from_log( $log ) {
+ $props = '\s*(?P<props>.+?)';
+ $props_greedy = '\s*(?P<props>.+)';
+ $props_short = '\s*(?P<props>\S{4,}((\s*and)?\s+\S{4,})?)'; // One or two words 4char+
+ $props_one = '\s*(?P<props>\S{4,})'; // Single prop, 4char+
+ $sol = '(^|[.]|\pP)\s*'; // Start of line, actual start of line or sentence start.
+ $real_sol = '(^|[.])\s*';
+ $eol = '([.]([^.]|$)|\pP|$)'; // EOL that's a full stop, new line, or randon punctuation.
+ $real_eol = '([.][^.]|[.]?$)'; // EOL that's actually full stop or new line.
+
+ // These matchers are regular expressions, put inside `#..#im`
+ $matchers = [
+ // These matchers apply in order, once one matches that's the parser used for the commit.
+ 'once' => [
+ "^props(?! to ) {$props_greedy}.?$", // Super basic initial primary matcher, trumps even the next one.
+ "{$real_sol}props(?! to ) {$props_greedy}{$real_eol}", // Primary matcher, "Props abc, def". Excludes "props to "
+ "([,.] )props{$props}([,.] )", // Simple inline props matcher, ". props abc." / ", props abc, fixes ..."
+ "{$sol}props([:]| to ) {$props_greedy}{$eol}",
+ "([0-9]|\pP)\s+props([:]|\s+to)? {$props_one}( in .+)?(,|{$eol})",
+ "{$sol}(h/t|hat tip:) {$props_short}{$eol}",
+
+ // These are starting to get real old... like three-digit core commit old..
+ "\S\sprops([:]|\s+to)? {$props_short}{$eol}", // Inline props
+ "\scredit(?! card)([:]|\sto)? {$props_short}", // Credit: ... or Credit to ...
+ "\s(diff|patch|patches|fix|fixes) from {$props_short}{$eol}", // Fixes from Ryan
+ "\smad props to {$props_short}{$eol}", // mad props to johny
+ "\sfrom {$props_short}$", // Super last-ditch effort
+ ],
+
+ // These matchers apply no matter which ones above have matched.
+ // They're intended to catch additional inline mentions.
+ 'multiple' => [
+ "\sunprops {$props_one}",
+ "{$sol}(dev)?reviewed[- ]by {$props}{$eol}",
+ "\sthanks {$props_one}",
+ ]
+ ];
+
+ // Cleanup the log
+
+ // Remove anything non-printable.
+ $log = preg_replace( "![^[:print:]\n]!", '', $log );
+
+ // Replace all whitespace with standard spaces.
+ $log = preg_replace( '![\pZ]+$!u', ' ', $log );
+
+ // remove any ticket references and other irrelevant things.
+ $log = preg_replace( '!(fixes|fixed|see|closes|merges):?\s*([[]\d{3,}[]]|r\d{2,}|#[a-z]*\d{2,}|https?://\S+)( for (trunk|[0-9.]+))?!i', '', $log ); // fixes [1234] for 5.6, closes #1234, see #meta12345
+ $log = preg_replace( '!(#\d+|[[]\d+[]])!', '', $log ); // Tickets, Revisions not matched above
+ $log = preg_replace( '!merges\s+\S+!i', '', $log );
+ $log = preg_replace( '![ ]{2,}!', ' ', $log );
+
+ // Trim out any URLs.
+ $log = preg_replace( '!https?://\S+!i', '', $log );
+ $log = trim( $log, ",. \n\t" );
+
+ // Fetch any lines related.
+ $data = [];
+ foreach ( $matchers['once'] as $regex ) {
+ if ( preg_match_all( '#' . $regex . '#im', $log, $m ) ) {
+ $data = array_merge( $data, $m['props'] );
+ break;
+ }
+ }
+ foreach ( $matchers['multiple'] as $regex ) {
+ if ( preg_match_all( '#' . $regex . '#im', $log, $m ) ) {
+ $data = array_merge( $data, $m['props'] );
+ }
+ }
+
+ if ( ! $data ) {
+ return [];
+ }
+
+ $users = [];
+ foreach ( $data as $d ) {
+ // Trim out any 'for ...' & '(for...)' & '( fo ...)'
+ $d = preg_replace( '!\b[(]?for? (now|.{4,}|[0-9.]{2,})([.]|$)!is', '', $d );
+
+ // Trim out any '$user with...'
+ $d = preg_replace( '!^(.{5,})\s*with .{4,}([.][^.]|$)!is', '$1', $d );
+
+ // Trim any odd whitespace and punctuation.
+ $d = trim( $d, ",. \n\t" );
+
+ // Reduce any " and " down to a comma list.
+ $d = preg_replace( '!(\w) and !i', '$1, ', $d );
+
+ // Commas or Slashes? Assume separated users.
+ if ( false !== strpos( $d, ',' ) || false !== strpos( $d, '/' ) ) {
+ $users = array_merge(
+ $users,
+ preg_split( '![,/]\s*!', $d )
+ );
+ }
+ // Words prefixed by @? User list.
+ else if ( preg_match( '!^(@(\S+\s*))*$!u', $d ) ) {
+ $users = array_merge(
+ $users,
+ // We'll trim the @ off later.
+ preg_split( '!\s+!u', $d )
+ );
+ }
+ // no spaces? Just a username?
+ else if ( false === strpos( $d, ' ' ) ) {
+ $users[] = $d;
+ }
+ else {
+ // At this point, we have to decide if this is a list of "user user user" or "user with spaces"
+
+ $user_list = preg_split( '!\s+!u', $d );
+
+ // If it's only 2 words, and we can find a matching user, trust it.
+ if (
+ 2 == count( $user_list ) &&
+ preg_match( '!^[a-z ]+$!i', $d ) &&
+ find_user_id( $d )
+ ) {
+ $users[] = $d;
+ } else {
+ // Multiple spaces is more likely a list of users.
+ $users = array_merge(
+ $users,
+ $user_list
+ );
+ }
+ }
+
+ }
+
+ // Cleanup users.
+ $users = array_map(
+ function( $u ) {
+ // Trim leading @
+ $u = ltrim( $u, '@' );
+
+ // Trim leading words.. these should never be here, but sometimes slip in with duplicate `props a props b`
+ $words = [
+ 'and', 'props',
+ ];
+ $u = preg_replace( '!((' . implode( '|', $words ) . ')\s+)*!i', '', $u );
+
+ // Trim trailing punctuation (if it starts without punctuation)
+ $u = preg_replace( '!^([a-z0-9].{4,})[\pP\s]+$!iu', '$1', $u );
+
+ // Does it start with a expected character, but have space followed by rand punctuation?
+ $u = preg_replace( '!^([a-z0-9]\S+)\s\pP.*$!i', '$1', $u );
+
+ return $u;
+ },
+ $users
+ );
+
+ // Filter the users.
+ $users = array_filter(
+ $users,
+ function( $u ) use( $users ) {
+ static $blacklist = [
+ 'list', 'for', 'fo', 'in', 'to', 'and', 'as', 'an', 'up', 'and', '&',
+ 'contributors', 'others',
+ 'et al', 'et alii', 'via',
+ 'fixes', 'fix', 'see', 'closes', 'props',
+ '`public`', // r31078
+ 'Team', // r31975
+ 'Gandalf', // r31975
+ 'dependabot', // r48501
+ 'everyone-in-the-core-updates-channel', // r48678
+ ];
+
+ if ( in_array( $u, $blacklist, true ) ) {
+ return false;
+ }
+
+ // Exclude purely numeric users.
+ // There exist a few, but they're so far between.
+ if ( is_numeric( $u ) ) {
+ return false;
+ }
+
+ // Ignore super-short names, probably mis-match.
+ if ( strlen( $u ) < 3 ) {
+ return false;
+ }
+
+ // Ignore pure punctuation.
+ if ( preg_match( '!^[\pP]+$!u', $u ) ) {
+ return false;
+ }
+
+ // If a user has more than 2 spaces, lets consider that invalid?
+ if ( substr_count( $u, ' ' ) > 2 ) {
+ return false;
+ }
+
+ // If the user is the start of another user, skip it.
+ // ie. [ 'john', 'john.smith' ] => [ 'john.smith' ]
+ foreach ( $users as $u2 ) {
+ if (
+ $u != $u2 &&
+ substr( $u2, 0, strlen( $u ) ) === $u
+ ) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ );
+
+ return array_unique( $users );
+}
+
+/**
+ * Find a user ID for the user being prop'd.
+ */
+function find_user_id( $prop, $svn = array() ) {
+ global $wpdb;
+
+ // Profile URL - This is primarily used via the Admin UI to assign ownership of a prop.
+ if (
+ preg_match( '!^https?://profiles.wordpress.org/(?P<user>[^/]+)/?$!', $user, $m ) &&
+ ( $user = get_user_by( 'slug', $m['user'] ) )
+ ) {
+ return $user->ID;
+ }
+
+ // User login
+ if ( $user = get_user_by( 'login', $prop ) ) {
+ return $user->ID;
+ }
+
+ // User nicename
+ if ( $user = get_user_by( 'slug', $prop ) ) {
+ return $user->ID;
+ }
+
+ // Email
+ if (
+ is_email( $prop ) &&
+ ( $user = get_user_by( 'email', $prop ) )
+ ) {
+ return $user->ID;
+ }
+
+ // User ID?
+ if (
+ is_numeric( $prop ) &&
+ ( $user = get_user_by( 'id', $prop ) )
+ ) {
+ return $user->ID;
+ }
+
+ // previous props?
+ // This works great to catch typo's, correct it manually once and it'll be caught next time.
+ foreach ( get_svns() as $svn ) {
+ $props_table = ['props_table'] ?? false;
+ if (
+ $props_table &&
+ ( $id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$props_table} WHERE prop_name = %s LIMIT 1", $prop ) ) )
+ ) {
+ return (int) $id;
+ }
+ }
+
+ // GitHub?
+ $github = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM wporg_github_users WHERE github_user = %s LIMIt 1", $prop ) );
+ if ( $github ) {
+ return (int) $github;
+ }
+
+ return false;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/props.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatchersvnphp"></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/wporg-trac-watcher/svn.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-trac-watcher/svn.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/svn.php 2021-12-13 05:41:15 UTC (rev 11362)
</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\Trac\Watcher\SVN;
+use function WordPressdotorg\Trac\Watcher\Props\from_log as props_from_log;
+use function WordPressdotorg\Trac\Watcher\Props\find_user_id;
+
+const MAX_REVISIONS = 250;
+
+add_action( 'import_revisions_from_svn', function() {
+ foreach ( get_svns() as $svn ) {
+ import_revisions( $svn );
+ }
+} );
+
+function get_svns() {
+ return [
+ 'core' => [
+ 'slug' => 'core',
+ 'name' => 'Core',
+ 'url' => 'https://develop.svn.wordpress.org',
+ 'trac' => 'https://core.trac.wordpress.org',
+ 'rev_table' => 'trac_core_revisions',
+ 'props_table' => 'trac_core_props',
+ ],
+ 'meta' => [
+ 'slug' => 'meta',
+ 'name' => 'Meta',
+ 'url' => 'https://meta.svn.wordpress.org',
+ 'trac' => 'https://meta.trac.wordpress.org',
+ 'rev_table' => 'trac_meta_revisions',
+ 'props_table' => 'trac_meta_props',
+ ]
+ ];
+}
+
+function import_revisions( $svn ) {
+ global $wpdb;
+
+ $svn_url = $svn['url'];
+ $slug = $svn['slug'];
+ $db_table = $svn['rev_table'];
+ $props_table = $svn['props_table'] ?? false;
+
+ $last_revision = $wpdb->get_var( "SELECT max(id) FROM {$db_table}" );
+ if ( ! is_numeric( $last_revision ) ) {
+ trigger_error( "Can't find max row for {$db_table} to import {$svn_url} revisions.", E_USER_WARNING );
+ return false;
+ }
+
+ $command = sprintf(
+ 'svn log %s -r %d:HEAD --limit %d --xml -v 2>/dev/null',
+ esc_url( $svn_url ),
+ (int) $last_revision,
+ (int) MAX_REVISIONS
+ );
+
+ $xml_internal_errors = libxml_use_internal_errors( true );
+ $xml = simplexml_load_string( shell_exec( $command ) );
+ libxml_use_internal_errors( $xml_internal_errors );
+
+ if ( ! $xml ) {
+ // Malformed XML, happens when SVN hits an error prior to finishing output (or the revision range is invalid)
+ return false;
+ }
+
+ $processed = 0;
+ foreach ( $xml as $change ) {
+ $id = (int) $change->attributes()['revision'];
+ $author = trim( (string) $change->author );
+ $msg = trim( (string) $change->msg );
+ $date = gmdate( 'Y-m-d H:i:s', strtotime( $change->date ) );
+
+ // No need to re-process the last revision.
+ if ( $id <= $last_revision ) {
+ continue;
+ }
+
+ echo "Importing {$id} \n";
+
+ $paths = (array) $change->paths->path;
+ $paths = array_filter( $paths, 'is_string' ); // hacky, to remove attributes array, leaving just paths.
+
+ $branch = get_branch_from_paths( $paths );
+
+ // Short summary - First line, first sentence, max 32 words.
+ $summary = explode( "\n", $msg )[0];
+ if ( $pos = strpos( $summary, '. ' ) ) {
+ $summary = substr( $summary, 0, $pos + 1 );
+ }
+ $summary = wp_trim_words( $summary, 32 );
+
+ $data = [
+ 'id' => $id,
+ 'author' => $author,
+ 'summary' => $summary,
+ 'message' => $msg,
+ 'date' => $date,
+ 'branch' => $branch,
+ ];
+
+ // Fetch the version for core...
+ if ( 'core' === $slug ) {
+ $data['version'] = get_wp_version( $svn_url, $branch, $id );
+ }
+
+ $wpdb->insert( $db_table, $data );
+
+ if ( $props_table ) {
+ // Look for the props in the commit.
+ $props = props_from_log( $msg );
+
+ foreach ( $props as $prop ) {
+
+ $data = [
+ 'revision' => $id,
+ 'prop_name' => $prop,
+ ];
+
+ $user_id = find_user_id( $prop, $svn );
+ if ( $user_id ) {
+ $data['user_id'] = $user_id;
+ }
+
+ $wpdb->insert( $props_table, $data );
+ }
+ }
+
+ $processed++;
+ }
+
+ return $processed;
+}
+
+/**
+ * Return the first branch related to the file paths given.
+ */
+function get_branch_from_paths( array $files ) {
+ foreach ( $files as $file ) {
+ if ( '/trunk' === substr( $file, 0, 6 ) ) {
+ return 'trunk';
+ }
+
+ if ( '/branches/' === substr( $file, 0, 10 ) ) {
+ $pos = max( 0, strpos( $file, '/', 12 ) - 1 ) ?: strlen( $file );
+ return substr( $file, 1, $pos );
+ }
+
+ if ( '/tags/' === substr( $file, 0, 6 ) ) {
+ $pos = max( 0, strpos( $file, '/', 7 ) - 1 ) ?: strlen( $file );
+ return substr( $file, 1, $pos );
+ }
+ }
+
+ return false;
+}
+
+function get_wp_version( $svn_url, $branch, $revision = 'HEAD' ) {
+ $files = [
+ 'src/wp-includes/version.php',
+ 'wp-includes/version.php',
+ 'wp-includes/vars.php',
+ 'b2-include/b2vars.php',
+ ];
+
+ foreach ( $files as $f ) {
+ $url = "{$svn_url}/{$branch}/{$f}";
+ $output = shell_exec( sprintf(
+ 'svn cat %s@%d 2>/dev/null',
+ esc_url( $url ),
+ (int) $revision
+ ) );
+
+ // Use regex, because it's simpler than 32 lines of PHP Tokeniser.
+ if ( $output && preg_match( '!\$(wp|b2)_version\s*=\s*([\'"])(?P<version>.*?)\\2!i', $output, $m ) ) {
+ return $m['version'];
+ }
+
+ }
+
+ return false;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/svn.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatchertracwatchphp"></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/wporg-trac-watcher/trac-watch.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-trac-watcher/trac-watch.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/trac-watch.php 2021-12-13 05:41:15 UTC (rev 11362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,98 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Trac\Watcher;
+/**
+ * Plugin Name: WordPress.org Trac & SVN Watcher.
+ */
+
+define( 'PLUGIN', __FILE__ );
+
+include_once __DIR__ . '/trac.php';
+include_once __DIR__ . '/svn.php';
+include_once __DIR__ . '/props.php';
+
+// Must be earlier than admin_init for admin_menu
+add_action( 'init', function() {
+ if ( defined( 'WP_ADMIN' ) && WP_ADMIN ) {
+ include_once __DIR__ . '/admin/ui.php';
+ }
+} );
+
+add_filter( 'cron_schedules', function( $schedules ) {
+ $schedules['10_minutes'] = [
+ 'interval' => 600,
+ 'display' => 'Every Ten Minutes'
+ ];
+ return $schedules;
+} );
+
+add_action( 'admin_init', function() {
+ // Queue the jobs on blog_id 1 only (wordpress.org/)
+ if ( 1 !== get_current_blog_id() ) {
+ return;
+ }
+
+ if ( ! wp_next_scheduled( 'import_revisions_from_svn' ) ) {
+ wp_schedule_event( time(), '10_minutes', 'import_revisions_from_svn' );
+ }
+
+ if ( ! wp_next_scheduled( 'import_trac_feeds' ) ) {
+ wp_schedule_event( time(), '10_minutes', 'import_trac_feeds' );
+ }
+} );
+
+/**
+ * Database tables for if this is used outside of wordpress.org
+ */
+register_activation_hook( __FILE__, __NAMESPACE__ . '\create_tables' );
+function create_tables() {
+ $trac_table = "CREATE TABLE IF NOT EXISTS `%s` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `description` longtext NOT NULL,
+ `summary` longtext NOT NULL,
+ `category` varchar(50) NOT NULL,
+ `username` varchar(50) NOT NULL,
+ `link` varchar(255) NOT NULL,
+ `pubdate` datetime NOT NULL,
+ `md5_id` varchar(50) DEFAULT NULL,
+ `title` varchar(255) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `md5_id` (`md5_id`),
+ KEY `category` (`category`),
+ KEY `username` (`username`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
+
+ $revisions_table = "CREATE TABLE IF NOT EXISTS `%s` (
+ `id` int(11) unsigned NOT NULL,
+ `author` varchar(255) NOT NULL DEFAULT '',
+ `date` datetime NOT NULL,
+ `summary` tinytext NOT NULL,
+ `message` text DEFAULT NULL,
+ `branch` varchar(255) NOT NULL DEFAULT '',
+ `version` varchar(32) NOT NULL DEFAULT '',
+ PRIMARY KEY (`id`),
+ KEY `author` (`author`),
+ KEY `branch` (`branch`),
+ KEY `version` (`version`(3))
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
+
+ $props_table = "CREATE TABLE IF NOT EXISTS `%s` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `revision` int(11) NOT NULL,
+ `user_id` bigint(20) DEFAULT NULL,
+ `prop_name` varchar(128) NOT NULL DEFAULT '',
+ PRIMARY KEY (`id`),
+ KEY `user_id` (`user_id`),
+ KEY `revision` (`revision`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
+
+ return; // TODO
+ foreach ( SVN\get_svns() as $prefix => $info ) {
+ $wpdb->query( sprintf( $trac_table, 'trac_' . $prefix ) );
+ if ( ! empty( $info['rev_table'] ) ) {
+ $wpdb->query( sprintf( $revisions_table, $info['rev_table'] ) );
+ }
+ if ( ! empty( $info['props_table'] ) ) {
+ $wpdb->query( sprintf( $props_table, $info['props_table'] ) );
+ }
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/trac-watch.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgtracwatchertracphp"></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/wporg-trac-watcher/trac.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-trac-watcher/trac.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/trac.php 2021-12-13 05:41:15 UTC (rev 11362)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,23 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Trac\Watcher\Trac;
+
+add_action( 'import_trac_feeds', function() {
+ // Trac RSS feed import from profiles.w.org to be moved here.
+} );
+
+function format_trac_markup( $message ) {
+ $message = esc_html( $message );
+ $message = preg_replace( '!`(.*?)`!i', '<code>$1</code>', $message );
+ $message = preg_replace( '!{{{(.*?)}}}!sm', '<code>$1</code>', $message );
+
+ $message = preg_replace( '!\[([^] ]+) ([^]]+)\]!i', '<a href="$1">$2</a>', $message );
+
+ // Escape shortcodes, but that takes out changesets..
+ // $message = str_replace( [ '[', ']'], [ '[[', ']]' ], $message );
+
+ // Might need to disable this, or escape more things prior to it.
+ $message = apply_filters( 'the_content', $message );
+ $message = make_clickable( $message );
+
+ return $message;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/trac.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>