Changeset 11749 for trunk/wp-admin/upload.php
- Timestamp:
- 07/30/2009 01:39:34 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/upload.php
r11715 r11749 68 68 } 69 69 70 } elseif ( isset($_GET[' action']) && isset($_GET['media']) && ( -1 != $_GET['action'] || -1 != $_GET['action2']) ) {70 } elseif ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) { 71 71 check_admin_referer('bulk-media'); 72 $doaction = ( -1 != $_GET['action'] ) ? $_GET['action'] : $_GET['action2']; 73 74 if ( 'delete' == $doaction ) { 75 foreach( (array) $_GET['media'] as $post_id_del ) { 76 $post_del = & get_post($post_id_del); 77 78 if ( !current_user_can('delete_post', $post_id_del) ) 79 wp_die( __('You are not allowed to delete this post.') ); 80 81 if ( $post_del->post_type == 'attachment' ) 82 if ( ! wp_delete_attachment($post_id_del) ) 72 73 if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) { 74 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" ); 75 $doaction = 'delete'; 76 } elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['media']) ) { 77 $post_ids = $_GET['media']; 78 $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2']; 79 } else 80 wp_redirect($_SERVER['HTTP_REFERER']); 81 82 $location = 'upload.php'; 83 if ( $referer = wp_get_referer() ) { 84 if ( false !== strpos($referer, 'upload.php') ) 85 $location = $referer; 86 } 87 88 switch ( $doaction ) { 89 case 'trash': 90 foreach( (array) $post_ids as $post_id ) { 91 if ( !current_user_can('delete_post', $post_id) ) 92 wp_die( __('You are not allowed to move this post to the trash.') ); 93 94 if ( !wp_trash_post($post_id) ) 95 wp_die( __('Error in moving to trash...') ); 96 } 97 $location = add_query_arg('message', 4, $location); 98 break; 99 case 'untrash': 100 foreach( (array) $post_ids as $post_id ) { 101 if ( !current_user_can('delete_post', $post_id) ) 102 wp_die( __('You are not allowed to remove this post from the trash.') ); 103 104 if ( !wp_untrash_post($post_id) ) 105 wp_die( __('Error in restoring from trash...') ); 106 } 107 $location = add_query_arg('message', 5, $location); 108 break; 109 case 'delete': 110 foreach( (array) $post_ids as $post_id_del ) { 111 if ( !current_user_can('delete_post', $post_id_del) ) 112 wp_die( __('You are not allowed to delete this post.') ); 113 114 if ( !wp_delete_attachment($post_id_del) ) 83 115 wp_die( __('Error in deleting...') ); 84 } 85 86 $location = 'upload.php'; 87 if ( $referer = wp_get_referer() ) { 88 if ( false !== strpos($referer, 'upload.php') ) 89 $location = $referer; 90 } 91 92 $location = add_query_arg('message', 2, $location); 93 $location = remove_query_arg('posted', $location); 94 wp_redirect($location); 95 exit; 96 } 116 } 117 $location = add_query_arg('message', 2, $location); 118 break; 119 } 120 121 $location = remove_query_arg('posted', $location); 122 wp_redirect($location); 123 exit; 97 124 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) { 98 125 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); … … 116 143 } else { 117 144 $start = ( $_GET['paged'] - 1 ) * 25; 118 $orphans = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_ parent < 1 LIMIT $start, 25" );145 $orphans = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT $start, 25" ); 119 146 $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / 25); 120 147 } … … 136 163 } 137 164 165 $is_trash = ( isset($_GET['status']) && $_GET['status'] == 'trash' ); 166 138 167 wp_enqueue_script('media'); 139 168 require_once('admin-header.php'); ?> … … 154 183 $messages[2] = __('Media deleted.'); 155 184 $messages[3] = __('Error saving media attachment.'); 185 $messages[4] = __('Media moved to Trash.'); 186 $messages[5] = __('Media removed from Trash.'); 156 187 157 188 if ( isset($_GET['message']) && (int) $_GET['message'] ) { … … 181 212 $type_links = array(); 182 213 $_num_posts = (array) wp_count_attachments(); 183 $_total_posts = array_sum( $_num_posts );214 $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; 184 215 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); 185 216 foreach ( $matches as $type => $reals ) … … 187 218 $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real]; 188 219 189 $class = empty($_GET['post_mime_type']) && ! isset($_GET['detached']) ? ' class="current"' : '';220 $class = ( empty($_GET['post_mime_type']) && !isset($_GET['detached']) && !isset($_GET['status']) ) ? ' class="current"' : ''; 190 221 $type_links[] = "<li><a href='upload.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</a>'; 191 222 foreach ( $post_mime_types as $mime_type => $label ) { … … 200 231 $type_links[] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>'; 201 232 } 202 $ class = isset($_GET['detached']) ? ' class="current"' : '';203 $type_links[] = '<li><a href="upload.php? detached=1"' . $class . '>' . __('Unattached') . '</a>';233 $type_links[] = '<li><a href="upload.php?detached=1"' . ( isset($_GET['detached']) ? ' class="current"' : '' ) . '>' . __('Unattached') . '</a>'; 234 $type_links[] = '<li><a href="upload.php?status=trash"' . ( (isset($_GET['status']) && $_GET['status'] == 'trash' ) ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>'; 204 235 205 236 echo implode( " |</li>\n", $type_links) . '</li>'; … … 243 274 <select name="action" class="select-action"> 244 275 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option> 245 <option value="delete"><?php _e('Delete'); ?></option> 246 <?php if ( isset($orphans) ) { ?> 276 <?php if ( $is_trash ) { ?> 277 <option value="untrash"><?php _e('Restore'); ?></option> 278 <option value="delete"><?php _e('Delete Permanently'); ?></option> 279 <?php } else { ?> 280 <option value="trash"><?php _e('Move to Trash'); ?></option> 281 <?php } if ( isset($orphans) ) { ?> 247 282 <option value="attach"><?php _e('Attach to a post'); ?></option> 248 283 <?php } ?> … … 252 287 253 288 <?php 254 if ( ! is_singular() && ! isset($_GET['detached'])) {289 if ( !is_singular() && !isset($_GET['detached']) && !$is_trash ) { 255 290 $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; 256 291 … … 287 322 <?php if ( isset($_GET['detached']) ) { ?> 288 323 <input type="submit" id="find_detached" name="find_detached" value="<?php esc_attr_e('Scan for lost attachments'); ?>" class="button-secondary" /> 324 <?php } elseif ( isset($_GET['status']) && $_GET['status'] == 'trash' ) { ?> 325 <input type="submit" id="delete_all" name="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" /> 289 326 <?php } ?> 290 327 … … 342 379 $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '">' . __('Edit') . '</a>'; 343 380 if ( current_user_can('delete_post', $post->ID) ) 344 $actions[' delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . esc_js(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this attachment '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this attachment '%s'\n 'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";381 $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID) . "'>" . __('Trash') . "</a>"; 345 382 $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View “%s”'), $title)) . '" rel="permalink">' . __('View') . '</a>'; 346 383 if ( current_user_can('edit_post', $post->ID) ) … … 399 436 <select name="action2" class="select-action"> 400 437 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option> 401 <option value="delete"><?php _e('Delete'); ?></option> 402 <?php if ( isset($orphans) ) { ?> 438 <?php if ($is_trash) { ?> 439 <option value="untrash"><?php _e('Restore'); ?></option> 440 <option value="delete"><?php _e('Delete Permanently'); ?></option> 441 <?php } else { ?> 442 <option value="trash"><?php _e('Move to Trash'); ?></option> 443 <?php } if (isset($orphans)) { ?> 403 444 <option value="attach"><?php _e('Attach to a post'); ?></option> 404 445 <?php } ?> 405 446 </select> 406 447 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" /> 448 449 <?php if ( isset($_GET['status']) && $_GET['status'] == 'trash' ) { ?> 450 <input type="submit" id="delete_all2" name="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" /> 451 <?php } ?> 407 452 </div> 408 453
Note: See TracChangeset
for help on using the changeset viewer.