Index: wp-includes/comment-template.php
===================================================================
--- wp-includes/comment-template.php	(revision 18280)
+++ wp-includes/comment-template.php	(working copy)
@@ -569,8 +569,9 @@
  * @param string $one Text for one comment
  * @param string $more Text for more than one comment
  * @param string $deprecated Not used.
+ * @param bool $echo Whether to echo or just return the string
  */
-function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
+function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $echo = true ) {
 	if ( !empty( $deprecated ) )
 		_deprecated_argument( __FUNCTION__, '1.3' );
 
@@ -583,7 +584,10 @@
 	else // must be one
 		$output = ( false === $one ) ? __('1 Comment') : $one;
 
-	echo apply_filters('comments_number', $output, $number);
+	if ( $echo )
+		echo apply_filters('comments_number', $output, $number);
+	else
+		return apply_filters('comments_number', $output, $number);
 }
 
 /**
@@ -949,24 +953,24 @@
 }
 
 /**
- * Displays the link to the comments popup window for the current post ID.
+ * Retrives the link to the comments popup window for the current post ID.
  *
  * Is not meant to be displayed on single posts and pages. Should be used on the
  * lists of posts
  *
- * @since 0.71
+ * @since 3.3.0
  * @uses $wpcommentspopupfile
  * @uses $wpcommentsjavascript
  * @uses $post
  *
- * @param string $zero The string to display when no comments
- * @param string $one The string to display when only one comment is available
- * @param string $more The string to display when there are more than one comment
+ * @param bool|string $zero The string to display when no comments
+ * @param bool|string $one The string to display when only one comment is available
+ * @param bool|string $more The string to display when there are more than one comment
  * @param string $css_class The CSS class to use for comments
- * @param string $none The string to display when comments have been turned off
- * @return null Returns null on single posts and pages.
+ * @param bool|string $none The string to display when comments have been turned off
+ * @return string
  */
-function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
+function get_comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
 	global $wpcommentspopupfile, $wpcommentsjavascript;
 
 	$id = get_the_ID();
@@ -978,45 +982,63 @@
 
 	$number = get_comments_number( $id );
 
-	if ( 0 == $number && !comments_open() && !pings_open() ) {
-		echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
-		return;
-	}
+	if ( 0 == $number && !comments_open() && !pings_open() )
+		return '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
 
-	if ( post_password_required() ) {
-		echo __('Enter your password to view comments.');
-		return;
-	}
+	if ( post_password_required() )
+		return __('Enter your password to view comments.');
 
-	echo '<a href="';
+	$output = '';
+
+	$output .= '<a href="';
 	if ( $wpcommentsjavascript ) {
 		if ( empty( $wpcommentspopupfile ) )
 			$home = home_url();
 		else
 			$home = get_option('siteurl');
-		echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
-		echo '" onclick="wpopen(this.href); return false"';
+		$output .= $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
+		$output .= '" onclick="wpopen(this.href); return false"';
 	} else { // if comments_popup_script() is not in the template, display simple comment link
 		if ( 0 == $number )
-			echo get_permalink() . '#respond';
+			$output .= get_permalink() . '#respond';
 		else
-			comments_link();
-		echo '"';
+			$output .= get_comments_link();
+		$output .= '"';
 	}
 
-	if ( !empty( $css_class ) ) {
-		echo ' class="'.$css_class.'" ';
-	}
+	if ( !empty( $css_class ) )
+		$output .= ' class="'.$css_class.'" ';
+
 	$title = the_title_attribute( array('echo' => 0 ) );
 
-	echo apply_filters( 'comments_popup_link_attributes', '' );
+	$output .= apply_filters( 'comments_popup_link_attributes', '' );
 
-	echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
-	comments_number( $zero, $one, $more );
-	echo '</a>';
+	$output .= ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
+	$output .= comments_number( $zero, $one, $more, '', false );
+	$output .= '</a>';
+
+	return $output;
 }
 
 /**
+ * Displays the link to the comments popup window for the current post ID.
+ *
+ * Is not meant to be displayed on single posts and pages. Should be used on the
+ * lists of posts
+ *
+ * @since 0.71
+ *
+ * @param bool|string $zero The string to display when no comments
+ * @param bool|string $one The string to display when only one comment is available
+ * @param bool|string $more The string to display when there are more than one comment
+ * @param string $css_class The CSS class to use for comments
+ * @param bool|string $none The string to display when comments have been turned off
+ */
+function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
+	echo get_comments_popup_link($zero, $one, $more, $css_class, $none);
+}
+
+/**
  * Retrieve HTML content for reply to comment link.
  *
  * The default arguments that can be override are 'add_below', 'respond_id',
