Update counts and pagination when trashing and moderating comments. Props garyc40, koopersmith, mdawaffe, nacin. fixes #15530
git-svn-id: http://svn.automattic.com/wordpress/trunk@17354 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
34358d9a42
commit
862b5e4da7
|
@ -189,7 +189,7 @@ endif;
|
|||
* @param int $comment_id
|
||||
* @return die
|
||||
*/
|
||||
function _wp_ajax_delete_comment_response( $comment_id ) {
|
||||
function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
|
||||
$total = (int) @$_POST['_total'];
|
||||
$per_page = (int) @$_POST['_per_page'];
|
||||
$page = (int) @$_POST['_page'];
|
||||
|
@ -198,43 +198,39 @@ function _wp_ajax_delete_comment_response( $comment_id ) {
|
|||
if ( !$total || !$per_page || !$page || !$url )
|
||||
die( (string) time() );
|
||||
|
||||
if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one)
|
||||
$total += $delta;
|
||||
if ( $total < 0 )
|
||||
$total = 0;
|
||||
|
||||
if ( 0 != $total % $per_page && 1 != mt_rand( 1, $per_page ) ) // Only do the expensive stuff on a page-break, and about 1 other time per page
|
||||
die( (string) time() );
|
||||
// Only do the expensive stuff on a page-break, and about 1 other time per page
|
||||
if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) {
|
||||
$post_id = 0;
|
||||
$status = 'total_comments'; // What type of comment count are we looking for?
|
||||
$parsed = parse_url( $url );
|
||||
if ( isset( $parsed['query'] ) ) {
|
||||
parse_str( $parsed['query'], $query_vars );
|
||||
if ( !empty( $query_vars['comment_status'] ) )
|
||||
$status = $query_vars['comment_status'];
|
||||
if ( !empty( $query_vars['p'] ) )
|
||||
$post_id = (int) $query_vars['p'];
|
||||
}
|
||||
|
||||
$post_id = 0;
|
||||
$status = 'total_comments'; // What type of comment count are we looking for?
|
||||
$parsed = parse_url( $url );
|
||||
if ( isset( $parsed['query'] ) ) {
|
||||
parse_str( $parsed['query'], $query_vars );
|
||||
if ( !empty( $query_vars['comment_status'] ) )
|
||||
$status = $query_vars['comment_status'];
|
||||
if ( !empty( $query_vars['p'] ) )
|
||||
$post_id = (int) $query_vars['p'];
|
||||
$comment_count = wp_count_comments($post_id);
|
||||
|
||||
if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
|
||||
$total = $comment_count->$status;
|
||||
// else use the decremented value from above
|
||||
}
|
||||
|
||||
$comment_count = wp_count_comments($post_id);
|
||||
$time = time(); // The time since the last comment count
|
||||
|
||||
if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
|
||||
$total = $comment_count->$status;
|
||||
// else use the decremented value from above
|
||||
|
||||
$page_links = paginate_links( array(
|
||||
'base' => add_query_arg( 'apage', '%#%', $url ),
|
||||
'format' => '',
|
||||
'prev_text' => __('«'),
|
||||
'next_text' => __('»'),
|
||||
'total' => ceil($total / $per_page),
|
||||
'current' => $page
|
||||
) );
|
||||
$x = new WP_Ajax_Response( array(
|
||||
'what' => 'comment',
|
||||
'id' => $comment_id, // here for completeness - not used
|
||||
'supplemental' => array(
|
||||
'pageLinks' => $page_links,
|
||||
'total_items_i18n' => sprintf( _n( '1 item', '%s items', $total ), number_format_i18n( $total ) ),
|
||||
'total_pages' => ceil( $total / $per_page ),
|
||||
'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
|
||||
'total' => $total,
|
||||
'time' => $time
|
||||
)
|
||||
|
@ -331,6 +327,7 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
|||
check_ajax_referer( "delete-comment_$id" );
|
||||
$status = wp_get_comment_status( $comment->comment_ID );
|
||||
|
||||
$delta = -1;
|
||||
if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
|
||||
if ( 'trash' == $status )
|
||||
die( (string) time() );
|
||||
|
@ -339,6 +336,8 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
|||
if ( 'trash' != $status )
|
||||
die( (string) time() );
|
||||
$r = wp_untrash_comment( $comment->comment_ID );
|
||||
if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash
|
||||
$delta = 1;
|
||||
} elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
|
||||
if ( 'spam' == $status )
|
||||
die( (string) time() );
|
||||
|
@ -347,6 +346,8 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
|||
if ( 'spam' != $status )
|
||||
die( (string) time() );
|
||||
$r = wp_unspam_comment( $comment->comment_ID );
|
||||
if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam
|
||||
$delta = 1;
|
||||
} elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
|
||||
$r = wp_delete_comment( $comment->comment_ID );
|
||||
} else {
|
||||
|
@ -354,7 +355,7 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
|||
}
|
||||
|
||||
if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
|
||||
_wp_ajax_delete_comment_response( $comment->comment_ID );
|
||||
_wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
|
||||
die( '0' );
|
||||
break;
|
||||
case 'delete-tag' :
|
||||
|
|
|
@ -48,6 +48,7 @@ class WP_Comments_List_Table extends WP_List_Table {
|
|||
$comment_status = 'all';
|
||||
|
||||
$comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
|
||||
error_log( var_export( $comment_type, true ) );
|
||||
|
||||
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ var theList, theExtraList, toggleWithKeyboard = false;
|
|||
setCommentsList = function() {
|
||||
var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
|
||||
|
||||
totalInput = $('.tablenav input[name="_total"]', '#comments-form');
|
||||
perPageInput = $('.tablenav input[name="_per_page"]', '#comments-form');
|
||||
pageInput = $('.tablenav input[name="_page"]', '#comments-form');
|
||||
totalInput = $('input[name="_total"]', '#comments-form');
|
||||
perPageInput = $('input[name="_per_page"]', '#comments-form');
|
||||
pageInput = $('input[name="_page"]', '#comments-form');
|
||||
|
||||
dimAfter = function( r, settings ) {
|
||||
var c = $('#' + settings.element);
|
||||
|
@ -38,6 +38,7 @@ setCommentsList = function() {
|
|||
settings.data._per_page = perPageInput.val() || 0;
|
||||
settings.data._page = pageInput.val() || 0;
|
||||
settings.data._url = document.location.href;
|
||||
settings.data.comment_status = $('input[name=comment_status]', '#comments-form').val();
|
||||
|
||||
if ( cl.indexOf(':trash=1') != -1 )
|
||||
action = 'trash';
|
||||
|
@ -192,12 +193,12 @@ setCommentsList = function() {
|
|||
total = 0;
|
||||
|
||||
if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
|
||||
pageLinks = settings.parsed.responses[0].supplemental.pageLinks || '';
|
||||
if ( $.trim( pageLinks ) )
|
||||
$('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) );
|
||||
else
|
||||
$('.tablenav-pages').find( '.page-numbers' ).remove();
|
||||
|
||||
total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
|
||||
if ( total_items_i18n ) {
|
||||
$('.displaying-num').text( total_items_i18n );
|
||||
$('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
|
||||
$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
|
||||
}
|
||||
updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
|
||||
} else {
|
||||
updateTotalCount( total, r, false );
|
||||
|
@ -236,7 +237,11 @@ setCommentsList = function() {
|
|||
args.no_placeholder = true;
|
||||
|
||||
args.paged ++;
|
||||
|
||||
|
||||
// $.query.get() needs some correction to be sent into an ajax request
|
||||
if ( true === args.comment_type )
|
||||
args.comment_type = '';
|
||||
|
||||
args = $.extend(args, {
|
||||
'action': 'fetch-list',
|
||||
'list_args': list_args,
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -299,7 +299,7 @@ function wp_default_scripts( &$scripts ) {
|
|||
$scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20090106' );
|
||||
$scripts->add_data( 'admin-custom-fields', 'group', 1 );
|
||||
|
||||
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags', 'jquery-query'), '20110121b' );
|
||||
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags', 'jquery-query'), '20110122' );
|
||||
$scripts->add_data( 'admin-comments', 'group', 1 );
|
||||
$scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
|
||||
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
|
||||
|
|
Loading…
Reference in New Issue