Make WordPress Core

Ticket #8584: 8584.diff

File 8584.diff, 9.1 KB (added by mdawaffe, 17 years ago)
  • wp-includes/script-loader.php

     
    161161                        'strong' => __('Strong'),
    162162                        'l10n_print_after' => 'try{convertEntities(pwsL10n);}catch(e){};'
    163163                ) );
    164                 $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20081210' );
     164                $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20081211' );
    165165                $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
    166166                        'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
    167167                        'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last'])
  • wp-admin/edit-comments.php

     
    227227<div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
    228228        number_format_i18n( $start + 1 ),
    229229        number_format_i18n( min( $page * $comments_per_page, $total ) ),
    230         number_format_i18n( $total ),
     230        '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
    231231        $page_links
    232232); echo $page_links_text; ?></div>
     233<input type="hidden" name="_total" value="<?php echo $total; ?>" />
     234<input type="hidden" name="_per_page" value="<?php echo $comments_per_page; ?>" />
     235<input type="hidden" name="_page" value="<?php echo $page; ?>" />
    233236<?php endif; ?>
    234237
    235238<div class="alignleft actions">
  • wp-admin/admin-ajax.php

     
    6363endswitch;
    6464endif;
    6565
     66/**
     67 * Sends back current comment total and new page links if they need to be updated.
     68 *
     69 * Contrary to normal success AJAX response ("1"), die with time() on success.
     70 *
     71 * @since 2.7
     72 *
     73 * @param int $comment_id
     74 * @return die
     75 */
     76function _wp_ajax_delete_comment_response( $comment_id ) {
     77        $total = (int) @$_POST['_total'];
     78        $per_page = (int) @$_POST['_per_page'];
     79        $page = (int) @$_POST['_page'];
     80        $url = clean_url( @$_POST['_url'], null, 'url' );
     81        // JS didn't send us everything we need to know.  Just die with success message
     82        if ( !$total || !$per_page || !$page || !$url )
     83                die( (string) time() );
     84
     85        if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one)
     86                $total = 0;
     87
     88        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
     89                die( (string) time() );
     90
     91        $status = 'total_comments'; // What type of comment count are we looking for?
     92        $parsed = parse_url( $url );
     93        if ( isset( $parsed['query'] ) ) {
     94                parse_str( $parsed['query'], $query_vars );
     95                if ( !empty( $query_vars['comment_status'] ) )
     96                        $status = $query_vars['comment_status'];
     97        }
     98
     99        $comment_count = wp_count_comments();
     100        $time = time(); // The time since the last comment count
     101
     102        if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
     103                $total = $comment_count->$status;
     104        // else use the decremented value from above
     105
     106        $page_links = paginate_links( array(
     107                'base' => add_query_arg( 'apage', '%#%', $url ),
     108                'format' => '',
     109                'prev_text' => __('&laquo;'),
     110                'next_text' => __('&raquo;'),
     111                'total' => ceil($total / $per_page),
     112                'current' => $page
     113        ) );
     114        $x = new WP_Ajax_Response( array(
     115                'what' => 'comment',
     116                'id' => $comment_id, // here for completeness - not used
     117                'supplemental' => array(
     118                        'pageLinks' => $page_links,
     119                        'total' => $total,
     120                        'time' => $time
     121                )
     122        ) );
     123        $x->send();
     124}
     125
    66126$id = isset($_POST['id'])? (int) $_POST['id'] : 0;
    67127switch ( $action = $_POST['action'] ) :
    68 case 'delete-comment' :
     128case 'delete-comment' : // On success, die with time() instead of 1
    69129        check_ajax_referer( "delete-comment_$id" );
    70130        if ( !$comment = get_comment( $id ) )
    71                 die('1');
     131                die( (string) time() );
    72132        if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
    73133                die('-1');
    74134
    75135        if ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
    76136                if ( 'spam' == wp_get_comment_status( $comment->comment_ID ) )
    77                         die('1');
     137                        die( (string) time() );
    78138                $r = wp_set_comment_status( $comment->comment_ID, 'spam' );
    79139        } else {
    80140                $r = wp_delete_comment( $comment->comment_ID );
    81141        }
    82 
    83         die( $r ? '1' : '0' );
     142        if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
     143                _wp_ajax_delete_comment_response( $comment->comment_ID );
     144        die( '0' );
    84145        break;
    85146case 'delete-cat' :
    86147        check_ajax_referer( "delete-category_$id" );
     
    195256        else
    196257                die('0');
    197258        break;
    198 case 'dim-comment' :
     259case 'dim-comment' : // On success, die with time() instead of 1
    199260        if ( !$comment = get_comment( $id ) )
    200261                die('0');
    201262
     
    206267
    207268        $current = wp_get_comment_status( $comment->comment_ID );
    208269        if ( $_POST['new'] == $current )
    209                 die('1');
     270                die( (string) time() );
    210271
     272        $r = 0;
    211273        if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
    212274                check_ajax_referer( "approve-comment_$id" );
    213275                if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) )
    214                         die('1');
     276                        $r = 1;
    215277        } else {
    216278                check_ajax_referer( "unapprove-comment_$id" );
    217279                if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) )
    218                         die('1');
     280                        $r = 1;
    219281        }
    220         die('0');
     282        if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
     283                _wp_ajax_delete_comment_response( $comment->comment_ID );
     284        die( '0' );
    221285        break;
    222286case 'add-category' : // On the Fly
    223287        check_ajax_referer( $action );
  • wp-admin/js/edit-comments.js

     
    22(function($) {
    33
    44setCommentsList = function() {
     5        var totalInput = $('#comments-form .tablenav :input[name="_total"]');
     6        var perPageInput = $('#comments-form .tablenav :input[name="_per_page"]');
     7        var pageInput = $('#comments-form .tablenav :input[name="_page"]');
     8        var lastConfidentTime = 0;
     9
    510        var dimAfter = function( r, settings ) {
    611                var c = $('#' + settings.element);
    712
     
    2530                });
    2631        };
    2732
     33        // Send current total, page, per_page and url
     34        var delBefore = function( settings ) {
     35                settings.data._total = totalInput.val();
     36                settings.data._per_page = perPageInput.val();
     37                settings.data._page = pageInput.val();
     38                settings.data._url = document.location.href;
     39                return settings;
     40        };
     41
     42        /* Updates the current total (as displayed visibly)
     43        */
     44        var updateTotalCount = function( total, time, setConfidentTime ) {
     45                if ( time < lastConfidentTime ) {
     46                        return;
     47                }
     48                totalInput.val( total.toString() );
     49                if ( setConfidentTime ) {
     50                        lastConfidentTime = time;
     51                }
     52                $('span.total-type-count').each( function() {
     53                        var a = $(this);
     54                        var n = totalInput.val().toString();
     55                        if ( n.length > 3 )
     56                                n = n.substr(0, n.length-3)+' '+n.substr(-3);
     57                        a.html(n);
     58                });
     59
     60        };
     61
     62        // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
    2863        var delAfter = function( r, settings ) {
    2964                $('span.pending-count').each( function() {
    3065                        var a = $(this);
     
    4479                        a.html(n);
    4580                });
    4681
    47                 $('span.spam-count' ).each( function() {
     82                $('span.spam-count').each( function() {
    4883                        var a = $(this);
    4984                        var n = a.html().replace(/[ ,.]+/g, '');
    5085                        n = parseInt(n,10);
     
    6196                        a.html(n);
    6297                });
    6398
     99               
     100                // XML response
     101                if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
     102                        // Set the total to the known good value (even if this value is a little old, newer values should only be a few less, and so shouldn't mess up the page links)
     103                        updateTotalCount( settings.parsed.responses[0].supplemental.total, settings.parsed.responses[0].supplemental.time, true );
     104                        if ( $.trim( settings.parsed.responses[0].supplemental.pageLinks ) ) {
     105                                $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( settings.parsed.responses[0].supplemental.pageLinks ) );
     106                        } else if ( 'undefined' != typeof settings.parsed.responses[0].supplemental.pageLinks ) {
     107                                $('.tablenav-pages').find( '.page-numbers' ).remove();
     108                        }
     109                } else {
     110                        // Decrement the total
     111                        var total = parseInt( totalInput.val(), 10 );
     112                        if ( total-- < 0 )
     113                                total = 0;
     114                        updateTotalCount( total, r, false );
     115                }
     116
    64117                if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 ) {
    65118                        return;
    66119                }
     
    70123        };
    71124
    72125        theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
    73         theList = $('#the-comment-list').wpList( { alt: '', dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } );
     126        theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } );
    74127
    75128};
    76129