Changeset 11369 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/reports-page.php
- Timestamp:
- 12/14/2021 04:39:01 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/admin/reports-page.php
r11367 r11369 6 6 $url = add_query_arg( 'page', $_REQUEST['page'], admin_url( 'admin.php' ) ); 7 7 $what = $_REQUEST['what'] ?? ''; 8 $version = $_REQUEST['version'] ?? (WP_CORE_LATEST_RELEASE+0.1);8 $version = $_REQUEST['version'] ?? null; 9 9 $revisions = $_REQUEST['revisions'] ?? ''; 10 10 $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 } 11 17 12 18 $url = add_query_arg( 'version', $version, $url ); … … 21 27 <li><a href="<?php echo $url; ?>&what=raw-contributors-and-committers">All Props+Committers matching filter grouped together</a></li> 22 28 29 <?php if ( $is_core ) { ?> 23 30 <li><a href="<?php echo $url; ?>&what=versions-contributed">Versions which users have contributed to. Ignores filter.</a></li> 31 <?php } ?> 24 32 </ol> 25 33 … … 29 37 30 38 <?php 31 if ( 'core' === $details['slug']) {39 if ( $is_core ) { 32 40 echo '<select name="version"><option value="">Version</option>'; 33 41 foreach ( get_wordpress_versions() as $v ) { … … 57 65 58 66 // Revision range. 59 echo '<input type="text" name="revisions" placeholder="Revs: 1: 50or 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 ) .'">'; 60 68 61 69 echo '<input type="submit" class="button button-primary" value="Filter">'; … … 70 78 // Revisions. 71 79 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 } 74 86 } elseif ( false !== strpos( $revisions, ',' ) ) { 75 87 $ids = implode( ',', array_map( 'intval', explode( ',', $revisions ) ) ); … … 201 213 ); 202 214 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 203 289 echo '<table class="widefat striped">'; 204 290 echo '<thead><tr><th>Prop</th><th>Count</th><th>Versions</th></tr></thead>'; … … 223 309 $p->count, 224 310 esc_attr( $p->versions ), 225 $ p->versions311 $compress( $p->versions ) 226 312 ); 227 313 }
Note: See TracChangeset
for help on using the changeset viewer.