Ticket #6530: garyc40-6530.patch
File garyc40-6530.patch, 12.5 KB (added by , 14 years ago) |
---|
-
wp-admin/admin-ajax.php
diff --git wp-admin/admin-ajax.php wp-admin/admin-ajax.php index 5eb33e1..963d5f5 100644
endif; 184 184 * @since 2.7 185 185 * 186 186 * @param int $comment_id 187 * @param int $delta How many units should the total post count be increased (or decreased). 187 188 * @return die 188 189 */ 189 function _wp_ajax_delete_comment_response( $comment_id ) {190 function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { 190 191 $total = (int) @$_POST['_total']; 191 192 $per_page = (int) @$_POST['_per_page']; 192 193 $page = (int) @$_POST['_page']; … … function _wp_ajax_delete_comment_response( $comment_id ) { 195 196 if ( !$total || !$per_page || !$page || !$url ) 196 197 die( (string) time() ); 197 198 198 if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one) 199 $total += $delta; 200 if ( $total < 0 ) 199 201 $total = 0; 200 202 201 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 202 die( (string) time() ); 203 204 $post_id = 0; 205 $status = 'total_comments'; // What type of comment count are we looking for? 206 $parsed = parse_url( $url ); 207 if ( isset( $parsed['query'] ) ) { 208 parse_str( $parsed['query'], $query_vars ); 209 if ( !empty( $query_vars['comment_status'] ) ) 210 $status = $query_vars['comment_status']; 211 if ( !empty( $query_vars['p'] ) ) 212 $post_id = (int) $query_vars['p']; 213 } 214 215 $comment_count = wp_count_comments($post_id); 216 $time = time(); // The time since the last comment count 217 218 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count 219 $total = $comment_count->$status; 220 // else use the decremented value from above 221 222 $page_links = paginate_links( array( 223 'base' => add_query_arg( 'apage', '%#%', $url ), 224 'format' => '', 225 'prev_text' => __('«'), 226 'next_text' => __('»'), 227 'total' => ceil($total / $per_page), 228 'current' => $page 229 ) ); 230 $x = new WP_Ajax_Response( array( 203 $response = array( 231 204 'what' => 'comment', 232 205 'id' => $comment_id, // here for completeness - not used 233 206 'supplemental' => array( 234 'pageLinks' => $page_links, 235 'total' => $total, 236 'time' => $time 207 'time' => time(), 208 'l10nTotal' => sprintf( _n( '1 item', '%s items', $total ), number_format_i18n( $total ) ), 237 209 ) 238 ) ); 210 ); 211 212 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 213 214 $post_id = 0; 215 $status = 'total_comments'; // What type of comment count are we looking for? 216 $parsed = parse_url( $url ); 217 if ( isset( $parsed['query'] ) ) { 218 parse_str( $parsed['query'], $query_vars ); 219 if ( !empty( $query_vars['comment_status'] ) ) 220 $status = $query_vars['comment_status']; 221 if ( !empty( $query_vars['p'] ) ) 222 $post_id = (int) $query_vars['p']; 223 } 224 225 $comment_count = wp_count_comments($post_id); 226 227 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count 228 $total = $comment_count->$status; 229 // else use the decremented value from above 230 231 set_current_screen( 'edit-comments' ); 232 $_REQUEST['paged'] = $page; 233 $wp_list_table = get_list_table( 'WP_Comments_List_Table' ); 234 $wp_list_table->set_pagination_args( array( 235 'total_items' => $total, 236 'per_page' => $per_page, 237 ) ); 238 239 ob_start(); 240 $wp_list_table->pagination(); 241 $page_links = ob_get_clean(); 242 $response['supplemental']['pageLinks'] = $page_links; 243 } 244 245 $response['supplemental']['total'] = $total; 246 247 $x = new WP_Ajax_Response( $response ); 239 248 $x->send(); 240 249 } 241 250 … … case 'delete-comment' : // On success, die with time() instead of 1 327 336 328 337 check_ajax_referer( "delete-comment_$id" ); 329 338 $status = wp_get_comment_status( $comment->comment_ID ); 330 339 $delta = -1; 331 340 if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { 332 341 if ( 'trash' == $status ) 333 342 die( (string) time() ); … … case 'delete-comment' : // On success, die with time() instead of 1 336 345 if ( 'trash' != $status ) 337 346 die( (string) time() ); 338 347 $r = wp_untrash_comment( $comment->comment_ID ); 348 if ( $_POST['comment_status'] != 'trash' ) { 349 $delta = 1; 350 } 339 351 } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { 340 352 if ( 'spam' == $status ) 341 353 die( (string) time() ); … … case 'delete-comment' : // On success, die with time() instead of 1 344 356 if ( 'spam' != $status ) 345 357 die( (string) time() ); 346 358 $r = wp_unspam_comment( $comment->comment_ID ); 359 if ( $_POST['comment_status'] != 'spam' ) { 360 $delta = 1; 361 } 347 362 } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { 348 363 $r = wp_delete_comment( $comment->comment_ID ); 349 364 } else { … … case 'delete-comment' : // On success, die with time() instead of 1 351 366 } 352 367 353 368 if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts 354 _wp_ajax_delete_comment_response( $comment->comment_ID );369 _wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); 355 370 die( '0' ); 356 371 break; 357 372 case 'delete-tag' : -
wp-admin/edit-comments.php
diff --git wp-admin/edit-comments.php wp-admin/edit-comments.php index 29e5f03..512d6e0 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-list-table.php
diff --git wp-admin/includes/class-wp-list-table.php wp-admin/includes/class-wp-list-table.php index 2b12888..c5f9c8c 100644
class WP_List_Table { 478 478 $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>'; 479 479 480 480 $current = $this->get_pagenum(); 481 482 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 481 482 if (! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { 483 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 484 } else { 485 $current_url = wp_get_referer(); 486 } 483 487 484 488 $page_links = array(); 485 489 -
wp-admin/js/edit-comments.dev.js
diff --git wp-admin/js/edit-comments.dev.js wp-admin/js/edit-comments.dev.js index 177dc86..cc5e49c 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 ) { 90 var per_page, total_pages; 89 91 if ( time < lastConfidentTime ) 90 92 return; 91 93 … … setCommentsList = function() { 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 $('.tablenav-pages .displaying-num').text(l10nTotal); 99 100 total_pages = Math.ceil(total/perPageInput.val()); 101 if (pageInput.val() > total_pages) { 102 listTable.change_page(total_pages); 103 } 99 104 }; 100 105 101 106 function dashboardTotals(n) { … … setCommentsList = function() { 135 140 } 136 141 n = n + n1; 137 142 } 143 138 144 el.html(n); 139 145 } 140 146 … … setCommentsList = function() { 185 191 if ( $('#dashboard_right_now').length ) { 186 192 N = trash ? -1 * trash : 0; 187 193 dashboardTotals(N); 188 } 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 ); 194 } else if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { 195 parsedResponse = settings.parsed.responses[0] 196 pageLinks = parsedResponse.supplemental.pageLinks || ''; 197 if ( $.trim( pageLinks ) ) { 198 $('.tablenav-pages').each(function(){ 199 $(this).replaceWith($(pageLinks)); 200 }); 204 201 } 202 203 updateTotalCount( parsedResponse.supplemental.total, parsedResponse.supplemental.time, true, parsedResponse.supplemental.l10nTotal ); 205 204 } 206 205 207 206 … … setCommentsList = function() { 246 245 if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 ) 247 246 $('#undo-' + id).fadeIn(300, function(){ $(this).show() }); 248 247 }); 249 $(listTable).bind('changePage', refillTheExtraList); 248 $(listTable).bind('changePage', function(paged){ 249 pageInput.val(paged); 250 refillTheExtraList(true); 251 }); 250 252 }; 251 253 252 254 commentReply = { -
wp-admin/js/list-table.dev.js
diff --git wp-admin/js/list-table.dev.js wp-admin/js/list-table.dev.js index 7d94ad2..f756210 100644
window.listTable = { 133 133 this.loading = false; 134 134 135 135 $('.list-ajax-loading').css('visibility', 'hidden'); 136 } 137 } 138 139 listTable.init(); 140 141 // Ajaxify various UI elements 142 143 function change_page(paged, $el) { 136 }, 137 138 change_page: function(paged, $el) { 144 139 if ( paged < 1 ) 145 140 paged = 1; 146 141 147 if ( paged > listTable.get_total_pages() )148 paged = listTable.get_total_pages();142 if ( paged > this.get_total_pages() ) 143 paged = this.get_total_pages(); 149 144 150 $( listTable).trigger('beforeChangePage');151 listTable.update_rows({'paged': paged}, false, function() {145 $(this).trigger('beforeChangePage'); 146 this.update_rows({'paged': paged}, false, function() { 152 147 if ( $el.parents('.tablenav.bottom').length ) 153 148 scrollTo(0, 0); 154 149 155 $( listTable).trigger('changePage');150 $(this).trigger('changePage', [paged]); 156 151 }); 157 152 } 153 } 154 155 listTable.init(); 156 157 // Ajaxify various UI elements 158 158 159 159 // pagination 160 $('.tablenav-pages a'). click(function() {160 $('.tablenav-pages a').live('click', function() { 161 161 var $el = $(this), 162 162 paged = $.query.GET('paged'); 163 163 … … listTable.init(); 176 176 break; 177 177 } 178 178 179 change_page(paged, $el);179 listTable.change_page(paged, $el); 180 180 181 181 return false; 182 182 }); … … listTable.init(); 187 187 188 188 var $el = $(this); 189 189 190 change_page(parseInt($el.val()) || 1, $el);190 listTable.change_page(parseInt($el.val()) || 1, $el); 191 191 192 192 return false; 193 193 });