Ticket #15530: garyc40.15530.pagination.diff
| File garyc40.15530.pagination.diff, 12.1 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..ea9fc3f 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 $page_gap = ( $delta == 1 ) ? 1 : 0; 216 217 if ( $page_gap == $total % $per_page ) { 218 set_current_screen( 'edit-comments' ); 219 220 $wp_list_table = _get_list_table('WP_Comments_List_Table'); 221 $wp_list_table->prepare_items(); 222 223 $response['supplemental']['pageLinks'] = $wp_list_table->pagination( 'top', false ); 224 $response['supplemental']['pageLinksBottom'] = $wp_list_table->pagination( 'bottom', false ); 225 $response['supplemental']['total_pages'] = number_format_i18n( $wp_list_table->get_pagination_arg( 'total_pages' ) ); 226 } 227 228 $x = new WP_Ajax_Response( $response ); 229 242 230 $x->send(); 243 231 } 244 232 … … case 'delete-comment' : // On success, die with time() instead of 1 330 318 331 319 check_ajax_referer( "delete-comment_$id" ); 332 320 $status = wp_get_comment_status( $comment->comment_ID ); 333 321 322 $delta = -1; 334 323 if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { 335 324 if ( 'trash' == $status ) 336 325 die( (string) time() ); … … case 'delete-comment' : // On success, die with time() instead of 1 339 328 if ( 'trash' != $status ) 340 329 die( (string) time() ); 341 330 $r = wp_untrash_comment( $comment->comment_ID ); 331 if ( $_POST['comment_status'] != 'trash' ) //undo trash 332 $delta = 1; 342 333 } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { 343 334 if ( 'spam' == $status ) 344 335 die( (string) time() ); … … case 'delete-comment' : // On success, die with time() instead of 1 347 338 if ( 'spam' != $status ) 348 339 die( (string) time() ); 349 340 $r = wp_unspam_comment( $comment->comment_ID ); 341 if ( $_POST['comment_status'] != 'spam' ) // undo spam 342 $delta = 1; 350 343 } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { 351 344 $r = wp_delete_comment( $comment->comment_ID ); 352 345 } else { … … case 'delete-comment' : // On success, die with time() instead of 1 354 347 } 355 348 356 349 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 );350 _wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); 358 351 die( '0' ); 359 352 break; 360 353 case 'delete-tag' : -
wp-admin/edit-comments.php
diff --git wp-admin/edit-comments.php wp-admin/edit-comments.php index 40ef4a4..ac3de48 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/includes/class-wp-comments-list-table.php
diff --git wp-admin/includes/class-wp-comments-list-table.php wp-admin/includes/class-wp-comments-list-table.php index 0c34b1d..af35fdc 100644
class WP_Comments_List_Table extends WP_List_Table { 47 47 if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) ) 48 48 $comment_status = 'all'; 49 49 50 $comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : ''; 50 $comment_type = isset( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : ''; 51 if ( ! in_array( $comment_type, array( '', 'pings', 'comment' ) ) ) 52 $comment_type = ''; 51 53 52 54 $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : ''; 53 55 -
wp-admin/includes/class-wp-list-table.php
diff --git wp-admin/includes/class-wp-list-table.php wp-admin/includes/class-wp-list-table.php index 1ece746..2388d58 100644
class WP_List_Table { 467 467 * @since 3.1.0 468 468 * @access protected 469 469 */ 470 function pagination( $which ) { 470 function pagination( $which, $echo = true ) { 471 global $current_screen; 471 472 if ( empty( $this->_pagination_args ) ) 472 return ;473 return ''; 473 474 474 475 extract( $this->_pagination_args ); 475 476 … … class WP_List_Table { 477 478 478 479 $current = $this->get_pagenum(); 479 480 480 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 481 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { 482 $current_url = wp_get_referer(); 483 } else { 484 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 485 } 481 486 482 487 $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url ); 483 488 … … class WP_List_Table { 536 541 537 542 $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>"; 538 543 539 echo $this->_pagination; 544 if ( $echo ) 545 echo $this->_pagination; 546 else 547 return $this->_pagination; 540 548 } 541 549 542 550 /** -
wp-admin/js/edit-comments.dev.js
diff --git wp-admin/js/edit-comments.dev.js wp-admin/js/edit-comments.dev.js index 463c77e..7acae5a 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() { 33 33 // Send current total, page, per_page and url 34 34 delBefore = function( settings, list ) { 35 35 var cl = $(settings.target).attr('className'), id, el, n, h, a, author, action = false; 36 36 37 37 settings.data._total = totalInput.val() || 0; 38 38 settings.data._per_page = perPageInput.val() || 0; 39 settings.data._page = pageInput.val() || 0;39 settings.data._page = settings.data.paged = pageInput.val() || 0; 40 40 settings.data._url = document.location.href; 41 settings.data.comment_status = $('input[name=comment_status]', '#comments-form').val(); 42 settings.data.s = $.query.get('s'); 41 43 42 44 if ( cl.indexOf(':trash=1') != -1 ) 43 45 action = 'trash'; … … setCommentsList = function() { 85 87 }; 86 88 87 89 // Updates the current total (as displayed visibly) 88 updateTotalCount = function( total, time, setConfidentTime ) {90 updateTotalCount = function( total, time, setConfidentTime, l10nTotal ) { 89 91 if ( time < lastConfidentTime ) 90 92 return; 91 93 92 94 if ( setConfidentTime ) 93 95 lastConfidentTime = time; 94 96 95 97 totalInput.val( total.toString() ); 96 $('span.total-type-count').each( function() { 97 updateCount( $(this), total ); 98 }); 98 $('span.displaying-num').text(l10nTotal); 99 99 }; 100 100 101 101 function dashboardTotals(n) { … … setCommentsList = function() { 138 138 el.html(n); 139 139 } 140 140 141 // In admin-ajax.php, we send back the unix time stamp instead of 1on success141 // In admin-ajax.php, we send back the unix time stamp as well as localized total items on success 142 142 delAfter = function( r, settings ) { 143 143 var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), spam, trash; 144 144 … … setCommentsList = function() { 191 191 if ( total < 0 ) 192 192 total = 0; 193 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 ); 194 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { 195 parsedResponse = settings.parsed.responses[0].supplemental; 196 pageLinks = parsedResponse.pageLinks; 197 if (typeof pageLinks !== 'undefined') { 198 if ( $.trim( pageLinks ) ) { 199 $('.top .tablenav-pages').html( pageLinks ); 200 $('.bottom .tablenav-pages').html( parsedResponse.pageLinksBottom ); 201 202 // redirect if there's a new last page 203 if (parsedResponse.total_pages < $.query.get('paged')) 204 window.location = $('.tablenav-pages a.last-page').attr('href'); 205 } else { 206 $('.tablenav-pages').remove(); 207 } 208 } 209 updateTotalCount( parsedResponse.total, parsedResponse.time, true, parsedResponse.l10nTotal ); 204 210 } 205 211 } 206 207 212 208 213 if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) { 209 214 return; 210 215 } … … setCommentsList = function() { 217 222 var refillTheExtraList = function(ev) { 218 223 // var args = $.query.get(), total_pages = listTable.get_total_pages(), per_page = $('input[name=_per_page]', '#comments-form').val(), r; 219 224 var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name=_per_page]', '#comments-form').val(), r; 220 225 221 226 if (! args.paged) 222 227 args.paged = 1; 223 228