]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/class-wp-media-list-table.php
WordPress 4.2
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-media-list-table.php
index 237c99d155fe6b52c15637f3b7ec408fe3f6576f..9ebd5c0c7f6b0152a9627635784fe0b690483abc 100644 (file)
@@ -9,6 +9,10 @@
  */
 class WP_Media_List_Table extends WP_List_Table {
 
  */
 class WP_Media_List_Table extends WP_List_Table {
 
+       private $detached;
+
+       private $is_trash;
+
        /**
         * Constructor.
         *
        /**
         * Constructor.
         *
@@ -22,6 +26,11 @@ class WP_Media_List_Table extends WP_List_Table {
        public function __construct( $args = array() ) {
                $this->detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] );
 
        public function __construct( $args = array() ) {
                $this->detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] );
 
+               $this->modes = array(
+                       'list' => __( 'List View' ),
+                       'grid' => __( 'Grid View' )
+               );
+
                parent::__construct( array(
                        'plural' => 'media',
                        'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
                parent::__construct( array(
                        'plural' => 'media',
                        'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
@@ -70,7 +79,7 @@ class WP_Media_List_Table extends WP_List_Table {
                        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'] ) ) )
                                $selected = ' selected="selected"';
                        if ( !empty( $num_posts[$mime_type] ) )
                        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'] ) ) )
                                $selected = ' selected="selected"';
                        if ( !empty( $num_posts[$mime_type] ) )
-                               $type_links[$mime_type] = '<option value="post_mime_type:' . urlencode( $mime_type ) . '"' . $selected . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</option>';
+                               $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>';
                }
                $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"' : '' ) . '>' . sprintf( _nx( 'Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</option>';
 
@@ -82,13 +91,26 @@ class WP_Media_List_Table extends WP_List_Table {
 
        protected function get_bulk_actions() {
                $actions = array();
 
        protected function get_bulk_actions() {
                $actions = array();
-               $actions['delete'] = __( 'Delete Permanently' );
+               if ( MEDIA_TRASH ) {
+                       if ( $this->is_trash ) {
+                               $actions['untrash'] = __( 'Restore' );
+                               $actions['delete'] = __( 'Delete Permanently' );
+                       } else {
+                               $actions['trash'] = __( 'Trash' );
+                       }
+               } else {
+                       $actions['delete'] = __( 'Delete Permanently' );
+               }
+
                if ( $this->detached )
                        $actions['attach'] = __( 'Attach to a post' );
 
                return $actions;
        }
 
                if ( $this->detached )
                        $actions['attach'] = __( 'Attach to a post' );
 
                return $actions;
        }
 
+       /**
+        * @param string $which
+        */
        protected function extra_tablenav( $which ) {
                if ( 'bar' !== $which ) {
                        return;
        protected function extra_tablenav( $which ) {
                if ( 'bar' !== $which ) {
                        return;
@@ -117,6 +139,9 @@ class WP_Media_List_Table extends WP_List_Table {
                if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
                        return 'attach';
 
                if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
                        return 'attach';
 
+               if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) )
+                       return 'detach';
+
                if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
                        return 'delete_all';
 
                if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
                        return 'delete_all';
 
@@ -131,44 +156,6 @@ class WP_Media_List_Table extends WP_List_Table {
                _e( 'No media attachments found.' );
        }
 
                _e( 'No media attachments found.' );
        }
 
-       protected function pagination( $which ) {
-               global $mode;
-
-               parent::pagination( $which );
-       }
-
-       /**
-        * Display a view switcher
-        *
-        * @since 3.1.0
-        * @access protected
-        */
-       protected function view_switcher( $current_mode ) {
-               $modes = array(
-                       'list'    => __( 'List View' ),
-                       'grid' => __( 'Grid View' )
-               );
-
-?>
-               <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
-               <div class="view-switch">
-<?php
-                       foreach ( $modes as $mode => $title ) {
-                               $classes = array( 'view-' . $mode );
-                               if ( $current_mode == $mode )
-                                       $classes[] = 'current';
-                               printf(
-                                       "<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
-                                       esc_url( add_query_arg( 'mode', $mode ) ),
-                                       implode( ' ', $classes ),
-                                       $title
-                               );
-                       }
-               ?>
-               </div>
-<?php
-       }
-
        /**
         * Override parent views so we can use the filter bar display.
         */
        /**
         * Override parent views so we can use the filter bar display.
         */
@@ -178,33 +165,36 @@ class WP_Media_List_Table extends WP_List_Table {
                $views = $this->get_views();
 ?>
 <div class="wp-filter">
                $views = $this->get_views();
 ?>
 <div class="wp-filter">
-       <?php $this->view_switcher( $mode ); ?>
+       <div class="filter-items">
+               <?php $this->view_switcher( $mode ); ?>
 
 
-       <select class="attachment-filters" name="attachment-filter">
-               <?php
-               if ( ! empty( $views ) ) {
-                       foreach ( $views as $class => $view ) {
-                               echo "\t$view\n";
+               <label for="attachment-filter" class="screen-reader-text"><?php _e( 'Filter by type' ); ?></label>
+               <select class="attachment-filters" name="attachment-filter" id="attachment-filter">
+                       <?php
+                       if ( ! empty( $views ) ) {
+                               foreach ( $views as $class => $view ) {
+                                       echo "\t$view\n";
+                               }
                        }
                        }
-               }
-               ?>
-       </select>
+                       ?>
+               </select>
 
 <?php
 
 <?php
-       $this->extra_tablenav( 'bar' );
+               $this->extra_tablenav( 'bar' );
 
 
-       /** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
-       $views = apply_filters( "views_{$this->screen->id}", array() );
+               /** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
+               $views = apply_filters( "views_{$this->screen->id}", array() );
 
 
-       // Back compat for pre-4.0 view links.
-       if ( ! empty( $views ) ) {
-               echo '<ul class="filter-links">';
-               foreach ( $views as $class => $view ) {
-                       echo "<li class='$class'>$view</li>";
+               // Back compat for pre-4.0 view links.
+               if ( ! empty( $views ) ) {
+                       echo '<ul class="filter-links">';
+                       foreach ( $views as $class => $view ) {
+                               echo "<li class='$class'>$view</li>";
+                       }
+                       echo '</ul>';
                }
                }
-               echo '</ul>';
-       }
 ?>
 ?>
+       </div>
 
        <div class="search-form">
                <label for="media-search-input" class="screen-reader-text"><?php esc_html_e( 'Search Media' ); ?></label>
 
        <div class="search-form">
                <label for="media-search-input" class="screen-reader-text"><?php esc_html_e( 'Search Media' ); ?></label>
@@ -282,7 +272,6 @@ class WP_Media_List_Table extends WP_List_Table {
                global $post;
 
                add_filter( 'the_title','esc_html' );
                global $post;
 
                add_filter( 'the_title','esc_html' );
-               $alt = '';
 
                while ( have_posts() ) : the_post();
                        $user_can_edit = current_user_can( 'edit_post', $post->ID );
 
                while ( have_posts() ) : the_post();
                        $user_can_edit = current_user_can( 'edit_post', $post->ID );
@@ -291,11 +280,10 @@ class WP_Media_List_Table extends WP_List_Table {
                        ||  !$this->is_trash && $post->post_status == 'trash' )
                                continue;
 
                        ||  !$this->is_trash && $post->post_status == 'trash' )
                                continue;
 
-                       $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
                        $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
                        $att_title = _draft_or_post_title();
 ?>
                        $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
                        $att_title = _draft_or_post_title();
 ?>
-       <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>">
+       <tr id="post-<?php echo $post->ID; ?>" class="<?php echo trim( ' author-' . $post_owner . ' status-' . $post->post_status ); ?>">
 <?php
 
 list( $columns, $hidden ) = $this->get_column_info();
 <?php
 
 list( $columns, $hidden ) = $this->get_column_info();
@@ -331,7 +319,7 @@ foreach ( $columns as $column_name => $column_display_name ) {
                                        echo $thumb;
                                } else {
 ?>
                                        echo $thumb;
                                } else {
 ?>
-                               <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
+                               <a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
                                        <?php echo $thumb; ?>
                                </a>
 
                                        <?php echo $thumb; ?>
                                </a>
 
@@ -348,19 +336,12 @@ foreach ( $columns as $column_name => $column_display_name ) {
                        <?php if ( $this->is_trash || ! $user_can_edit ) {
                                echo $att_title;
                        } else { ?>
                        <?php if ( $this->is_trash || ! $user_can_edit ) {
                                echo $att_title;
                        } else { ?>
-                       <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>"
+                       <a href="<?php echo get_edit_post_link( $post->ID ); ?>"
                                title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
                                <?php echo $att_title; ?></a>
                        <?php };
                        _media_states( $post ); ?></strong>
                                title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $att_title ) ); ?>">
                                <?php echo $att_title; ?></a>
                        <?php };
                        _media_states( $post ); ?></strong>
-                       <p>
-<?php
-                       if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
-                               echo esc_html( strtoupper( $matches[1] ) );
-                       else
-                               echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) );
-?>
-                       </p>
+                       <p class="filename"><?php echo wp_basename( $post->guid ); ?></p>
 <?php
                echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
 ?>
 <?php
                echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
 ?>
@@ -422,7 +403,16 @@ foreach ( $columns as $column_name => $column_display_name ) {
                                } else {
                                        echo $title;
                                } ?></strong>,
                                } else {
                                        echo $title;
                                } ?></strong>,
-                               <?php echo get_the_time( __( 'Y/m/d' ) ); ?>
+                               <?php echo get_the_time( __( 'Y/m/d' ) ); ?><br />
+                               <?php
+                               if ( $user_can_edit ):
+                                       $detach_url = add_query_arg( array(
+                                               'parent_post_id' => $post->post_parent,
+                                               'media[]' => $post->ID,
+                                               '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] )
+                                       ), 'upload.php' ); ?>
+                               <a class="hide-if-no-js detach-from-parent" href="<?php echo $detach_url ?>"><?php _e( 'Detach' ); ?></a>
+                               <?php endif; ?>
                        </td>
 <?php
                } else {
                        </td>
 <?php
                } else {
@@ -486,21 +476,19 @@ foreach ( $columns as $column_name => $column_display_name ) {
                        break;
                }
 ?>
                        break;
                }
 ?>
-               <td <?php echo $attributes ?>>
-                       <?php
-                               /**
-                                * Fires for each custom column in the Media list table.
-                                *
-                                * Custom columns are registered using the 'manage_media_columns' filter.
-                                *
-                                * @since 2.5.0
-                                *
-                                * @param string $column_name Name of the custom column.
-                                * @param int    $post_id     Attachment ID.
-                                */
-                       ?>
-                       <?php do_action( 'manage_media_custom_column', $column_name, $post->ID ); ?>
-               </td>
+               <td <?php echo $attributes ?>><?php
+                       /**
+                        * Fires for each custom column in the Media list table.
+                        *
+                        * Custom columns are registered using the 'manage_media_columns' filter.
+                        *
+                        * @since 2.5.0
+                        *
+                        * @param string $column_name Name of the custom column.
+                        * @param int    $post_id     Attachment ID.
+                        */
+                       do_action( 'manage_media_custom_column', $column_name, $post->ID );
+               ?></td>
 <?php
                break;
        }
 <?php
                break;
        }
@@ -510,12 +498,16 @@ foreach ( $columns as $column_name => $column_display_name ) {
 <?php endwhile;
        }
 
 <?php endwhile;
        }
 
+       /**
+        * @param WP_Post $post
+        * @param string  $att_title
+        */
        private function _get_row_actions( $post, $att_title ) {
                $actions = array();
 
                if ( $this->detached ) {
                        if ( current_user_can( 'edit_post', $post->ID ) )
        private function _get_row_actions( $post, $att_title ) {
                $actions = array();
 
                if ( $this->detached ) {
                        if ( current_user_can( 'edit_post', $post->ID ) )
-                               $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
+                               $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '">' . __( 'Edit' ) . '</a>';
                        if ( current_user_can( 'delete_post', $post->ID ) )
                                if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
                                        $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
                        if ( current_user_can( 'delete_post', $post->ID ) )
                                if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
                                        $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
@@ -529,7 +521,7 @@ foreach ( $columns as $column_name => $column_display_name ) {
                }
                else {
                        if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash )
                }
                else {
                        if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash )
-                               $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>';
+                               $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '">' . __( 'Edit' ) . '</a>';
                        if ( current_user_can( 'delete_post', $post->ID ) ) {
                                if ( $this->is_trash )
                                        $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
                        if ( current_user_can( 'delete_post', $post->ID ) ) {
                                if ( $this->is_trash )
                                        $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";