X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/11be8dc178e77d0b46189bbd8e33a216a9b90942..refs/tags/wordpress-2.9:/wp-admin/upload.php diff --git a/wp-admin/upload.php b/wp-admin/upload.php index 7b57f649..2b891e13 100644 --- a/wp-admin/upload.php +++ b/wp-admin/upload.php @@ -10,15 +10,14 @@ require_once('admin.php'); wp_enqueue_script( 'wp-ajax-response' ); wp_enqueue_script( 'jquery-ui-draggable' ); -wp_enqueue_script( 'jquery-ui-resizable' ); -if (!current_user_can('upload_files')) +if ( !current_user_can('upload_files') ) wp_die(__('You do not have permission to upload files.')); -if ( isset($_GET['find_detached'] ) ) { +if ( isset($_GET['find_detached']) ) { check_admin_referer('bulk-media'); - if ( ! current_user_can('edit_posts') ) + if ( !current_user_can('edit_posts') ) wp_die( __('You are not allowed to scan for lost attachments.') ); $all_posts = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'post' OR post_type = 'page'"); @@ -63,38 +62,65 @@ if ( isset($_GET['find_detached'] ) ) { $location = $referer; } - $location = add_query_arg( array( 'detached' => 1, 'attached' => $attached ) , $location ); + $location = add_query_arg( array( 'attached' => $attached ) , $location ); wp_redirect($location); exit; } -} elseif ( isset($_GET['action']) && isset($_GET['media']) && ( -1 != $_GET['action'] || -1 != $_GET['action2'] ) ) { +} elseif ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) { check_admin_referer('bulk-media'); - $doaction = ( -1 != $_GET['action'] ) ? $_GET['action'] : $_GET['action2']; - if ( 'delete' == $doaction ) { - foreach( (array) $_GET['media'] as $post_id_del ) { - $post_del = & get_post($post_id_del); - - if ( !current_user_can('delete_post', $post_id_del) ) - wp_die( __('You are not allowed to delete this post.') ); + if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) { + $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" ); + $doaction = 'delete'; + } elseif ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['media']) || isset($_GET['ids']) ) ) { + $post_ids = isset($_GET['media']) ? $_GET['media'] : explode(',', $_GET['ids']); + $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2']; + } else { + wp_redirect($_SERVER['HTTP_REFERER']); + } - if ( $post_del->post_type == 'attachment' ) - if ( ! wp_delete_attachment($post_id_del) ) - wp_die( __('Error in deleting...') ); - } + $location = 'upload.php'; + if ( $referer = wp_get_referer() ) { + if ( false !== strpos($referer, 'upload.php') ) + $location = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted'), $referer ); + } - $location = 'upload.php'; - if ( $referer = wp_get_referer() ) { - if ( false !== strpos($referer, 'upload.php') ) - $location = $referer; - } + switch ( $doaction ) { + case 'trash': + 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.') ); - $location = add_query_arg('message', 2, $location); - $location = remove_query_arg('posted', $location); - wp_redirect($location); - exit; + if ( !wp_trash_post($post_id) ) + wp_die( __('Error in moving to trash...') ); + } + $location = add_query_arg( array( 'message' => 4, 'ids' => join(',', $post_ids) ), $location ); + break; + case 'untrash': + 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('message', 5, $location); + break; + case 'delete': + 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('message', 2, $location); + break; } + + wp_redirect($location); + exit; } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) { wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); exit; @@ -108,25 +134,24 @@ if ( ! isset( $_GET['paged'] ) || $_GET['paged'] < 1 ) if ( isset($_GET['detached']) ) { + $media_per_page = (int) get_user_option( 'upload_per_page', 0, false ); + if ( empty($media_per_page) || $media_per_page < 1 ) + $media_per_page = 20; + $media_per_page = apply_filters( 'upload_per_page', $media_per_page ); + if ( !empty($lost) ) { - $start = ( $_GET['paged'] - 1 ) * 50; - $page_links_total = ceil(count($lost) / 50); + $start = ( (int) $_GET['paged'] - 1 ) * $media_per_page; + $page_links_total = ceil(count($lost) / $media_per_page); $lost = implode(',', $lost); - $orphans = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN ($lost) LIMIT $start, 50" ); + $orphans = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN (%s) LIMIT %d, %d", $lost, $start, $media_per_page ) ); } else { - $start = ( $_GET['paged'] - 1 ) * 25; - $orphans = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent < 1 LIMIT $start, 25" ); - $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / 25); + $start = ( (int) $_GET['paged'] - 1 ) * $media_per_page; + $orphans = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT %d, %d", $start, $media_per_page ) ); + $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / $media_per_page); } - $post_mime_types = array( - 'image' => array(__('Images'), __('Manage Images'), __ngettext_noop('Image (%s)', 'Images (%s)')), - 'audio' => array(__('Audio'), __('Manage Audio'), __ngettext_noop('Audio (%s)', 'Audio (%s)')), - 'video' => array(__('Video'), __('Manage Video'), __ngettext_noop('Video (%s)', 'Video (%s)')), - ); - $post_mime_types = apply_filters('post_mime_types', $post_mime_types); - + $post_mime_types = get_post_mime_types(); $avail_post_mime_types = get_available_post_mime_types('attachment'); if ( isset($_GET['post_mime_type']) && !array_intersect( (array) $_GET['post_mime_type'], array_keys($post_mime_types) ) ) @@ -136,9 +161,23 @@ if ( isset($_GET['detached']) ) { list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); } -require_once('admin-header.php'); ?> +$is_trash = ( isset($_GET['status']) && $_GET['status'] == 'trash' ); + +wp_enqueue_script('media'); +require_once('admin-header.php'); + +do_action('restrict_manage_posts'); +?> + +
+ +

' . __('Search results for “%s”') . '', esc_html( get_search_query() ) ); ?> +

' . __('Undo') . ''; +$messages[5] = __('Media restored from the trash.'); if ( isset($_GET['message']) && (int) $_GET['message'] ) { $message = $messages[$_GET['message']]; $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']); } -?> - - -
- -

' . __('Search results for “%s”') . '', wp_specialchars( get_search_query() ) ); ?> -

- - +if ( !empty($message) ) { ?>

- +

+
- -