From 56935938b03866bbbf5709435a513f0b091586f7 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Sat, 6 Dec 2008 03:59:03 +0000 Subject: [PATCH] Cron order for single-post Edit Comments page. Remember Single Post when searching, switching comment statuses, and filtering comment types git-svn-id: http://svn.automattic.com/wordpress/trunk@10082 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-comments.php | 43 ++++++++++++++++++++++++---------- wp-admin/includes/template.php | 11 +++++---- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/wp-admin/edit-comments.php b/wp-admin/edit-comments.php index c1e832a16b..c78c66678e 100644 --- a/wp-admin/edit-comments.php +++ b/wp-admin/edit-comments.php @@ -12,13 +12,18 @@ require_once('admin.php'); wp_enqueue_script('admin-comments'); enqueue_comment_hotkeys_js(); +$post_id = isset($_REQUEST['p']) ? (int) $_REQUEST['p'] : 0; + if ( ( isset( $_REQUEST['delete_all_spam'] ) || isset( $_REQUEST['delete_all_spam2'] ) ) && !empty( $_REQUEST['pagegen_timestamp'] ) ) { check_admin_referer('bulk-spam-delete', '_spam_nonce'); $delete_time = $wpdb->escape( $_REQUEST['pagegen_timestamp'] ); $deleted_spam = $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam' AND '$delete_time' > comment_date_gmt" ); - wp_redirect('edit-comments.php?comment_status=spam&deleted=' . (int) $deleted_spam); + $redirect_to = 'edit-comments.php?comment_status=spam&deleted=' . (int) $deleted_spam; + if ( $post_id ) + $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to ); + wp_redirect( $redirect_to ); } elseif ( isset($_REQUEST['delete_comments']) && isset($_REQUEST['action']) && ( -1 != $_REQUEST['action'] || -1 != $_REQUEST['action2'] ) ) { check_admin_referer('bulk-comments'); $doaction = ( -1 != $_REQUEST['action'] ) ? $_REQUEST['action'] : $_REQUEST['action2']; @@ -26,9 +31,9 @@ if ( ( isset( $_REQUEST['delete_all_spam'] ) || isset( $_REQUEST['delete_all_spa $deleted = $approved = $unapproved = $spammed = 0; foreach ( (array) $_REQUEST['delete_comments'] as $comment_id) : // Check the permissions on each $comment_id = (int) $comment_id; - $post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) ); + $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) ); - if ( !current_user_can('edit_post', $post_id) ) + if ( !current_user_can('edit_post', $_post_id) ) continue; switch( $doaction ) { @@ -52,6 +57,8 @@ if ( ( isset( $_REQUEST['delete_all_spam'] ) || isset( $_REQUEST['delete_all_spa endforeach; $redirect_to = 'edit-comments.php?deleted=' . $deleted . '&approved=' . $approved . '&spam=' . $spammed . '&unapproved=' . $unapproved; + if ( $post_id ) + $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to ); if ( isset($_REQUEST['apage']) ) $redirect_to = add_query_arg( 'apage', absint($_REQUEST['apage']), $redirect_to ); if ( !empty($_REQUEST['mode']) ) @@ -66,8 +73,6 @@ if ( ( isset( $_REQUEST['delete_all_spam'] ) || isset( $_REQUEST['delete_all_spa exit; } -$post_id = isset($_GET['p']) ? (int) $_GET['p'] : 0; - if ( $post_id ) $title = sprintf(__('Edit Comments on “%s”'), wp_html_excerpt(_draft_or_post_title($post_id), 50)); else @@ -88,7 +93,7 @@ $search = attribute_escape( $search_dirty ); ?>

' . __('Search results for “%s”') . '', wp_specialchars( stripslashes($_GET['s']) ) ); ?> + printf( '' . sprintf( __( 'Search results for “%s”' ), wp_html_excerpt( wp_specialchars( stripslashes( $_GET['s'] ) ), 50 ) ) . '' ); ?>

moderated) ), "" . number_format_i18n($num_comments->moderated) . ""), //, number_format_i18n($num_comments->spam) ), "" . number_format_i18n($num_comments->spam) . "") $stati = array( + 'all' => __ngettext_noop('All', 'All'), // singular not used 'moderated' => __ngettext_noop('Pending (%s)', 'Pending (%s)'), 'approved' => __ngettext_noop('Approved', 'Approved'), // singular not used 'spam' => __ngettext_noop('Spam (%s)', 'Spam (%s)') ); $class = ( '' === $comment_status ) ? ' class="current"' : ''; -$status_links[] = "
  • " . __( 'All' ) . ''; -$type = ( !$comment_type && 'all' != $comment_type ) ? '' : "&comment_type=$comment_type"; +// $status_links[] = "
  • " . __( 'All' ) . ''; +$link = 'edit-comments.php'; +if ( !empty($comment_type) && 'all' != $comment_type ) + $link = add_query_arg( 'comment_type', $comment_type, $link ); foreach ( $stati as $status => $label ) { $class = ''; - if ( $status == $comment_status ) + if ( str_replace( 'all', '', $status ) == $comment_status ) $class = ' class="current"'; if ( !isset( $num_comments->$status ) ) $num_comments->$status = 10; - - $status_links[] = "
  • " . sprintf( + if ( 'all' != $status ) + $link = add_query_arg( 'comment_status', $status, $link ); + if ( $post_id ) + $link = add_query_arg( 'p', absint( $post_id ), $link ); + /* + // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark + if ( !empty( $_GET['s'] ) ) + $link = add_query_arg( 's', attribute_escape( stripslashes( $_GET['s'] ) ), $link ); + */ + $status_links[] = "
  • " . sprintf( __ngettext( $label[0], $label[1], $num_comments->$status ), number_format_i18n( $num_comments->$status ) ) . ''; @@ -189,6 +205,9 @@ $page_links = paginate_links( array( ?> + + + diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index f5cc66743d..219eefc2d9 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -1890,10 +1890,13 @@ function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0 else $approved = "( comment_approved = '0' OR comment_approved = '1' )"; - if ( $post ) + if ( $post ) { $post = " AND comment_post_ID = '$post'"; - else + $orderby = "ORDER BY comment_date_gmt ASC LIMIT $start, $num"; + } else { $post = ''; + $orderby = "ORDER BY comment_date_gmt DESC LIMIT $start, $num"; + } if ( 'comment' == $type ) $typesql = "AND comment_type = ''"; @@ -1916,9 +1919,9 @@ function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0 comment_content LIKE ('%$s%') ) AND $approved $typesql - ORDER BY comment_date_gmt DESC LIMIT $start, $num"); + $orderby"); } else { - $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE $approved $post $typesql ORDER BY comment_date_gmt DESC LIMIT $start, $num" ); + $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE $approved $post $typesql $orderby" ); } update_comment_cache($comments);