Making WordPress.org

Changeset 11369


Ignore:
Timestamp:
12/14/2021 04:39:01 AM (5 years ago)
Author:
dd32
Message:

SVN Watcher: Reports: Avoid some PHP Notices, and compress the versions contributed to table. Instead of showing 3.0, 3.1, .... 5.8 just show 3.0-5.8.

See #5978.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/list-table.php

    r11362 r11369  
    5757
    5858                if ( ! empty( $args['version'] ) ) {
    59                         $where .= $wpdb->prepare( ' AND version LIKE %s', $wpdb->esc_like( $args['version'] ) . '%' );
     59                        $where .= $wpdb->prepare( ' AND r.version LIKE %s', $wpdb->esc_like( $args['version'] ) . '%' );
    6060                }
    6161                if ( ! empty( $args['branch'] ) ) {
    62                         $where .= $wpdb->prepare( ' AND branch LIKE %s', $wpdb->esc_like( $args['branch'] ) );
    63                 }
    64 
    65                 if ( ! empty( $args['revisions'] ) && preg_match( '!(?P<start>\d+):(?P<end>\d+)!', $args['revisions'], $m ) ) {
    66                         $where .= $wpdb->prepare( ' AND id BETWEEN %d AND %d', $m['start'], $m['end'] );
     62                        $where .= $wpdb->prepare( ' AND r.branch LIKE %s', $wpdb->esc_like( $args['branch'] ) );
     63                }
     64
     65                if ( ! empty( $args['revisions'] ) && preg_match( '!(?P<start>\d+)[:-](?P<end>(HEAD|\d+))!', $args['revisions'], $m ) ) {
     66                        if ( 'HEAD' === $m['end'] ) {
     67                                $where .= $wpdb->prepare( ' AND r.id > %d', $m['start'] );
     68                        } else {
     69                                $where .= $wpdb->prepare( ' AND r.id BETWEEN %d AND %d', $m['start'], $m['end'] );
     70                        }
    6771                }
    6872                if ( ! empty( $args['revisions'] ) && preg_match( '!^[\d,]+$!', $args['revisions'], $m ) ) {
    6973                        $ids = implode(',', array_map( 'intval', explode( ',', $args['revisions'] ) ) );
    70                         $where .= " AND id IN({$ids})";
     74                        $where .= " AND r.id IN({$ids})";
    7175                }
    7276
    7377                if ( ! empty( $args['author'] ) ) {
    74                         $where .= $wpdb->prepare( ' AND author = %s', $args['author'] );
     78                        $where .= $wpdb->prepare( ' AND r.author = %s', $args['author'] );
    7579                }
    7680
    … …  
    8084                        }
    8185                        $where .= $wpdb->prepare(
    82                                 ' AND ( message LIKE %s OR p.prop_name LIKE %s )',
     86                                ' AND ( r.message LIKE %s OR p.prop_name LIKE %s )',
    8387                                '%' . $wpdb->esc_like( $args['s'] ) . '%',
    8488                                '%' . $wpdb->esc_like( $args['s'] ) . '%',
    8589                        );
    8690                }
    87 
    88         //              $where .= ' AND r.id IN( 46290, 51195, 50933, 50810 )';
    8991
    9092                $this->items = $wpdb->get_results(
    … …  
    117119                $revisions = implode( ',', array_map( 'intval', $revisions ) );
    118120
    119                 $props_list = $wpdb->get_results( $wpdb->prepare(
     121                $props_list = $wpdb->get_results(
    120122                        "SELECT revision,user_id,prop_name
    121123                        FROM {$props_table}
    122124                        WHERE revision IN({$revisions})
    123                         ORDER BY LENGTH(prop_name) DESC
    124                         "
    125                 ) );
     125                        ORDER BY LENGTH(prop_name) DESC"
     126                );
    126127
    127128                foreach ( $this->items as $i => $details ) {
    … …  
    215216                $views = [
    216217                        'all' => '<a href="' . esc_url( $url ) . '">All</a>',
    217                         'unknown-props' => '<a href="' . esc_url( add_query_arg( [ 'unknown-props' => 1 ], $url ) ) . '">Unknown Props</a>',
     218                        'unknown-props' => '<a href="' . esc_url( add_query_arg( 'unknown-props', 1, $url ) ) . '">Unknown Props</a>',
    218219                ];
    219220
    220221                if ( defined( 'WP_CORE_LATEST_RELEASE' ) && 'core' === $this->svn['slug'] ) {
    221222                        $v = sprintf( '%.1f', ((float)WP_CORE_LATEST_RELEASE+0.1) );
    222                         $views['commits-to-trunk'] = '<a href="' . esc_url( add_query_arg( [ 'version' => $v ], $url ) ) . '">Commits to ' . $v .'</a>';
     223                        $views['commits-to-trunk'] = '<a href="' . esc_url( add_query_arg( 'version', $v, $url ) ) . '">Commits to ' . $v .'</a>';
    223224                }
    224225
    … …  
    345346                                                '<span class="user" data-prop="%s" data-user="%s">',
    346347                                                esc_attr( $prop ),
    347                                                 esc_attr( $user->user_login )
     348                                                esc_attr( $user->user_login ?? '' )
    348349                                        );
    349350                                        if ( $user ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/reports-page.php

    r11367 r11369  
    66        $url       = add_query_arg( 'page', $_REQUEST['page'], admin_url( 'admin.php' ) );
    77        $what      = $_REQUEST['what'] ?? '';
    8         $version   = $_REQUEST['version'] ?? (WP_CORE_LATEST_RELEASE+0.1);
     8        $version   = $_REQUEST['version'] ?? null;
    99        $revisions = $_REQUEST['revisions'] ?? '';
    1010        $branch    = $_REQUEST['branch'] ?? '';
     11        $is_core   = ( 'core' === $details['slug'] );
     12
     13        // Default to the latest version for core.
     14        if ( $is_core && is_null( $version ) ) {
     15                $version = sprintf( '%.1f', WP_CORE_LATEST_RELEASE + 0.1 );
     16        }
    1117
    1218        $url = add_query_arg( 'version', $version, $url );
    … …  
    2127                        <li><a href="<?php echo $url; ?>&what=raw-contributors-and-committers">All Props+Committers matching filter grouped together</a></li>
    2228                       
     29                        <?php if ( $is_core ) { ?>
    2330                        <li><a href="<?php echo $url; ?>&what=versions-contributed">Versions which users have contributed to. Ignores filter.</a></li>
     31                        <?php } ?>
    2432                </ol>
    2533
    … …  
    2937
    3038                <?php
    31                 if ( 'core' === $details['slug'] ) {
     39                if ( $is_core ) {
    3240                        echo '<select name="version"><option value="">Version</option>';
    3341                        foreach ( get_wordpress_versions() as $v ) {
    … …  
    5765
    5866                // Revision range.
    59                 echo '<input type="text" name="revisions" placeholder="Revs: 1:50 or 1,2,4,5" value="' . esc_attr( $revisions ) .'">';
     67                echo '<input type="text" name="revisions" placeholder="Revs: 1:HEAD or 1,2,4,5" value="' . esc_attr( $revisions ) .'">';
    6068
    6169                echo '<input type="submit" class="button button-primary" value="Filter">';
    … …  
    7078                // Revisions.
    7179                if ( ! empty( $revisions ) ) {
    72                         if ( false !== strpos( $revisions, ':' ) || false !== strpos( $revisions, '-' )  ) {
    73                                 $where .= $wpdb->prepare( ' AND r.id BETWEEN %d AND %d', preg_split( '![-:]!', $revisions ) );
     80                        if (  preg_match( '!(?P<start>\d+)[:-](?P<end>(HEAD|\d+))!', $args['revisions'], $m ) ) {
     81                                if ( 'HEAD' === $m['end'] ) {
     82                                        $where .= $wpdb->prepare( ' AND r.id > %d', $m['start'] );
     83                                } else {
     84                                        $where .= $wpdb->prepare( ' AND r.id BETWEEN %d AND %d', $m['start'], $m['end'] );
     85                                }
    7486                        } elseif ( false !== strpos( $revisions, ',' ) ) {
    7587                                $ids = implode( ',', array_map( 'intval', explode( ',', $revisions ) ) );
    … …  
    201213                                        );
    202214
     215                                        // Compress the versions list down to a smaller range.
     216                                        $compress = function( $versions ) {
     217                                                $in = $versions;
     218                                                $out = [];
     219                                                if ( ! is_array( $versions ) ) {
     220                                                        $versions = preg_split( '![,\s]+!', $versions );
     221                                                }
     222
     223                                                // Don't try to compress only a few versions.
     224                                                if ( count( $versions ) <= 2 ) {
     225                                                        return $in;
     226                                                }
     227
     228                                                // [ X.Y => 0, X.Y+1 => 1, ... ]
     229                                                $versions = array_flip( $versions );
     230
     231                                                $not_a_version = [
     232                                                        '0.9', '1.1', '1.2', '1.4', '1.7', '1.8', '1.9',
     233                                                ];
     234
     235                                                // 2.4 + 2.5 are special. 2.4 was skipped, and many users only have a 2.4 or a 2.5 prop. Give them both versions if they have either.
     236                                                if ( isset( $versions['2.5'] ) || isset( $versions['2.4'] ) ) {
     237                                                        $versions['2.5'] = $version['2.4'] = 1;
     238                                                }
     239
     240                                                $i = 0; // This counter is just here to protect against infinite loops should something go wrong.
     241                                                while ( $versions && $i++ < 40 ) {
     242                                                        $min   = sprintf( '%.1f', min( array_keys( $versions ) ) );
     243                                                        $max   = sprintf( '%.1f', max( array_keys( $versions ) ) );
     244                                                        if ( $min === $max ) {
     245                                                                $out[] = $min;
     246                                                                break;
     247                                                        } elseif ( $max - $min < 0.2 ) {
     248                                                                $out[] = "{$min}-{$max}";
     249                                                                break;
     250                                                        }
     251
     252                                                        foreach ( range( $min, $max+0.1, 0.1 ) as $v ) {
     253                                                                $v = sprintf( '%.1f', $v );
     254
     255                                                                if ( in_array( $v, $not_a_version ) ) {
     256                                                                        unset( $versions[ $v ] );
     257                                                                        continue;
     258                                                                }
     259
     260                                                                if ( ! isset( $versions[ $v ] ) ) {
     261                                                                        $last = sprintf( '%.1f', $v - 0.1 );
     262
     263                                                                        if ( $last == $min ) {
     264                                                                                $out[] = $last;
     265                                                                                unset( $versions[ $v ] );
     266                                                                                break;
     267                                                                        } elseif ( $last - $min < 0.15 ) {
     268                                                                                // No point doing 1-2, just do 1, 2
     269                                                                                $out[] = $min;
     270                                                                                $out[] = $last;
     271                                                                        } else {
     272                                                                                $out[] = "{$min}-{$last}";
     273                                                                        }
     274                                                                        break;
     275                                                                } elseif ( $v == $max ) {
     276                                                                        $out[] = "{$min}-{$max}"; // (5)";
     277                                                                        unset( $versions[ $v ] );
     278                                                                        break;
     279                                                                } else {
     280                                                                        // no break. We're between a start, and end version.
     281                                                                }
     282                                                                unset( $versions[ $v ] );
     283                                                        }
     284                                                }
     285
     286                                                return implode( ', ', $out );
     287                                        };
     288
    203289                                        echo '<table class="widefat striped">';
    204290                                        echo '<thead><tr><th>Prop</th><th>Count</th><th>Versions</th></tr></thead>';
    … …  
    223309                                                        $p->count,
    224310                                                        esc_attr( $p->versions ),
    225                                                         $p->versions
     311                                                        $compress( $p->versions )
    226312                                                );
    227313                                        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/ui.php

    r11362 r11369  
    7878
    7979function display_list_table( $details ) {
     80        $url   = add_query_arg( 'page', $_REQUEST['page'], admin_url( 'admin.php' ) );
    8081        $table = new Commits_List_Table( $details );
    8182        $table->prepare_items( $_REQUEST );
    … …  
    8384                <div class="wrap propstable">
    8485                        <h2><?php echo esc_html( $details['name'] ); ?> Props</h2>
    85                         <form method="GET" action="<?php echo esc_url( add_query_arg() ); ?>">
     86                        <form method="GET" action="<?php echo esc_url( $url ); ?>">
    8687                                <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
    8788                                <?php $table->search_box( 'Search', 's' ); ?>
Note: See TracChangeset for help on using the changeset viewer.