mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 17:48:01 +01:00
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
|
* @param int $comment_id
|
||||||
* @return die
|
* @return die
|
||||||
*/
|
*/
|
||||||
function _wp_ajax_delete_comment_response( $comment_id ) {
|
function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
|
||||||
$total = (int) @$_POST['_total'];
|
$total = (int) @$_POST['_total'];
|
||||||
$per_page = (int) @$_POST['_per_page'];
|
$per_page = (int) @$_POST['_per_page'];
|
||||||
$page = (int) @$_POST['_page'];
|
$page = (int) @$_POST['_page'];
|
||||||
@ -198,12 +198,12 @@ function _wp_ajax_delete_comment_response( $comment_id ) {
|
|||||||
if ( !$total || !$per_page || !$page || !$url )
|
if ( !$total || !$per_page || !$page || !$url )
|
||||||
die( (string) time() );
|
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;
|
$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
|
// Only do the expensive stuff on a page-break, and about 1 other time per page
|
||||||
die( (string) time() );
|
if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) {
|
||||||
|
|
||||||
$post_id = 0;
|
$post_id = 0;
|
||||||
$status = 'total_comments'; // What type of comment count are we looking for?
|
$status = 'total_comments'; // What type of comment count are we looking for?
|
||||||
$parsed = parse_url( $url );
|
$parsed = parse_url( $url );
|
||||||
@ -216,25 +216,21 @@ function _wp_ajax_delete_comment_response( $comment_id ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$comment_count = wp_count_comments($post_id);
|
$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
|
if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
|
||||||
$total = $comment_count->$status;
|
$total = $comment_count->$status;
|
||||||
// else use the decremented value from above
|
// else use the decremented value from above
|
||||||
|
}
|
||||||
|
|
||||||
|
$time = time(); // The time since the last comment count
|
||||||
|
|
||||||
$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(
|
$x = new WP_Ajax_Response( array(
|
||||||
'what' => 'comment',
|
'what' => 'comment',
|
||||||
'id' => $comment_id, // here for completeness - not used
|
'id' => $comment_id, // here for completeness - not used
|
||||||
'supplemental' => array(
|
'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,
|
'total' => $total,
|
||||||
'time' => $time
|
'time' => $time
|
||||||
)
|
)
|
||||||
@ -331,6 +327,7 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
|||||||
check_ajax_referer( "delete-comment_$id" );
|
check_ajax_referer( "delete-comment_$id" );
|
||||||
$status = wp_get_comment_status( $comment->comment_ID );
|
$status = wp_get_comment_status( $comment->comment_ID );
|
||||||
|
|
||||||
|
$delta = -1;
|
||||||
if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
|
if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
|
||||||
if ( 'trash' == $status )
|
if ( 'trash' == $status )
|
||||||
die( (string) time() );
|
die( (string) time() );
|
||||||
@ -339,6 +336,8 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
|||||||
if ( 'trash' != $status )
|
if ( 'trash' != $status )
|
||||||
die( (string) time() );
|
die( (string) time() );
|
||||||
$r = wp_untrash_comment( $comment->comment_ID );
|
$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'] ) {
|
} elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
|
||||||
if ( 'spam' == $status )
|
if ( 'spam' == $status )
|
||||||
die( (string) time() );
|
die( (string) time() );
|
||||||
@ -347,6 +346,8 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
|||||||
if ( 'spam' != $status )
|
if ( 'spam' != $status )
|
||||||
die( (string) time() );
|
die( (string) time() );
|
||||||
$r = wp_unspam_comment( $comment->comment_ID );
|
$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'] ) {
|
} elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
|
||||||
$r = wp_delete_comment( $comment->comment_ID );
|
$r = wp_delete_comment( $comment->comment_ID );
|
||||||
} else {
|
} 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
|
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' );
|
die( '0' );
|
||||||
break;
|
break;
|
||||||
case 'delete-tag' :
|
case 'delete-tag' :
|
||||||
|
@ -48,6 +48,7 @@ class WP_Comments_List_Table extends WP_List_Table {
|
|||||||
$comment_status = 'all';
|
$comment_status = 'all';
|
||||||
|
|
||||||
$comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
|
$comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
|
||||||
|
error_log( var_export( $comment_type, true ) );
|
||||||
|
|
||||||
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
|
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@ var theList, theExtraList, toggleWithKeyboard = false;
|
|||||||
setCommentsList = function() {
|
setCommentsList = function() {
|
||||||
var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
|
var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
|
||||||
|
|
||||||
totalInput = $('.tablenav input[name="_total"]', '#comments-form');
|
totalInput = $('input[name="_total"]', '#comments-form');
|
||||||
perPageInput = $('.tablenav input[name="_per_page"]', '#comments-form');
|
perPageInput = $('input[name="_per_page"]', '#comments-form');
|
||||||
pageInput = $('.tablenav input[name="_page"]', '#comments-form');
|
pageInput = $('input[name="_page"]', '#comments-form');
|
||||||
|
|
||||||
dimAfter = function( r, settings ) {
|
dimAfter = function( r, settings ) {
|
||||||
var c = $('#' + settings.element);
|
var c = $('#' + settings.element);
|
||||||
@ -38,6 +38,7 @@ setCommentsList = function() {
|
|||||||
settings.data._per_page = perPageInput.val() || 0;
|
settings.data._per_page = perPageInput.val() || 0;
|
||||||
settings.data._page = pageInput.val() || 0;
|
settings.data._page = pageInput.val() || 0;
|
||||||
settings.data._url = document.location.href;
|
settings.data._url = document.location.href;
|
||||||
|
settings.data.comment_status = $('input[name=comment_status]', '#comments-form').val();
|
||||||
|
|
||||||
if ( cl.indexOf(':trash=1') != -1 )
|
if ( cl.indexOf(':trash=1') != -1 )
|
||||||
action = 'trash';
|
action = 'trash';
|
||||||
@ -192,12 +193,12 @@ setCommentsList = function() {
|
|||||||
total = 0;
|
total = 0;
|
||||||
|
|
||||||
if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
|
if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
|
||||||
pageLinks = settings.parsed.responses[0].supplemental.pageLinks || '';
|
total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
|
||||||
if ( $.trim( pageLinks ) )
|
if ( total_items_i18n ) {
|
||||||
$('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) );
|
$('.displaying-num').text( total_items_i18n );
|
||||||
else
|
$('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
|
||||||
$('.tablenav-pages').find( '.page-numbers' ).remove();
|
$('.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 );
|
updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
|
||||||
} else {
|
} else {
|
||||||
updateTotalCount( total, r, false );
|
updateTotalCount( total, r, false );
|
||||||
@ -237,6 +238,10 @@ setCommentsList = function() {
|
|||||||
|
|
||||||
args.paged ++;
|
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, {
|
args = $.extend(args, {
|
||||||
'action': 'fetch-list',
|
'action': 'fetch-list',
|
||||||
'list_args': list_args,
|
'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( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20090106' );
|
||||||
$scripts->add_data( 'admin-custom-fields', 'group', 1 );
|
$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->add_data( 'admin-comments', 'group', 1 );
|
||||||
$scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
|
$scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
|
||||||
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
|
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
|
||||||
|
Loading…
Reference in New Issue
Block a user