Ticket #15530: garyc40.15530.diff
| File garyc40.15530.diff, 8.6 KB (added by , 15 years ago) |
|---|
-
wp-admin/admin-ajax.php
diff --git wp-admin/admin-ajax.php wp-admin/admin-ajax.php index d5a0d1e..968b069 100644
endif; 189 189 * @param int $comment_id 190 190 * @return die 191 191 */ 192 function _wp_ajax_delete_comment_response( $comment_id ) {192 function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { 193 193 $total = (int) @$_POST['_total']; 194 194 $per_page = (int) @$_POST['_per_page']; 195 195 $page = (int) @$_POST['_page']; … … function _wp_ajax_delete_comment_response( $comment_id ) { 198 198 if ( !$total || !$per_page || !$page || !$url ) 199 199 die( (string) time() ); 200 200 201 if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one) 201 $total += $delta; 202 if ( $total < 0 ) 202 203 $total = 0; 203 204 204 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 205 die( (string) time() ); 206 207 $post_id = 0; 208 $status = 'total_comments'; // What type of comment count are we looking for? 209 $parsed = parse_url( $url ); 210 if ( isset( $parsed['query'] ) ) { 211 parse_str( $parsed['query'], $query_vars ); 212 if ( !empty( $query_vars['comment_status'] ) ) 213 $status = $query_vars['comment_status']; 214 if ( !empty( $query_vars['p'] ) ) 215 $post_id = (int) $query_vars['p']; 216 } 217 218 $comment_count = wp_count_comments($post_id); 219 $time = time(); // The time since the last comment count 220 221 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count 222 $total = $comment_count->$status; 223 // else use the decremented value from above 224 225 $page_links = paginate_links( array( 226 'base' => add_query_arg( 'apage', '%#%', $url ), 227 'format' => '', 228 'prev_text' => __('«'), 229 'next_text' => __('»'), 230 'total' => ceil($total / $per_page), 231 'current' => $page 232 ) ); 233 $x = new WP_Ajax_Response( array( 205 $response = array( 234 206 'what' => 'comment', 235 207 'id' => $comment_id, // here for completeness - not used 236 208 'supplemental' => array( 237 'pageLinks' => $page_links, 209 'time' => time(), 210 'l10nTotal' => sprintf( _n( '1 item', '%s items', $total ), number_format_i18n( $total ) ), 238 211 'total' => $total, 239 'time' => $time 240 ) 241 ) ); 212 ), 213 ); 214 215 // TODO: determine if pagination links need to be updated in case total number of pages change 216 217 $x = new WP_Ajax_Response( $response ); 218 242 219 $x->send(); 243 220 } 244 221 … … case 'delete-comment' : // On success, die with time() instead of 1 330 307 331 308 check_ajax_referer( "delete-comment_$id" ); 332 309 $status = wp_get_comment_status( $comment->comment_ID ); 333 310 311 $delta = -1; 334 312 if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { 335 313 if ( 'trash' == $status ) 336 314 die( (string) time() ); … … case 'delete-comment' : // On success, die with time() instead of 1 339 317 if ( 'trash' != $status ) 340 318 die( (string) time() ); 341 319 $r = wp_untrash_comment( $comment->comment_ID ); 320 if ( $_POST['comment_status'] != 'trash' ) //undo trash 321 $delta = 1; 342 322 } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { 343 323 if ( 'spam' == $status ) 344 324 die( (string) time() ); … … case 'delete-comment' : // On success, die with time() instead of 1 347 327 if ( 'spam' != $status ) 348 328 die( (string) time() ); 349 329 $r = wp_unspam_comment( $comment->comment_ID ); 330 if ( $_POST['comment_status'] != 'spam' ) // undo spam 331 $delta = 1; 350 332 } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { 351 333 $r = wp_delete_comment( $comment->comment_ID ); 352 334 } else { … … case 'delete-comment' : // On success, die with time() instead of 1 354 336 } 355 337 356 338 if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts 357 _wp_ajax_delete_comment_response( $comment->comment_ID );339 _wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); 358 340 die( '0' ); 359 341 break; 360 342 case 'delete-tag' : -
wp-admin/edit-comments.php
diff --git wp-admin/edit-comments.php wp-admin/edit-comments.php index 269dbff..97b7013 100644
if ( isset($_REQUEST['approved']) || isset($_REQUEST['deleted']) || isset($_REQU 228 228 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" /> 229 229 <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" /> 230 230 231 <input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('total_items') ); ?>" />232 <input type="hidden" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('per_page') ); ?>" />233 <input type="hidden" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('page') ); ?>" />231 <input type="hidden" autocomplete="off" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('total_items') ); ?>" /> 232 <input type="hidden" autocomplete="off" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('per_page') ); ?>" /> 233 <input type="hidden" autocomplete="off" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('page') ); ?>" /> 234 234 235 235 <?php if ( isset($_REQUEST['paged']) ) { ?> 236 236 <input type="hidden" name="paged" value="<?php echo esc_attr( absint( $_REQUEST['paged'] ) ); ?>" /> -
wp-admin/js/edit-comments.dev.js
diff --git wp-admin/js/edit-comments.dev.js wp-admin/js/edit-comments.dev.js index 5ca2fb6..bf5728f 100644
var theList, theExtraList, toggleWithKeyboard = false; 4 4 setCommentsList = function() { 5 5 var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter; 6 6 7 totalInput = $(' .tablenavinput[name="_total"]', '#comments-form');8 perPageInput = $(' .tablenavinput[name="_per_page"]', '#comments-form');9 pageInput = $(' .tablenavinput[name="_page"]', '#comments-form');7 totalInput = $('input[name="_total"]', '#comments-form'); 8 perPageInput = $('input[name="_per_page"]', '#comments-form'); 9 pageInput = $('input[name="_page"]', '#comments-form'); 10 10 11 11 dimAfter = function( r, settings ) { 12 12 var c = $('#' + settings.element); … … setCommentsList = function() { 38 38 settings.data._per_page = perPageInput.val() || 0; 39 39 settings.data._page = pageInput.val() || 0; 40 40 settings.data._url = document.location.href; 41 settings.data.comment_status = $('input[name=comment_status]', '#comments-form').val(); 41 42 42 43 if ( cl.indexOf(':trash=1') != -1 ) 43 44 action = 'trash'; … … setCommentsList = function() { 85 86 }; 86 87 87 88 // Updates the current total (as displayed visibly) 88 updateTotalCount = function( total, time, setConfidentTime ) {89 updateTotalCount = function( total, time, setConfidentTime, l10nTotal ) { 89 90 if ( time < lastConfidentTime ) 90 91 return; 91 92 … … setCommentsList = function() { 93 94 lastConfidentTime = time; 94 95 95 96 totalInput.val( total.toString() ); 96 $('span.total-type-count').each( function() { 97 updateCount( $(this), total ); 98 }); 97 $('span.displaying-num').text(l10nTotal); 99 98 }; 100 99 101 100 function dashboardTotals(n) { … … setCommentsList = function() { 138 137 el.html(n); 139 138 } 140 139 141 // In admin-ajax.php, we send back the unix time stamp instead of 1on success140 // In admin-ajax.php, we send back the unix time stamp as well as localized total items on success 142 141 delAfter = function( r, settings ) { 143 142 var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), spam, trash; 144 143 … … setCommentsList = function() { 186 185 N = trash ? -1 * trash : 0; 187 186 dashboardTotals(N); 188 187 } else { 189 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; 190 total = total - spam - trash; 191 if ( total < 0 ) 192 total = 0; 193 194 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { 195 pageLinks = settings.parsed.responses[0].supplemental.pageLinks || ''; 196 if ( $.trim( pageLinks ) ) 197 $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) ); 198 else 199 $('.tablenav-pages').find( '.page-numbers' ).remove(); 200 201 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true ); 202 } else { 203 updateTotalCount( total, r, false ); 188 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { 189 parsedResponse = settings.parsed.responses[0]; 190 updateTotalCount( parsedResponse.supplemental.total, parsedResponse.supplemental.time, true, parsedResponse.supplemental.l10nTotal ); 204 191 } 205 192 } 206 193 207 208 194 if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) { 209 195 return; 210 196 }