Index: wp-includes/comment.php
===================================================================
--- wp-includes/comment.php	(revision 15432)
+++ wp-includes/comment.php	(working copy)
@@ -703,7 +703,7 @@
  * @return int|null Comment page number or null on error.
  */
 function get_page_of_comment( $comment_ID, $args = array() ) {
-	global $wpdb;
+	global $wpdb, $user_ID;
 
 	if ( !$comment = get_comment( $comment_ID ) )
 		return;
@@ -712,13 +712,13 @@
 	$args = wp_parse_args( $args, $defaults );
 
 	if ( '' === $args['per_page'] && get_option('page_comments') )
-		$args['per_page'] = get_query_var('comments_per_page');
+		$args['per_page'] = get_option('comments_per_page');
 	if ( empty($args['per_page']) ) {
 		$args['per_page'] = 0;
 		$args['page'] = 0;
 	}
 	if ( $args['per_page'] < 1 )
-		return 1;
+		return 1; // apply_filters ?
 
 	if ( '' === $args['max_depth'] ) {
 		if ( get_option('thread_comments') )
@@ -731,23 +731,59 @@
 	if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )
 		return get_page_of_comment( $comment->comment_parent, $args );
 
+	// wp_list_comments allows: all, comment, trackback, pingback, and pings
 	$allowedtypes = array(
 		'comment' => '',
 		'pingback' => 'pingback',
 		'trackback' => 'trackback',
 	);
 
-	$comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
+	$comtypewhere = ( 'all' != $args['type'] && 'pings' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
+	if ( 'pings' == $args['type'] ) $comtypewhere = " AND (comment_type = 'pingback' OR comment_type = 'trackback')";
 
+	if ( $args['max_depth'] > 1 )
+		$where_comment_parent = ' AND comment_parent = 0';
+	else
+		$where_comment_parent = '';
+
+	/**
+	 * Comment author information fetched from the comment cookies.
+	 *
+	 * @uses wp_get_current_commenter()
+	 */
+	$commenter = wp_get_current_commenter();
+
+	/**
+	 * The name of the current comment author escaped for use in attributes.
+	 */
+	$comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies()
+
+	/**
+	 * The email address of the current comment author escaped for use in attributes.
+	 */
+	$comment_author_email = $commenter['comment_author_email'];  // Escaped by sanitize_comment_cookies()
+
 	// Count comments older than this one
-	$oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
+	// Partially copied from the comments_template function
+	if ( $user_ID )
+		$prepared = $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d" . $where_comment_parent . " AND (comment_approved = '1' OR (user_id = %d AND comment_approved = '0')) AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $user_ID, $comment->comment_date_gmt );
+	else if ( empty($comment_author) )
+		$prepared = $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d" . $where_comment_parent . " AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt );
+	else
+		$prepared = $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d" . $where_comment_parent . " AND (comment_approved = '1' OR (comment_author = %s AND comment_author_email = %s AND comment_approved = '0')) AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email, $comment->comment_date_gmt );
 
-	// No older comments? Then it's page #1.
-	if ( 0 == $oldercoms )
-		return 1;
+	$oldercoms = $wpdb->get_var( $prepared );
 
-	// Divide comments older than this one by comments per page to get this comment's page number
-	return ceil( ( $oldercoms + 1 ) / $args['per_page'] );
+	if ( 0 == $oldercoms ) {
+		// No older comments? Then it's page #1.
+		$page = 1;
+	}
+	else {
+		// Divide comments older than this one by comments per page to get this comment's page number
+		$page = ceil( ( $oldercoms + 1 ) / $args['per_page'] );
+	}
+
+	return apply_filters( 'get_page_of_comment', $page, $comment, $args );
 }
 
 /**
