Index: src/wp-includes/comment-template.php
===================================================================
--- src/wp-includes/comment-template.php	(revision 30076)
+++ src/wp-includes/comment-template.php	(working copy)
@@ -711,12 +711,18 @@
  * @param string $one        Optional. Text for one comment. Default false.
  * @param string $more       Optional. Text for more than one comment. Default false.
  * @param string $deprecated Not used.
- */
-function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
+ * @param bool   $echo       Whether to echo or just return the string. Default true. 
+*/
+function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $echo = true ) {
 	if ( ! empty( $deprecated ) ) {
 		_deprecated_argument( __FUNCTION__, '1.3' );
 	}
-	echo get_comments_number_text( $zero, $one, $more );
+
+	if ( $echo ) {
+		echo get_comments_number_text( $zero, $one, $more );
+	} else {
+		return get_comments_number_text( $zero, $one, $more );
+	}
 }
 
 /**
@@ -1204,7 +1204,7 @@
 }
 
 /**
- * Displays the link to the comments popup window for the current post ID.
+ * Retrieves 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
@@ -1212,19 +1212,19 @@
  * @global string $wpcommentspopupfile  The URL to use for the popup window.
  * @global int    $wpcommentsjavascript Whether to use JavaScript. Set when function is called.
  *
- * @since 0.71
+ * @since 4.1.0
  *
- * @param string $zero      Optional. String to display when no comments. Default false.
- * @param string $one       Optional. String to display when only one comment is available.
- *                          Default false.
- * @param string $more      Optional. String to display when there are more than one comment.
- *                          Default false.
- * @param string $css_class Optional. CSS class to use for comments. Default empty.
- * @param string $none      Optional. String to display when comments have been turned off.
- *                          Default false.
- * @return null Returns null on single posts and pages.
+ * @param bool|string $zero      Optional. String to display when no comments. Default false.
+ * @param bool|string $one       Optional. String to display when only one comment is available.
+ *                               Default false.
+ * @param bool|string $more      Optional. String to display when there are more than one comment.
+ *                               Default false.
+ * @param string $css_class      Optional. CSS class to use for comments. Default empty.
+ * @param bool|string $none      Optional. String to display when comments have been turned off.
+ *                               Default false.
+ * @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();
@@ -1236,9 +1236,8 @@
 
 	$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() ) {
@@ -1246,24 +1245,27 @@
 		return;
 	}
 
-	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';
-		else
-			comments_link();
-		echo '"';
+		if ( 0 == $number ) {
+			$output .= get_permalink() . '#respond';
+		} else {
+			$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 ) );
 
@@ -1275,14 +1277,33 @@
 	 *
 	 * @param string $attributes The comments popup link attributes. Default empty.
 	 */
-	echo apply_filters( 'comments_popup_link_attributes', $attributes );
+	$output .= apply_filters( 'comments_popup_link_attributes', $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 .= get_comments_number_text( $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.
  *
  * @since 2.7.0
