"Trash" updates, props caesarsgrunt, see #4529

git-svn-id: http://svn.automattic.com/wordpress/trunk@11841 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-08-19 08:35:24 +00:00
parent 4c13a5acf4
commit be026258fa
12 changed files with 54 additions and 24 deletions

View File

@ -312,6 +312,19 @@ case 'delete-post' :
else
die('0');
break;
case 'trash-post' :
check_ajax_referer( "{$action}_$id" );
if ( !current_user_can( 'delete_post', $id ) )
die('-1');
if ( !get_post( $id ) )
die('1');
if ( wp_trash_post( $id ) )
die('1');
else
die('0');
break;
case 'delete-page' :
check_ajax_referer( "{$action}_$id" );
if ( !current_user_can( 'delete_page', $id ) )

View File

@ -59,7 +59,7 @@ foreach ($posts_columns as $column_name => $column_display_name ) {
case 'cb':
?>
<th scope="row" class="check-column"><input type="checkbox" name="media[]" value="<?php the_ID(); ?>" /></th>
<th scope="row" class="check-column"><?php if ( current_user_can('edit_post', $post->ID) ) { ?><input type="checkbox" name="media[]" value="<?php the_ID(); ?>" /><?php } ?></th>
<?php
break;
@ -89,9 +89,11 @@ foreach ($posts_columns as $column_name => $column_display_name ) {
<p>
<?php
$actions = array();
if ( $is_trash && current_user_can('delete_post', $post->ID) ) {
$actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID) . "'>" . __('Restore') . "</a>";
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "'>" . __('Delete Permanently') . "</a>";
if ( $is_trash ) {
if ( current_user_can('delete_post', $post->ID) ) {
$actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID) . "'>" . __('Restore') . "</a>";
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "'>" . __('Delete Permanently') . "</a>";
}
} else {
if ( current_user_can('edit_post', $post->ID) )
$actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '">' . __('Edit') . '</a>';

View File

@ -303,7 +303,7 @@ $page_links = paginate_links( array(
if ( ( 'spam' == $comment_status || 'trash' == $comment_status) && current_user_can ('moderate_comments') ) {
wp_nonce_field('bulk-destroy', '_destroy_nonce');
if ( 'spam' == $comment_status ) { ?>
if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?>
<input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
<?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?>
<input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
@ -375,7 +375,7 @@ if ( $page_links )
</select>
<input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
<?php if ( 'spam' == $comment_status ) { ?>
<?php if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?>
<input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
<?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?>
<input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />

View File

@ -68,7 +68,7 @@ $date = date_i18n( $datef, strtotime( $comment->comment_date ) );
<div id="major-publishing-actions">
<div id="delete-action">
<?php echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=deletecomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "'>" . __('Move to Trash') . "</a>\n"; ?>
<?php echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=trashcomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'trash-comment_' . $comment->comment_ID) . "'>" . __('Move to Trash') . "</a>\n"; ?>
</div>
<div id="publishing-action">
<input type="submit" name="save" value="<?php esc_attr_e('Update Comment'); ?>" tabindex="4" class="button-primary" />

View File

@ -1062,9 +1062,12 @@ function get_media_items( $post_id, $errors ) {
}
$output = '';
foreach ( (array) $attachments as $id => $attachment )
foreach ( (array) $attachments as $id => $attachment ) {
if ( $attachment->post_status == 'trash' )
continue;
if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>";
}
return $output;
}
@ -1166,11 +1169,11 @@ function get_media_item( $attachment_id, $args = null ) {
'extra_rows' => array(),
);
$delete_href = wp_nonce_url("post.php?action=trash&amp;post=$attachment_id", 'delete-post_' . $attachment_id);
$delete_href = wp_nonce_url("post.php?action=trash&amp;post=$attachment_id", 'trash-post_' . $attachment_id);
if ( $send )
$send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . esc_attr__( 'Insert into Post' ) . "' />";
if ( $delete )
$delete = "<a href=\"$delete_href\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Move to Trash') . "</a>";
$delete = current_user_can('delete_post', $attachment_id) ? "<a href=\"$delete_href\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Move to Trash') . "</a>" : "";
if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
$form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete</td></tr>\n");

View File

@ -1439,9 +1439,11 @@ function _post_row($a_post, $pending_comments, $mode) {
the_excerpt();
$actions = array();
if ( 'trash' == $post->post_status && current_user_can('delete_post', $post->ID) ) {
$actions['untrash'] = "<a title='" . esc_attr(__('Remove this post from the Trash')) . "' href='" . wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID) . "'>" . __('Restore') . "</a>";
$actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this post permanently')) . "' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "'>" . __('Delete Permanently') . "</a>";
if ('trash' == $post->post_status) {
if ( current_user_can('delete_post', $post->ID) ) {
$actions['untrash'] = "<a title='" . esc_attr(__('Restore this post from the Trash')) . "' href='" . wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID) . "'>" . __('Restore') . "</a>";
$actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this post permanently')) . "' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "'>" . __('Delete Permanently') . "</a>";
}
} else {
if ( current_user_can('edit_post', $post->ID) ) {
$actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this post')) . '">' . __('Edit') . '</a>';

View File

@ -321,7 +321,7 @@ foreach ($arc_result as $arc_row) {
<?php if ( isset($_GET['detached']) ) { ?>
<input type="submit" id="find_detached" name="find_detached" value="<?php esc_attr_e('Scan for lost attachments'); ?>" class="button-secondary" />
<?php } elseif ( isset($_GET['status']) && $_GET['status'] == 'trash' ) { ?>
<?php } elseif ( isset($_GET['status']) && $_GET['status'] == 'trash' && current_user_can('edit_others_posts') ) { ?>
<input type="submit" id="delete_all" name="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
<?php } ?>
@ -362,7 +362,7 @@ foreach ($arc_result as $arc_row) {
$att_title = esc_html( _draft_or_post_title($post->ID) );
?>
<tr id='post-<?php echo $post->ID; ?>' class='<?php echo $class; ?>' valign="top">
<th scope="row" class="check-column"><input type="checkbox" name="media[]" value="<?php echo esc_attr($post->ID); ?>" /></th>
<th scope="row" class="check-column"><?php if ( current_user_can('edit_post', $post->ID) ) { ?><input type="checkbox" name="media[]" value="<?php echo esc_attr($post->ID); ?>" /><?php } ?></th>
<td class="media-icon"><?php
if ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) { ?>
@ -446,7 +446,7 @@ if ( $page_links )
</select>
<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
<?php if ( isset($_GET['status']) && $_GET['status'] == 'trash' ) { ?>
<?php if ( isset($_GET['status']) && $_GET['status'] == 'trash' && current_user_can('edit_others_posts') ) { ?>
<input type="submit" id="delete_all2" name="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
<?php } ?>
</div>

View File

@ -827,11 +827,16 @@ function map_meta_cap( $cap, $user_id ) {
// If the user is the author...
if ( $user_id == $post_author_data->ID ) {
// If the post is published...
if ( 'publish' == $post->post_status )
if ( 'publish' == $post->post_status ) {
$caps[] = 'edit_published_posts';
else
} elseif ( 'trash' == $post->post_status ) {
$trash_meta = get_option('wp_trash_meta');
if ( is_array($trash_meta) && isset($trash_meta['posts'][$post->ID]['status']) && $trash_meta['posts'][$post->ID]['status'] == 'publish' )
$caps[] = 'edit_published_posts';
} else {
// If the post is draft...
$caps[] = 'edit_posts';
}
} else {
// The user is trying to edit someone else's post.
$caps[] = 'edit_others_posts';
@ -851,11 +856,16 @@ function map_meta_cap( $cap, $user_id ) {
// If the user is the author...
if ( $user_id == $page_author_data->ID ) {
// If the page is published...
if ( 'publish' == $page->post_status )
if ( 'publish' == $page->post_status ) {
$caps[] = 'edit_published_pages';
else
} elseif ( 'trash' == $page->post_status ) {
$trash_meta = get_option('wp_trash_meta');
if ( is_array($trash_meta) && isset($trash_meta['posts'][$page->ID]['status']) && $trash_meta['posts'][$page->ID]['status'] == 'publish' )
$caps[] = 'edit_published_pages';
} else {
// If the page is draft...
$caps[] = 'edit_pages';
}
} else {
// The user is trying to edit someone else's page.
$caps[] = 'edit_others_pages';

View File

@ -78,7 +78,7 @@ function prepareMediaItemInit(fileObj) {
// Tell the server to delete it. TODO: handle exceptions
jQuery.ajax({url:'admin-ajax.php',type:'post',success:deleteSuccess,error:deleteError,id:fileObj.id,data:{
id : this.id.replace(/[^0-9]/g,''),
action : 'delete-post',
action : 'trash-post',
_ajax_nonce : this.href.replace(/^.*wpnonce=/,'')}
});
return false;

File diff suppressed because one or more lines are too long

View File

@ -1264,7 +1264,7 @@ function wp_untrash_post($postid = 0) {
do_action('untrash_post', $postid);
$post['post_status'] = 'draft';
$post['post_status'] = ($post->post_type == 'attachment') ? 'inherit' : 'draft';
$trash_meta = get_option('wp_trash_meta');
if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) {

View File

@ -186,7 +186,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'swfupload-all', '/wp-includes/js/swfupload/swfupload-all.js', array(), '2201');
}
$scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20090515');
$scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20090818');
// these error messages came from the sample swfupload js, they might need changing.
$scripts->localize( 'swfupload-handlers', 'swfuploadL10n', array(
'queue_limit_exceeded' => __('You have attempted to queue too many files.'),