Make WordPress Core

Ticket #6530: garyc40-6530.patch

File garyc40-6530.patch, 12.5 KB (added by garyc40, 14 years ago)

there's a patch for that

  • wp-admin/admin-ajax.php

    diff --git wp-admin/admin-ajax.php wp-admin/admin-ajax.php
    index 5eb33e1..963d5f5 100644
    endif; 
    184184 * @since 2.7
    185185 *
    186186 * @param int $comment_id
     187 * @param int $delta How many units should the total post count be increased (or decreased).
    187188 * @return die
    188189 */
    189 function _wp_ajax_delete_comment_response( $comment_id ) {
     190function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
    190191        $total = (int) @$_POST['_total'];
    191192        $per_page = (int) @$_POST['_per_page'];
    192193        $page = (int) @$_POST['_page'];
    function _wp_ajax_delete_comment_response( $comment_id ) { 
    195196        if ( !$total || !$per_page || !$page || !$url )
    196197                die( (string) time() );
    197198
    198         if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one)
     199        $total += $delta;
     200        if ( $total < 0 )
    199201                $total = 0;
    200202
    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' => __('&laquo;'),
    226                 'next_text' => __('&raquo;'),
    227                 'total' => ceil($total / $per_page),
    228                 'current' => $page
    229         ) );
    230         $x = new WP_Ajax_Response( array(
     203        $response = array(
    231204                'what' => 'comment',
    232205                'id' => $comment_id, // here for completeness - not used
    233206                '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 ) ),
    237209                )
    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 );
    239248        $x->send();
    240249}
    241250
    case 'delete-comment' : // On success, die with time() instead of 1 
    327336
    328337        check_ajax_referer( "delete-comment_$id" );
    329338        $status = wp_get_comment_status( $comment->comment_ID );
    330 
     339        $delta = -1;
    331340        if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
    332341                if ( 'trash' == $status )
    333342                        die( (string) time() );
    case 'delete-comment' : // On success, die with time() instead of 1 
    336345                if ( 'trash' != $status )
    337346                        die( (string) time() );
    338347                $r = wp_untrash_comment( $comment->comment_ID );
     348                if ( $_POST['comment_status'] != 'trash' ) {
     349                        $delta = 1;
     350                }
    339351        } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
    340352                if ( 'spam' == $status )
    341353                        die( (string) time() );
    case 'delete-comment' : // On success, die with time() instead of 1 
    344356                if ( 'spam' != $status )
    345357                        die( (string) time() );
    346358                $r = wp_unspam_comment( $comment->comment_ID );
     359                if ( $_POST['comment_status'] != 'spam' ) {
     360                        $delta = 1;
     361                }
    347362        } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
    348363                $r = wp_delete_comment( $comment->comment_ID );
    349364        } else {
    case 'delete-comment' : // On success, die with time() instead of 1 
    351366        }
    352367
    353368        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 );
    355370        die( '0' );
    356371        break;
    357372case '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 
    228228<input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
    229229<input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
    230230
    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') ); ?>" />
    234234
    235235<?php if ( isset($_REQUEST['paged']) ) { ?>
    236236        <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 { 
    478478                $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
    479479
    480480                $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                }
    483487
    484488                $page_links = array();
    485489
  • 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; 
    44setCommentsList = function() {
    55        var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
    66
    7         totalInput = $('.tablenav input[name="_total"]', '#comments-form');
    8         perPageInput = $('.tablenav input[name="_per_page"]', '#comments-form');
    9         pageInput = $('.tablenav input[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');
    1010
    1111        dimAfter = function( r, settings ) {
    1212                var c = $('#' + settings.element);
    setCommentsList = function() { 
    3838                settings.data._per_page = perPageInput.val() || 0;
    3939                settings.data._page = pageInput.val() || 0;
    4040                settings.data._url = document.location.href;
     41                settings.data.comment_status = $('input[name=comment_status]', '#comments-form').val();
    4142
    4243                if ( cl.indexOf(':trash=1') != -1 )
    4344                        action = 'trash';
    setCommentsList = function() { 
    8586        };
    8687
    8788        // 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;
    8991                if ( time < lastConfidentTime )
    9092                        return;
    9193
    setCommentsList = function() { 
    9395                        lastConfidentTime = time;
    9496
    9597                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                }
    99104        };
    100105
    101106        function dashboardTotals(n) {
    setCommentsList = function() { 
    135140                        }
    136141                        n = n + n1;
    137142                }
     143
    138144                el.html(n);
    139145        }
    140146
    setCommentsList = function() { 
    185191                if ( $('#dashboard_right_now').length ) {
    186192                        N = trash ? -1 * trash : 0;
    187193                        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                                });
    204201                        }
     202
     203                        updateTotalCount( parsedResponse.supplemental.total, parsedResponse.supplemental.time, true, parsedResponse.supplemental.l10nTotal );
    205204                }
    206205
    207206
    setCommentsList = function() { 
    246245                        if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
    247246                                $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
    248247                });
    249         $(listTable).bind('changePage', refillTheExtraList);
     248        $(listTable).bind('changePage', function(paged){
     249                pageInput.val(paged);
     250                refillTheExtraList(true);
     251        });
    250252};
    251253
    252254commentReply = {
  • 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 = { 
    133133                this.loading = false;
    134134
    135135                $('.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) {
    144139                if ( paged < 1 )
    145140                        paged = 1;
    146141
    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();
    149144
    150                 $(listTable).trigger('beforeChangePage');
    151                 listTable.update_rows({'paged': paged}, false, function() {
     145                $(this).trigger('beforeChangePage');
     146                this.update_rows({'paged': paged}, false, function() {
    152147                        if ( $el.parents('.tablenav.bottom').length )
    153148                                scrollTo(0, 0);
    154149                               
    155                         $(listTable).trigger('changePage');
     150                        $(this).trigger('changePage', [paged]);
    156151                });
    157152        }
     153}
     154
     155listTable.init();
     156
     157// Ajaxify various UI elements
    158158
    159159        // pagination
    160         $('.tablenav-pages a').click(function() {
     160        $('.tablenav-pages a').live('click', function() {
    161161                var $el = $(this),
    162162                        paged = $.query.GET('paged');
    163163
    listTable.init(); 
    176176                                break;
    177177                }
    178178
    179                 change_page(paged, $el);
     179                listTable.change_page(paged, $el);
    180180
    181181                return false;
    182182        });
    listTable.init(); 
    187187
    188188                var $el = $(this);
    189189
    190                 change_page(parseInt($el.val()) || 1, $el);
     190                listTable.change_page(parseInt($el.val()) || 1, $el);
    191191
    192192                return false;
    193193        });