Ticket #15530: 15530.6.diff
| File 15530.6.diff, 6.4 KB (added by , 15 years ago) |
|---|
-
wp-admin/admin-ajax.php
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']; … … 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() ); 205 // Only do the expensive stuff on a page-break, and about 1 other time per page 206 if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) { 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 } 206 217 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']; 218 $comment_count = wp_count_comments($post_id); 219 220 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count 221 $total = $comment_count->$status; 222 // else use the decremented value from above 216 223 } 217 224 218 $comment_count = wp_count_comments($post_id);219 225 $time = time(); // The time since the last comment count 220 226 221 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count222 $total = $comment_count->$status;223 // else use the decremented value from above224 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' => $page232 ) );233 227 $x = new WP_Ajax_Response( array( 234 228 'what' => 'comment', 235 229 'id' => $comment_id, // here for completeness - not used 236 230 'supplemental' => array( 237 'pageLinks' => $page_links, 231 'total_items_i18n' => sprintf( _n( '1 item', '%s items', $total ), number_format_i18n( $total ) ), 232 'total_pages' => ceil( $total / $per_page ), 233 'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ), 238 234 'total' => $total, 239 235 'time' => $time 240 236 ) … … 331 327 check_ajax_referer( "delete-comment_$id" ); 332 328 $status = wp_get_comment_status( $comment->comment_ID ); 333 329 330 $delta = -1; 334 331 if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { 335 332 if ( 'trash' == $status ) 336 333 die( (string) time() ); … … 339 336 if ( 'trash' != $status ) 340 337 die( (string) time() ); 341 338 $r = wp_untrash_comment( $comment->comment_ID ); 339 if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash 340 $delta = 1; 342 341 } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { 343 342 if ( 'spam' == $status ) 344 343 die( (string) time() ); … … 347 346 if ( 'spam' != $status ) 348 347 die( (string) time() ); 349 348 $r = wp_unspam_comment( $comment->comment_ID ); 349 if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam 350 $delta = 1; 350 351 } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { 351 352 $r = wp_delete_comment( $comment->comment_ID ); 352 353 } else { … … 354 355 } 355 356 356 357 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 );358 _wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); 358 359 die( '0' ); 359 360 break; 360 361 case 'delete-tag' : -
wp-admin/js/edit-comments.dev.js
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); … … 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'; … … 192 193 total = 0; 193 194 194 195 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 else199 $('.tablenav-pages').find( '.page-numbers' ).remove();200 196 total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || ''; 197 if ( total_items_i18n ) { 198 $('.displaying-num').text( total_items_i18n ); 199 $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n ); 200 $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val()); 201 } 201 202 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true ); 202 203 } else { 203 204 updateTotalCount( total, r, false );