Media List Table: remove the counts from the "views" portion of the toolbar, which are inconsistent with grid view. Also reduces complexity and removes potentially expensive count query.

Related to the toolbar view, remove the `wp_admin_canonical_url()` action in grid mode. Grid views that result from links from the list table view are lenses into the library and need to be indicated as such vs being a full attachment query.

Fixes #29744.

Built from https://develop.svn.wordpress.org/trunk@34256


git-svn-id: http://core.svn.wordpress.org/trunk@34220 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-09-17 02:30:26 +00:00
parent a87ef29978
commit 58ac764859
3 changed files with 37 additions and 25 deletions

View File

@ -84,36 +84,46 @@ class WP_Media_List_Table extends WP_List_Table {
* @return array * @return array
*/ */
protected function get_views() { protected function get_views() {
global $wpdb, $post_mime_types, $avail_post_mime_types; global $post_mime_types, $avail_post_mime_types;
$type_links = array(); $type_links = array();
$_num_posts = (array) wp_count_attachments();
$_total_posts = array_sum($_num_posts) - $_num_posts['trash']; $filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter'];
$total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); $type_links['all'] = sprintf(
$num_posts = array(); '<option value=""%s>%s</option>',
foreach ( $matches as $type => $reals ) { selected( $filter, true, false ),
foreach ( $reals as $real ) { __( 'All media items' )
$num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real]; );
}
}
$selected = empty( $_GET['attachment-filter'] ) ? ' selected="selected"' : '';
$type_links['all'] = "<option value=''$selected>" . sprintf( _nx( 'All (%s)', 'All (%s)', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</option>';
foreach ( $post_mime_types as $mime_type => $label ) { foreach ( $post_mime_types as $mime_type => $label ) {
if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
continue; continue;
}
$selected = ''; $selected = selected(
if ( !empty( $_GET['attachment-filter'] ) && strpos( $_GET['attachment-filter'], 'post_mime_type:' ) === 0 && wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $_GET['attachment-filter'] ) ) ) $filter && 0 === strpos( $filter, 'post_mime_type:' ) &&
$selected = ' selected="selected"'; wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ),
if ( !empty( $num_posts[$mime_type] ) ) true,
$type_links[$mime_type] = '<option value="post_mime_type:' . esc_attr( $mime_type ) . '"' . $selected . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</option>'; false
);
$type_links[$mime_type] = sprintf(
'<option value="post_mime_type:%s"%s>%s</option>',
esc_attr( $mime_type ),
$selected,
$label[0]
);
} }
$type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . sprintf( _nx( 'Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</option>'; $type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . __( 'Unattached' ) . '</option>';
if ( !empty($_num_posts['trash']) )
$type_links['trash'] = '<option value="trash"' . ( (isset($_GET['attachment-filter']) && $_GET['attachment-filter'] == 'trash' ) ? ' selected="selected"' : '') . '>' . sprintf( _nx( 'Trash (%s)', 'Trash (%s)', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</option>';
if ( $this->is_trash ) {
$type_links['trash'] = sprintf(
'<option value="trash"%s>%s</option>',
selected( 'trash' === $filter, true, false ),
__( 'Trash' )
);
}
return $type_links; return $type_links;
} }
@ -372,7 +382,7 @@ class WP_Media_List_Table extends WP_List_Table {
</strong> </strong>
<p class="filename"> <p class="filename">
<span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span> <span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span>
<?php <?php
$file = get_attached_file( $post->ID ); $file = get_attached_file( $post->ID );
echo wp_basename( $file ); echo wp_basename( $file );
?> ?>

View File

@ -25,6 +25,8 @@ if ( 'grid' === $mode ) {
wp_enqueue_script( 'media-grid' ); wp_enqueue_script( 'media-grid' );
wp_enqueue_script( 'media' ); wp_enqueue_script( 'media' );
remove_action( 'admin_head', 'wp_admin_canonical_url' );
$q = $_GET; $q = $_GET;
// let JS handle this // let JS handle this
unset( $q['s'] ); unset( $q['s'] );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-alpha-34255'; $wp_version = '4.4-alpha-34256';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.