X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/76aea3697c6043c1613370f172395b4f65ee71f0..4713a14935b83517997f3c88f808eb41da55033d:/wp-admin/upload.php?ds=inline diff --git a/wp-admin/upload.php b/wp-admin/upload.php index cf6c1916..c38a0b63 100644 --- a/wp-admin/upload.php +++ b/wp-admin/upload.php @@ -1,250 +1,245 @@ get_pagenum(); - if ( !current_user_can('delete_post', $post_id_del) ) - wp_die( __('You are not allowed to delete this post.') ); +// Handle bulk actions +$doaction = $wp_list_table->current_action(); + +if ( $doaction ) { + check_admin_referer('bulk-media'); - if ( $post_del->post_type == 'attachment' ) - if ( ! wp_delete_attachment($post_id_del) ) - wp_die( __('Error in deleting...') ); + if ( 'delete_all' == $doaction ) { + $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" ); + $doaction = 'delete'; + } elseif ( isset( $_REQUEST['media'] ) ) { + $post_ids = $_REQUEST['media']; + } elseif ( isset( $_REQUEST['ids'] ) ) { + $post_ids = explode( ',', $_REQUEST['ids'] ); } $location = 'upload.php'; if ( $referer = wp_get_referer() ) { - if ( false !== strpos($referer, 'upload.php') ) - $location = $referer; + if ( false !== strpos( $referer, 'upload.php' ) ) + $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer ); } - $location = add_query_arg('message', 2, $location); - $location = remove_query_arg('posted', $location); - wp_redirect($location); - exit; -} elseif ( !empty($_GET['_wp_http_referer']) ) { - wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']))); + switch ( $doaction ) { + case 'find_detached': + if ( !current_user_can('edit_posts') ) + wp_die( __('You are not allowed to scan for lost attachments.') ); + + $lost = $wpdb->get_col( " + SELECT ID FROM $wpdb->posts + WHERE post_type = 'attachment' AND post_parent > '0' + AND post_parent NOT IN ( + SELECT ID FROM $wpdb->posts + WHERE post_type NOT IN ( 'attachment', '" . join( "', '", get_post_types( array( 'public' => false ) ) ) . "' ) + ) + " ); + + $_REQUEST['detached'] = 1; + break; + case 'attach': + $parent_id = (int) $_REQUEST['found_post_id']; + if ( !$parent_id ) + return; + + $parent = get_post( $parent_id ); + if ( !current_user_can( 'edit_post', $parent_id ) ) + wp_die( __( 'You are not allowed to edit this post.' ) ); + + $attach = array(); + foreach ( (array) $_REQUEST['media'] as $att_id ) { + $att_id = (int) $att_id; + + if ( !current_user_can( 'edit_post', $att_id ) ) + continue; + + $attach[] = $att_id; + } + + if ( ! empty( $attach ) ) { + $attach_string = implode( ',', $attach ); + $attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach_string )", $parent_id ) ); + foreach ( $attach as $att_id ) { + clean_attachment_cache( $att_id ); + } + } + + if ( isset( $attached ) ) { + $location = 'upload.php'; + if ( $referer = wp_get_referer() ) { + if ( false !== strpos( $referer, 'upload.php' ) ) + $location = $referer; + } + + $location = add_query_arg( array( 'attached' => $attached ) , $location ); + wp_redirect( $location ); + exit; + } + break; + case 'trash': + if ( !isset( $post_ids ) ) + break; + foreach ( (array) $post_ids as $post_id ) { + if ( !current_user_can( 'delete_post', $post_id ) ) + wp_die( __( 'You are not allowed to move this post to the trash.' ) ); + + if ( !wp_trash_post( $post_id ) ) + wp_die( __( 'Error in moving to trash.' ) ); + } + $location = add_query_arg( array( 'trashed' => count( $post_ids ), 'ids' => join( ',', $post_ids ) ), $location ); + break; + case 'untrash': + if ( !isset( $post_ids ) ) + break; + foreach ( (array) $post_ids as $post_id ) { + if ( !current_user_can( 'delete_post', $post_id ) ) + wp_die( __( 'You are not allowed to move this post out of the trash.' ) ); + + if ( !wp_untrash_post( $post_id ) ) + wp_die( __( 'Error in restoring from trash.' ) ); + } + $location = add_query_arg( 'untrashed', count( $post_ids ), $location ); + break; + case 'delete': + if ( !isset( $post_ids ) ) + break; + foreach ( (array) $post_ids as $post_id_del ) { + if ( !current_user_can( 'delete_post', $post_id_del ) ) + wp_die( __( 'You are not allowed to delete this post.' ) ); + + if ( !wp_delete_attachment( $post_id_del ) ) + wp_die( __( 'Error in deleting.' ) ); + } + $location = add_query_arg( 'deleted', count( $post_ids ), $location ); + break; + } + + wp_redirect( $location ); exit; +} elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { + wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); + exit; } -$title = __('Media Library'); -$parent_file = 'edit.php'; -wp_enqueue_script( 'admin-forms' ); - -list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); - -if ( is_singular() ) - wp_enqueue_script( 'admin-comments' ); - -require_once('admin-header.php'); - -if ( !isset( $_GET['paged'] ) ) - $_GET['paged'] = 1; +$wp_list_table->prepare_items(); +$title = __('Media Library'); +$parent_file = 'upload.php'; + +wp_enqueue_script( 'media' ); + +add_screen_option( 'per_page', array('label' => _x( 'Media items', 'items per page (screen options)' )) ); + +get_current_screen()->add_help_tab( array( +'id' => 'overview', +'title' => __('Overview'), +'content' => + '

' . __( 'All the files you’ve uploaded are listed in the Media Library, with the most recent uploads listed first. You can use the Screen Options tab to customize the display of this screen.' ) . '

' . + '

' . __( 'You can narrow the list by file type/status using the text link filters at the top of the screen. You also can refine the list by date using the dropdown menu above the media table.' ) . '

' +) ); +get_current_screen()->add_help_tab( array( +'id' => 'actions-links', +'title' => __('Available Actions'), +'content' => + '

' . __( 'Hovering over a row reveals action links: Edit, Delete Permanently, and View. Clicking Edit or on the media file’s name displays a simple screen to edit that individual file’s metadata. Clicking Delete Permanently will delete the file from the media library (as well as from any posts to which it is currently attached). View will take you to the display page for that file.' ) . '

' +) ); +get_current_screen()->add_help_tab( array( +'id' => 'attaching-files', +'title' => __('Attaching Files'), +'content' => + '

' . __( 'If a media file has not been attached to any post, you will see that in the Attached To column, and can click on Attach File to launch a small popup that will allow you to search for a post and attach the file.' ) . '

' +) ); + +get_current_screen()->set_help_sidebar( + '

' . __( 'For more information:' ) . '

' . + '

' . __( 'Documentation on Media Library' ) . '

' . + '

' . __( 'Support Forums' ) . '

' +); + +require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>
- -
-

post_title)); -} else { - $post_mime_type_label = _c('Manage Media|manage media header'); - if ( isset($_GET['post_mime_type']) && in_array( $_GET['post_mime_type'], array_keys($post_mime_types) ) ) - $post_mime_type_label = $post_mime_types[$_GET['post_mime_type']][1]; - if ( $post_listing_pageable && !is_archive() && !is_search() ) - $h2_noun = is_paged() ? sprintf(__( 'Previous %s' ), $post_mime_type_label) : sprintf(__('Latest %s'), $post_mime_type_label); - else - $h2_noun = $post_mime_type_label; - // Use $_GET instead of is_ since they can override each other - $h2_author = ''; - $_GET['author'] = (int) $_GET['author']; - if ( $_GET['author'] != 0 ) { - if ( $_GET['author'] == '-' . $user_ID ) { // author exclusion - $h2_author = ' ' . __('by other authors'); - } else { - $author_user = get_userdata( get_query_var( 'author' ) ); - $h2_author = ' ' . sprintf(__('by %s'), wp_specialchars( $author_user->display_name )); - } - } - $h2_search = isset($_GET['s']) && $_GET['s'] ? ' ' . sprintf(__('matching “%s”'), wp_specialchars( get_search_query() ) ) : ''; - $h2_cat = isset($_GET['cat']) && $_GET['cat'] ? ' ' . sprintf( __('in “%s”'), single_cat_title('', false) ) : ''; - $h2_tag = isset($_GET['tag']) && $_GET['tag'] ? ' ' . sprintf( __('tagged with “%s”'), single_tag_title('', false) ) : ''; - $h2_month = isset($_GET['m']) && $_GET['m'] ? ' ' . sprintf( __('during %s'), single_month_title(' ', false) ) : ''; - printf( _c( '%1$s%2$s%3$s%4$s%5$s%6$s|You can reorder these: 1: Posts, 2: by {s}, 3: matching {s}, 4: in {s}, 5: tagged with {s}, 6: during {s}' ), $h2_noun, $h2_author, $h2_search, $h2_cat, $h2_tag, $h2_month ); -} -?>

- - - - -

|

- -

- - -

- - - -

- - - -
- - add_query_arg( 'paged', '%#%' ), - 'format' => '', - 'total' => $wp_query->max_num_pages, - 'current' => $_GET['paged'] -)); - -if ( $page_links ) - echo "
$page_links
"; -?> +if ( ! empty( $_REQUEST['s'] ) ) + printf( '' . __('Search results for “%s”') . '', get_search_query() ); ?> + -
- - posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; +if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) { + $message = sprintf( _n('Reattached %d attachment.', 'Reattached %d attachments.', $attached), $attached ); + $_SERVER['REQUEST_URI'] = remove_query_arg(array('attached'), $_SERVER['REQUEST_URI']); +} - $arc_result = $wpdb->get_results( $arc_query ); +if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) { + $message = sprintf( _n( 'Media attachment permanently deleted.', '%d media attachments permanently deleted.', $deleted ), number_format_i18n( $_GET['deleted'] ) ); + $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']); +} - $month_count = count($arc_result); +if ( ! empty( $_GET['trashed'] ) && $trashed = absint( $_GET['trashed'] ) ) { + $message = sprintf( _n( 'Media attachment moved to the trash.', '%d media attachments moved to the trash.', $trashed ), number_format_i18n( $_GET['trashed'] ) ); + $message .= ' ' . __('Undo') . ''; + $_SERVER['REQUEST_URI'] = remove_query_arg(array('trashed'), $_SERVER['REQUEST_URI']); +} - if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) : ?> - - - +$messages[1] = __('Media attachment updated.'); +$messages[2] = __('Media permanently deleted.'); +$messages[3] = __('Error saving media attachment.'); +$messages[4] = __('Media moved to the trash.') . ' ' . __('Undo') . ''; +$messages[5] = __('Media restored from the trash.'); - +if ( ! empty( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) { + $message = $messages[ $_GET['message'] ]; + $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); +} -
+if ( !empty($message) ) { ?> +

+ -
-
+views(); ?> -
+ - +search_box( __( 'Search Media' ), 'media' ); ?> -
+display(); ?>
- -
- -$page_links
"; -?> - + +
-
- -get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved != 'spam' ORDER BY comment_date", $id) ); - if ( $comments ) : - // Make sure comments, post, and post_author are cached - update_comment_cache($comments); - $post = get_post($id); - $authordata = get_userdata($post->post_author); - ?> - -
- - - - - - - - - - -comment_ID, 'detail', false, false ); -?> - -
- - - - - +include( ABSPATH . 'wp-admin/admin-footer.php' );