WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/11/2010 09:54:51 PM (10 years ago)
Author:
scribu
Message:

Ajaxify list-type screens in the admin. See #14579

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-comments.php

    r15132 r15491  
    1313    wp_die(__('Cheatin’ uh?'));
    1414
    15 wp_enqueue_script('admin-comments');
    16 enqueue_comment_hotkeys_js();
    17 
    18 $post_id = isset($_REQUEST['p']) ? (int) $_REQUEST['p'] : 0;
    19 
    20 if ( isset($_REQUEST['doaction']) ||  isset($_REQUEST['doaction2']) || isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) ) {
    21     check_admin_referer('bulk-comments');
    22 
    23     if ( (isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2'])) && !empty($_REQUEST['pagegen_timestamp']) ) {
    24         $comment_status = $wpdb->escape($_REQUEST['comment_status']);
    25         $delete_time = $wpdb->escape($_REQUEST['pagegen_timestamp']);
     15if ( isset( $_REQUEST['doaction'] ) ||  isset( $_REQUEST['doaction2'] ) || isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
     16    check_admin_referer( 'bulk-comments' );
     17
     18    if ( ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
     19        $comment_status = $wpdb->escape( $_REQUEST['comment_status'] );
     20        $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] );
    2621        $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" );
    2722        $doaction = 'delete';
    28     } elseif ( ($_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1) && isset($_REQUEST['delete_comments']) ) {
     23    } elseif ( ( $_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1 ) && isset( $_REQUEST['delete_comments'] ) ) {
    2924        $comment_ids = $_REQUEST['delete_comments'];
    30         $doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2'];
    31     } elseif ( $_REQUEST['doaction'] == 'undo' && isset($_REQUEST['ids']) ) {
    32         $comment_ids = array_map( 'absint', explode(',', $_REQUEST['ids']) );
     25        $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
     26    } elseif ( $_REQUEST['doaction'] == 'undo' && isset( $_REQUEST['ids'] ) ) {
     27        $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
    3328        $doaction = $_REQUEST['action'];
    3429    } else {
     
    3732
    3833    $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
    39     $redirect_to = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids'), wp_get_referer() );
    40 
    41     foreach ($comment_ids as $comment_id) { // Check the permissions on each
    42         $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) );
    43 
    44         if ( !current_user_can('edit_post', $_post_id) )
     34    $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
     35
     36    foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
     37        $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id ) );
     38
     39        if ( !current_user_can( 'edit_post', $_post_id ) )
    4540            continue;
    4641
    47         switch( $doaction ) {
     42        switch ( $doaction ) {
    4843            case 'approve' :
    49                 wp_set_comment_status($comment_id, 'approve');
     44                wp_set_comment_status( $comment_id, 'approve' );
    5045                $approved++;
    5146                break;
    5247            case 'unapprove' :
    53                 wp_set_comment_status($comment_id, 'hold');
     48                wp_set_comment_status( $comment_id, 'hold' );
    5449                $unapproved++;
    5550                break;
    5651            case 'spam' :
    57                 wp_spam_comment($comment_id);
     52                wp_spam_comment( $comment_id );
    5853                $spammed++;
    5954                break;
    6055            case 'unspam' :
    61                 wp_unspam_comment($comment_id);
     56                wp_unspam_comment( $comment_id );
    6257                $unspammed++;
    6358                break;
    6459            case 'trash' :
    65                 wp_trash_comment($comment_id);
     60                wp_trash_comment( $comment_id );
    6661                $trashed++;
    6762                break;
    6863            case 'untrash' :
    69                 wp_untrash_comment($comment_id);
     64                wp_untrash_comment( $comment_id );
    7065                $untrashed++;
    7166                break;
    7267            case 'delete' :
    73                 wp_delete_comment($comment_id);
     68                wp_delete_comment( $comment_id );
    7469                $deleted++;
    7570                break;
     
    9287        $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
    9388    if ( $trashed || $spammed )
    94         $redirect_to = add_query_arg( 'ids', join(',', $comment_ids), $redirect_to );
     89        $redirect_to = add_query_arg( 'ids', join( ',', $comment_ids ), $redirect_to );
    9590
    9691    wp_redirect( $redirect_to );
    9792    exit;
    98 } elseif ( ! empty($_GET['_wp_http_referer']) ) {
    99      wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
     93} elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
     94     wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) );
    10095     exit;
    10196}
     97
     98require_once( './includes/default-list-tables.php' );
     99
     100$table = new WP_Comments_Table;
     101
     102wp_enqueue_script('admin-comments');
     103enqueue_comment_hotkeys_js();
    102104
    103105if ( $post_id )
     
    119121);
    120122require_once('./admin-header.php');
    121 
    122 $mode = ( empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
    123 
    124 $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
    125 if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'trash')) )
    126     $comment_status = 'all';
    127 
    128 $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
    129 
    130 $search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
    131 $search = esc_attr( $search_dirty ); ?>
     123?>
    132124
    133125<div class="wrap">
    134126<?php screen_icon(); ?>
    135127<h2><?php echo esc_html( $title );
    136 if ( isset($_GET['s']) && $_GET['s'] )
    137     printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( stripslashes( $_GET['s'] ) ), 50 ) ) . '</span>' ); ?>
     128if ( isset($_REQUEST['s']) && $_REQUEST['s'] )
     129    printf( '<span class="subtitle">' . sprintf( __( 'Search results for &#8220;%s&#8221;' ), wp_html_excerpt( esc_html( stripslashes( $_REQUEST['s'] ) ), 50 ) ) . '</span>' ); ?>
    138130</h2>
    139131
    140132<?php
    141 if ( isset( $_GET['error'] ) ) {
    142     $error = (int) $_GET['error'];
     133if ( isset( $_REQUEST['error'] ) ) {
     134    $error = (int) $_REQUEST['error'];
    143135    $error_msg = '';
    144136    switch ( $error ) {
     
    154146}
    155147
    156 if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spammed']) || isset($_GET['unspammed']) || isset($_GET['same']) ) {
    157     $approved  = isset( $_GET['approved']  ) ? (int) $_GET['approved']  : 0;
    158     $deleted   = isset( $_GET['deleted']   ) ? (int) $_GET['deleted']   : 0;
    159     $trashed   = isset( $_GET['trashed']   ) ? (int) $_GET['trashed']   : 0;
    160     $untrashed = isset( $_GET['untrashed'] ) ? (int) $_GET['untrashed'] : 0;
    161     $spammed   = isset( $_GET['spammed']   ) ? (int) $_GET['spammed']   : 0;
    162     $unspammed = isset( $_GET['unspammed'] ) ? (int) $_GET['unspammed'] : 0;
    163     $same      = isset( $_GET['same'] )      ? (int) $_GET['same']      : 0;
     148if ( isset($_REQUEST['approved']) || isset($_REQUEST['deleted']) || isset($_REQUEST['trashed']) || isset($_REQUEST['untrashed']) || isset($_REQUEST['spammed']) || isset($_REQUEST['unspammed']) || isset($_REQUEST['same']) ) {
     149    $approved  = isset( $_REQUEST['approved']  ) ? (int) $_REQUEST['approved']  : 0;
     150    $deleted   = isset( $_REQUEST['deleted']   ) ? (int) $_REQUEST['deleted']   : 0;
     151    $trashed   = isset( $_REQUEST['trashed']   ) ? (int) $_REQUEST['trashed']   : 0;
     152    $untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
     153    $spammed   = isset( $_REQUEST['spammed']   ) ? (int) $_REQUEST['spammed']   : 0;
     154    $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
     155    $same      = isset( $_REQUEST['same'] )      ? (int) $_REQUEST['same']      : 0;
    164156
    165157    if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
     
    168160
    169161        if ( $spammed > 0 ) {
    170             $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
     162            $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
    171163            $messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
    172164        }
     
    176168
    177169        if ( $trashed > 0 ) {
    178             $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
     170            $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
    179171            $messages[] = sprintf( _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
    180172        }
     
    205197?>
    206198
    207 <form id="comments-form" action="" method="get">
     199<form id="comments-form" action="" method="post">
    208200<ul class="subsubsub">
    209201<?php
     
    234226    $link = add_query_arg( 'comment_status', $status, $link );
    235227    if ( $post_id )
    236         $link = add_query_arg( 'p', absint( $post_id ), $link );
     228        $link = add_query_arg( 'post_ID', absint( $post_id ), $link );
    237229    /*
    238230    // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
    239     if ( !empty( $_GET['s'] ) )
    240         $link = add_query_arg( 's', esc_attr( stripslashes( $_GET['s'] ) ), $link );
     231    if ( !empty( $_REQUEST['s'] ) )
     232        $link = add_query_arg( 's', esc_attr( stripslashes( $_REQUEST['s'] ) ), $link );
    241233    */
    242234    $status_links[] = "<li class='$status'><a href='$link'$class>" . sprintf(
     
    259251</p>
    260252
    261 <?php
    262 $comments_per_page = (int) get_user_option( 'edit_comments_per_page' );
    263 if ( empty( $comments_per_page ) || $comments_per_page < 1 )
    264     $comments_per_page = 20;
    265 $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
    266 
    267 if ( isset( $_GET['apage'] ) )
    268     $page = abs( (int) $_GET['apage'] );
    269 else
    270     $page = 1;
    271 
    272 $start = $offset = ( $page - 1 ) * $comments_per_page;
    273 
    274 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 8, $post_id, $comment_type ); // Grab a few extra
    275 
    276 $_comment_post_ids = array();
    277 foreach ( $_comments as $_c ) {
    278     $_comment_post_ids[] = $_c->comment_post_ID;
    279 }
    280 
    281 $_comment_pending_count = get_pending_comments_num($_comment_post_ids);
    282 
    283 $comments = array_slice($_comments, 0, $comments_per_page);
    284 $extra_comments = array_slice($_comments, $comments_per_page);
    285 
    286 $page_links = paginate_links( array(
    287     'base' => add_query_arg( 'apage', '%#%' ),
    288     'format' => '',
    289     'prev_text' => __('&laquo;'),
    290     'next_text' => __('&raquo;'),
    291     'total' => ceil($total / $comments_per_page),
    292     'current' => $page
    293 ));
    294 
    295 ?>
    296 
    297253<input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
    298254<?php if ( $post_id ) : ?>
    299 <input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
     255<input type="hidden" name="post_ID" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
    300256<?php endif; ?>
    301257<input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
    302258<input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
    303259
    304 <div class="tablenav">
    305 
    306 <?php if ( $page_links ) : ?>
    307 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
    308     number_format_i18n( $start + 1 ),
    309     number_format_i18n( min( $page * $comments_per_page, $total ) ),
    310     '<span class="total-type-count">' . number_format_i18n( $total ) . '</span>',
    311     $page_links
    312 ); echo $page_links_text; ?></div>
    313260<input type="hidden" name="_total" value="<?php echo esc_attr($total); ?>" />
    314261<input type="hidden" name="_per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
    315262<input type="hidden" name="_page" value="<?php echo esc_attr($page); ?>" />
    316 <?php endif; ?>
    317 
    318 <?php if ( $comments ) : ?>
    319 <div class="alignleft actions">
    320 <select name="action">
    321 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
    322 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
    323 <option value="unapprove"><?php _e('Unapprove'); ?></option>
    324 <?php endif; ?>
    325 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
    326 <option value="approve"><?php _e('Approve'); ?></option>
    327 <?php endif; ?>
    328 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
    329 <option value="spam"><?php _ex('Mark as Spam', 'comment'); ?></option>
    330 <?php endif; ?>
    331 <?php if ( 'trash' == $comment_status ): ?>
    332 <option value="untrash"><?php _e('Restore'); ?></option>
    333 <?php elseif ( 'spam' == $comment_status ): ?>
    334 <option value="unspam"><?php _ex('Not Spam', 'comment'); ?></option>
    335 <?php endif; ?>
    336 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
    337 <option value="delete"><?php _e('Delete Permanently'); ?></option>
    338 <?php else: ?>
    339 <option value="trash"><?php _e('Move to Trash'); ?></option>
    340 <?php endif; ?>
    341 </select>
    342 <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
    343 <?php wp_nonce_field('bulk-comments'); ?>
    344 
    345 <?php endif; ?>
    346 
    347 <select name="comment_type">
    348     <option value="all"><?php _e('Show all comment types'); ?></option>
    349 <?php
    350     $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
    351         'comment' => __('Comments'),
    352         'pings' => __('Pings'),
    353     ) );
    354 
    355     foreach ( $comment_types as $type => $label ) {
    356         echo "  <option value='" . esc_attr($type) . "'";
    357         selected( $comment_type, $type );
    358         echo ">$label</option>\n";
    359     }
    360 ?>
    361 </select>
    362 <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
    363 
    364 <?php if ( isset($_GET['apage']) ) { ?>
    365     <input type="hidden" name="apage" value="<?php echo esc_attr( absint( $_GET['apage'] ) ); ?>" />
    366 <?php }
    367 
    368 if ( ( 'spam' == $comment_status || 'trash' == $comment_status) && current_user_can ('moderate_comments') ) {
    369     wp_nonce_field('bulk-destroy', '_destroy_nonce');
    370     if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?>
    371         <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
    372 <?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?>
    373         <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
    374 <?php }
    375 } ?>
    376 <?php do_action('manage_comments_nav', $comment_status); ?>
    377 </div>
    378 
    379 <br class="clear" />
    380 
    381 </div>
    382 
    383 <div class="clear"></div>
    384 <?php if ( $comments ) { ?>
    385 
    386 <table class="widefat comments fixed" cellspacing="0">
    387 <thead>
    388     <tr>
    389 <?php print_column_headers('edit-comments'); ?>
    390     </tr>
    391 </thead>
    392 
    393 <tfoot>
    394     <tr>
    395 <?php print_column_headers('edit-comments', false); ?>
    396     </tr>
    397 </tfoot>
    398 
    399 <tbody id="the-comment-list" class="list:comment">
    400 <?php
    401     foreach ($comments as $comment)
    402         _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
    403 ?>
    404 </tbody>
    405 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
    406 <?php
    407     foreach ($extra_comments as $comment)
    408         _wp_comment_row( $comment->comment_ID, $mode, $comment_status );
    409 ?>
    410 </tbody>
    411 </table>
    412 
    413 <div class="tablenav">
    414 <?php
    415 if ( $page_links )
    416     echo "<div class='tablenav-pages'>$page_links_text</div>";
    417 ?>
    418 
    419 <div class="alignleft actions">
    420 <select name="action2">
    421 <option value="-1" selected="selected"><?php _e('Bulk Actions') ?></option>
    422 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
    423 <option value="unapprove"><?php _e('Unapprove'); ?></option>
    424 <?php endif; ?>
    425 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
    426 <option value="approve"><?php _e('Approve'); ?></option>
    427 <?php endif; ?>
    428 <?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
    429 <option value="spam"><?php _ex('Mark as Spam', 'comment'); ?></option>
    430 <?php endif; ?>
    431 <?php if ( 'trash' == $comment_status ): ?>
    432 <option value="untrash"><?php _e('Restore'); ?></option>
    433 <?php endif; ?>
    434 <?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
    435 <option value="delete"><?php _e('Delete Permanently'); ?></option>
    436 <?php elseif ( 'spam' == $comment_status ): ?>
    437 <option value="unspam"><?php _ex('Not Spam', 'comment'); ?></option>
    438 <?php else: ?>
    439 <option value="trash"><?php _e('Move to Trash'); ?></option>
    440 <?php endif; ?>
    441 </select>
    442 <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
    443 
    444 <?php if ( 'spam' == $comment_status && current_user_can('moderate_comments') ) { ?>
    445 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
    446 <?php } elseif ( 'trash' == $comment_status && current_user_can('moderate_comments') ) { ?>
    447 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
     263
     264<?php if ( isset($_REQUEST['paged']) ) { ?>
     265    <input type="hidden" name="paged" value="<?php echo esc_attr( absint( $_REQUEST['paged'] ) ); ?>" />
    448266<?php } ?>
    449 <?php do_action('manage_comments_nav', $comment_status); ?>
    450 </div>
     267
     268<?php if ( $table->has_items() ) { ?>
     269
     270<?php $table->display_table(); ?>
    451271
    452272<br class="clear" />
     
    461281    <input type="hidden" name="page" value="<?php echo esc_attr($page); ?>" />
    462282    <input type="hidden" name="per_page" value="<?php echo esc_attr($comments_per_page); ?>" />
    463     <input type="hidden" name="p" value="<?php echo esc_attr( $post_id ); ?>" />
     283    <input type="hidden" name="post_ID" value="<?php echo esc_attr( $post_id ); ?>" />
    464284    <input type="hidden" name="comment_type" value="<?php echo esc_attr( $comment_type ); ?>" />
    465285    <?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
Note: See TracChangeset for help on using the changeset viewer.