Make WordPress Core

Changeset 5118


Ignore:
Timestamp:
03/27/2007 09:20:16 PM (18 years ago)
Author:
ryan
Message:

Dynamically refill comment list when a comment is deleted. Props mdawaffe. fixes #4038

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r5089 r5118  
    150150        'supplemental' => array('name' => $cat_full_name, 'show-link' => sprintf(__( 'Category <a href="#%s">%s</a> added' ), "cat-$cat->cat_ID", $cat_full_name))
    151151    ) );
     152    $x->send();
     153    break;
     154case 'add-comment' :
     155    if ( !current_user_can( 'edit_post', $id ) )
     156        die('-1');
     157    $search = isset($_POST['s']) ? $_POST['s'] : false;
     158    $start = isset($_POST['page']) ? intval($_POST['page']) * 25 : 25;
     159
     160    list($comments, $total) = _wp_get_comment_list( $search, $start, 1 );
     161
     162    if ( !$comments )
     163        die('1');
     164    $x = new WP_Ajax_Response();
     165    foreach ( (array) $comments as $comment ) {
     166        get_comment( $comment );
     167        ob_start();
     168            _wp_comment_list_item( $comment->comment_ID );
     169            $comment_list_item = ob_get_contents();
     170        ob_end_clean();
     171        $x->add( array(
     172            'what' => 'comment',
     173            'id' => $comment->comment_ID,
     174            'data' => $comment_list_item
     175        ) );
     176    }
    152177    $x->send();
    153178    break;
  • trunk/wp-admin/admin-functions.php

    r5110 r5118  
    908908    $r .= "</td>\n\t</tr>";
    909909    return $r;
     910}
     911
     912function _wp_get_comment_list( $s = false, $start, $num ) {
     913    global $wpdb;
     914
     915    $start = (int) $start;
     916    $num = (int) $num;
     917
     918    if ( $s ) {
     919        $s = $wpdb->escape($s);
     920        $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
     921            (comment_author LIKE '%$s%' OR
     922            comment_author_email LIKE '%$s%' OR
     923            comment_author_url LIKE ('%$s%') OR
     924            comment_author_IP LIKE ('%$s%') OR
     925            comment_content LIKE ('%$s%') ) AND
     926            comment_approved != 'spam'
     927            ORDER BY comment_date DESC LIMIT $start, $num");
     928    } else {
     929        $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $num" );
     930    }
     931
     932    $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
     933
     934    return array($comments, $total);
     935}
     936
     937function _wp_comment_list_item( $id, $alt = 0 ) {
     938    global $authordata, $comment, $wpdb;
     939    $id = (int) $id;
     940    $comment =& get_comment( $id );
     941    $class = '';
     942    $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
     943    $comment_status = wp_get_comment_status($comment->comment_ID);
     944    if ( 'unapproved' == $comment_status )
     945        $class .= ' unapproved';
     946    if ( $alt % 2 )
     947        $class .= ' alternate';
     948    echo "<li id='comment-$comment->comment_ID' class='$class'>";
     949?>
     950<p><strong><?php comment_author(); ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
     951
     952<?php comment_text() ?>
     953
     954<p><?php comment_date(__('M j, g:i A'));  ?> &#8212; [
     955<?php
     956if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
     957    echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" .  __('Edit') . '</a>';
     958    echo ' | <a href="' . wp_nonce_url('ocomment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
     959    if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
     960        echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
     961        echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
     962    }
     963    echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author))  . "', theCommentList );\">" . __('Spam') . "</a> ";
     964}
     965$post = get_post($comment->comment_post_ID);
     966$post_title = wp_specialchars( $post->post_title, 'double' );
     967$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
     968?>
     969 ] &#8212; <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p>
     970        </li>
     971<?php
    910972}
    911973
  • trunk/wp-admin/edit-comments.js

    r3847 r5118  
    33    if ( !theCommentList )
    44        return false;
     5
     6    theExtraCommentList = new listMan('the-extra-comment-list');
     7    if ( theExtraCommentList ) {
     8        theExtraCommentList.showLink = 0;
     9        theExtraCommentList.altOffset = 1;
     10        if ( theExtraCommentList.theList && theExtraCommentList.theList.childNodes )
     11            var commentNum = $A(theExtraCommentList.theList.childNodes).findAll( function(i) { return Element.visible(i) } ).length;
     12        else
     13            var commentNum = 0;
     14        var urlQ   = document.location.href.split('?');
     15        var params = urlQ[1] ? urlQ[1].toQueryParams() : [];
     16        var search = params['s'] ? params['s'] : '';
     17        var page   = params['apage'] ? params['apage'] : 1;
     18    }
     19
    520    theCommentList.dimComplete = function(what,id,dimClass) {
    621        var m = document.getElementById('awaitmod');
    7         if ( document.getElementById(what + '-' + id).className.match(dimClass) ) m.innerHTML = parseInt(m.innerHTML,10) + 1;
    8         else m.innerHTML = parseInt(m.innerHTML,10) - 1;
     22        if ( document.getElementById(what + '-' + id).className.match(dimClass) )
     23            m.innerHTML = parseInt(m.innerHTML,10) + 1;
     24        else
     25            m.innerHTML = parseInt(m.innerHTML,10) - 1;
    926    }
     27
    1028    theCommentList.delComplete = function(what,id) {
    1129        var m = document.getElementById('awaitmod');
    12         if ( document.getElementById(what + '-' + id).className.match('unapproved') ) m.innerHTML = parseInt(m.innerHTML,10) - 1;
     30        if ( document.getElementById(what + '-' + id).className.match('unapproved') )
     31            m.innerHTML = parseInt(m.innerHTML,10) - 1;
     32        if ( theExtraCommentList && commentNum ) {
     33            var theMover = theExtraCommentList.theList.childNodes[0];
     34            Element.removeClassName(theMover,'alternate');
     35            theCommentList.theList.appendChild(theMover);
     36            theExtraCommentList.inputData += '&page=' + page;
     37            if ( search )
     38                theExtraCommentList.inputData += '&s=' + search; // trust the URL not the search box
     39            theExtraCommentList.addComplete = function() {
     40                if ( theExtraCommentList.theList.childNodes )
     41                    var commentNum = $A(theExtraCommentList.theList.childNodes).findAll( function(i) { return Element.visible(i) } ).length;
     42                else
     43                    var commentNum = 0;
     44            }
     45            theExtraCommentList.ajaxAdder( 'comment', 'ajax-response' ); // Dummy Request
     46        }
    1347    }
     48
    1449    if ( theList ) // the post list: edit.php
    1550        theList.delComplete = function() {
  • trunk/wp-admin/edit-comments.php

    r5087 r5118  
    7676endif;
    7777
    78 if (isset($_GET['s'])) {
    79     $s = $wpdb->escape($_GET['s']);
    80     $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments  WHERE
    81         (comment_author LIKE '%$s%' OR
    82         comment_author_email LIKE '%$s%' OR
    83         comment_author_url LIKE ('%$s%') OR
    84         comment_author_IP LIKE ('%$s%') OR
    85         comment_content LIKE ('%$s%') ) AND
    86         comment_approved != 'spam'
    87         ORDER BY comment_date DESC");
    88 } else {
    89     if ( isset( $_GET['apage'] ) )
    90         $page = (int) $_GET['apage'];
    91     else
    92         $page = 1;
    93     $start = $offset = ( $page - 1 ) * 20;
    94 
    95     $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, 20" );
    96     $total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1'" );
    97 }
    98 ?>
    99 <?php if ( $total > 20 ) {
    100 $total_pages = ceil( $total / 20 );
    101 $r = '';
    102 if ( 1 < $page ) {
    103     $args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
    104     $r .=  '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">&laquo; '. __('Previous Page') .'</a>' . "\n";
    105 }
    106 if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
    107     for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
    108         if ( $page == $page_num ) :
    109             $r .=  "<span>$page_num</span>\n";
    110         else :
    111             $p = false;
    112             if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
    113                 $args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
    114                 $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
    115                 $in = true;
    116             elseif ( $in == true ) :
    117                 $r .= "...\n";
    118                 $in = false;
    119             endif;
    120         endif;
    121     endfor;
    122 }
    123 if ( ( $page ) * 20 < $total || -1 == $total ) {
    124     $args['apage'] = $page + 1;
    125     $r .=  '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page') .' &raquo;</a>' . "\n";
    126 }
    127 echo "<p class='pagenav'>$r</p>";
    128 ?>
    129 
    130 <?php } ?>
    131 
    132 <?php
     78if ( isset( $_GET['apage'] ) )
     79    $page = (int) $_GET['apage'];
     80else
     81    $page = 1;
     82$start = $offset = ( $page - 1 ) * 20;
     83
     84list($_comments, $total) = _wp_get_comment_list( isset($_GET['s']) ? $_GET['s'] : false, $start, 25 ); // Grab a few extra
     85
     86$comments = array_slice($_comments, 0, 20);
     87$extra_comments = array_slice($_comments, 20);
     88
     89$page_links = paginate_links( array(
     90    'base' => clean_url( add_query_arg( 'apage', '%#%' ) ),
     91    'format' => '',
     92    'total' => ceil($total / 20),
     93    'current' => $page
     94));
     95
     96if ( $page_links )
     97    echo "<p class='pagenav'>$page_links</p>";
     98
    13399if ('view' == $mode) {
    134100    if ($comments) {
    135 ?>
    136 <?php
    137 $offset = $offset + 1;
    138 $start = " start='$offset'";
    139 
    140         echo "<ol id='the-comment-list' class='commentlist' $start>";
     101        $offset = $offset + 1;
     102        $start = " start='$offset'";
     103
     104        echo "<ol id='the-comment-list' class='commentlist' $start>\n";
    141105        $i = 0;
    142         foreach ($comments as $comment) {
    143         ++$i; $class = '';
    144         $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID"));
    145             $comment_status = wp_get_comment_status($comment->comment_ID);
    146             if ('unapproved' == $comment_status)
    147                 $class .= ' unapproved';
    148             if ($i % 2)
    149                 $class .= ' alternate';
    150             echo "<li id='comment-$comment->comment_ID' class='$class'>";
    151 ?>
    152 <p><strong><?php comment_author() ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
    153 
    154 <?php comment_text() ?>
    155 
    156 <p><?php comment_date(__('M j, g:i A'));  ?> &#8212; [
    157 <?php
    158 if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
    159     echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" .  __('Edit') . '</a>';
    160     echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
    161     if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
    162         echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
    163         echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
    164     }
    165     echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author))  . "', theCommentList );\">" . __('Spam') . "</a> ";
    166 }
    167 $post = get_post($comment->comment_post_ID);
    168 $post_title = wp_specialchars( $post->post_title, 'double' );
    169 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
    170 ?>
    171  ] &#8212; <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p>
    172         </li>
    173 
    174 <?php } // end foreach($comment) ?>
    175 </ol>
     106        foreach ( $comments as $comment ) {
     107            get_comment( $comment ); // Cache it
     108            _wp_comment_list_item( $comment->comment_ID, ++$i );
     109        }
     110        echo "</ol>\n\n";
     111
     112if ( $extra_comments ) : ?>
     113<div id="extra-comments" style="display:none">
     114<ul id="the-extra-comment-list" class="commentlist">
     115<?php
     116    foreach ( $extra_comments as $comment ) {
     117        get_comment( $comment ); // Cache it
     118        _wp_comment_list_item( $comment->comment_ID, ++$i );
     119    }
     120?>
     121</ul>
     122</div>
     123<?php endif; // $extra_comments ?>
    176124
    177125<div id="ajax-response"></div>
     
    243191    } // end if ($comments)
    244192}
    245     ?>
    246 <?php if ( $total > 20 ) {
    247 $total_pages = ceil( $total / 20 );
    248 $r = '';
    249 if ( 1 < $page ) {
    250     $args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
    251     $r .=  '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">&laquo; '. __('Previous Page') .'</a>' . "\n";
    252 }
    253 if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
    254     for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
    255         if ( $page == $page_num ) :
    256             $r .=  "<span>$page_num</span>\n";
    257         else :
    258             $p = false;
    259             if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
    260                 $args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
    261                 $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
    262                 $in = true;
    263             elseif ( $in == true ) :
    264                 $r .= "...\n";
    265                 $in = false;
    266             endif;
    267         endif;
    268     endfor;
    269 }
    270 if ( ( $page ) * 20 < $total || -1 == $total ) {
    271     $args['apage'] = $page + 1;
    272     $r .=  '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page') .' &raquo;</a>' . "\n";
    273 }
    274 echo "<p class='pagenav'>$r</p>";
    275 ?>
    276 
    277 <?php } ?>
     193
     194if ( $page_links )
     195    echo "<p class='pagenav'>$page_links</p>";
     196
     197?>
    278198
    279199</div>
  • trunk/wp-includes/script-loader.php

    r5114 r5118  
    3535            'whoaText' => __("Slow down, I'm still sending your data!")
    3636        ) );
    37         $this->add( 'listman', '/wp-includes/js/list-manipulation.js', array('wp-ajax', 'fat'), '20070306');
     37        $this->add( 'listman', '/wp-includes/js/list-manipulation.js', array('wp-ajax', 'fat'), '20070306' );
    3838        $this->localize( 'listman', 'listManL10n', array(
    3939            'jumpText' => __('Jump to new item'),
     
    8585            $this->add( 'admin-categories', '/wp-admin/categories.js', array('listman'), '3684' );
    8686            $this->add( 'admin-custom-fields', '/wp-admin/custom-fields.js', array('listman'), '3733' );
    87             $this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '3847' );
     87            $this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '20070327' );
    8888            $this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '4583' );
    8989            $this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
Note: See TracChangeset for help on using the changeset viewer.