Make WordPress Core

Ticket #11359: 11359.4.diff

File 11359.4.diff, 10.0 KB (added by akibjorklund, 10 years ago)

Fix bug that results into admin comment content links inappropriately nofollowed

  • wp-includes/comment-functions.php

     
    14821482         *
    14831483         * @param int $comment_content The comment content.
    14841484         */
    1485         $commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] );
     1485        $commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'], isset( $commentdata['user_id'] ) ? $commentdata['user_id'] : null );
    14861486        /**
    14871487         * Filter the comment author's IP before it is set.
    14881488         *
  • wp-includes/comment-template.php

     
    210210        $url     = get_comment_author_url( $comment );
    211211        $author  = get_comment_author( $comment );
    212212
    213         if ( empty( $url ) || 'http://' == $url )
     213        if ( empty( $url ) || 'http://' == $url ) {
    214214                $return = $author;
    215         else
    216                 $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
     215        } else {
     216                // By default, add rel=nofollow to author links
     217                $nofollow = ' nofollow';
     218                $comment = get_comment( $comment_ID );
     219                // If the author can edit comments, no need to rel=unfollow the link
     220                if ( $comment->user_id > 0 && user_can( $comment->user_id, 'edit_comment' ) ) {
     221                        $nofollow = '';
     222                }
    217223
     224                $return = "<a href='$url' rel='external$nofollow' class='url'>$author</a>";
     225        }
     226
    218227        /**
    219228         * Filter the comment author's link for display.
    220229         *
  • wp-includes/default-filters.php

     
    143143add_filter( 'the_excerpt',     'shortcode_unautop');
    144144add_filter( 'get_the_excerpt', 'wp_trim_excerpt'  );
    145145
    146 add_filter( 'comment_text', 'wptexturize'            );
    147 add_filter( 'comment_text', 'convert_chars'          );
    148 add_filter( 'comment_text', 'make_clickable',      9 );
    149 add_filter( 'comment_text', 'force_balance_tags', 25 );
    150 add_filter( 'comment_text', 'convert_smilies',    20 );
    151 add_filter( 'comment_text', 'wpautop',            30 );
     146add_filter( 'comment_text', 'wptexturize'                  );
     147add_filter( 'comment_text', 'convert_chars'                );
     148add_filter( 'comment_text', 'make_comment_clickable', 9, 2 );
     149add_filter( 'comment_text', 'force_balance_tags',     25  );
     150add_filter( 'comment_text', 'convert_smilies',        20  );
     151add_filter( 'comment_text', 'wpautop',                30  );
    152152
    153153add_filter( 'comment_excerpt', 'convert_chars' );
    154154
     
    176176add_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
    177177
    178178// Misc filters
    179 add_filter( 'option_ping_sites',        'privacy_ping_filter'                 );
    180 add_filter( 'option_blog_charset',      '_wp_specialchars'                    ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
    181 add_filter( 'option_blog_charset',      '_canonical_charset'                  );
    182 add_filter( 'option_home',              '_config_wp_home'                     );
    183 add_filter( 'option_siteurl',           '_config_wp_siteurl'                  );
    184 add_filter( 'tiny_mce_before_init',     '_mce_set_direction'                  );
    185 add_filter( 'teeny_mce_before_init',    '_mce_set_direction'                  );
    186 add_filter( 'pre_kses',                 'wp_pre_kses_less_than'               );
    187 add_filter( 'sanitize_title',           'sanitize_title_with_dashes',   10, 3 );
    188 add_action( 'check_comment_flood',      'check_comment_flood_db',       10, 3 );
    189 add_filter( 'comment_flood_filter',     'wp_throttle_comment_flood',    10, 3 );
    190 add_filter( 'pre_comment_content',      'wp_rel_nofollow',              15    );
    191 add_filter( 'comment_email',            'antispambot'                         );
    192 add_filter( 'option_tag_base',          '_wp_filter_taxonomy_base'            );
    193 add_filter( 'option_category_base',     '_wp_filter_taxonomy_base'            );
    194 add_filter( 'the_posts',                '_close_comments_for_old_posts', 10, 2);
    195 add_filter( 'comments_open',            '_close_comments_for_old_post', 10, 2 );
    196 add_filter( 'pings_open',               '_close_comments_for_old_post', 10, 2 );
    197 add_filter( 'editable_slug',            'urldecode'                           );
    198 add_filter( 'editable_slug',            'esc_textarea'                        );
    199 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object'        );
    200 add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri'            );
    201 add_filter( 'xmlrpc_pingback_error',    'xmlrpc_pingback_error'               );
    202 add_filter( 'title_save_pre',           'trim'                                );
    203 add_filter( 'get_comment_metadata',     'wp_lazyload_comment_meta',     10, 2 );
     179add_filter( 'option_ping_sites',        'privacy_ping_filter'                  );
     180add_filter( 'option_blog_charset',      '_wp_specialchars'                     ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
     181add_filter( 'option_blog_charset',      '_canonical_charset'                   );
     182add_filter( 'option_home',              '_config_wp_home'                      );
     183add_filter( 'option_siteurl',           '_config_wp_siteurl'                   );
     184add_filter( 'tiny_mce_before_init',     '_mce_set_direction'                   );
     185add_filter( 'teeny_mce_before_init',    '_mce_set_direction'                   );
     186add_filter( 'pre_kses',                 'wp_pre_kses_less_than'                );
     187add_filter( 'sanitize_title',           'sanitize_title_with_dashes',    10, 3 );
     188add_action( 'check_comment_flood',      'check_comment_flood_db',        10, 3 );
     189add_filter( 'comment_flood_filter',     'wp_throttle_comment_flood',     10, 3 );
     190add_filter( 'pre_comment_content',      'wp_maybe_rel_nofollow_comment', 15, 2 );
     191add_filter( 'comment_email',            'antispambot'                          );
     192add_filter( 'option_tag_base',          '_wp_filter_taxonomy_base'             );
     193add_filter( 'option_category_base',     '_wp_filter_taxonomy_base'             );
     194add_filter( 'the_posts',                '_close_comments_for_old_posts', 10, 2 );
     195add_filter( 'comments_open',            '_close_comments_for_old_post', 10, 2  );
     196add_filter( 'pings_open',               '_close_comments_for_old_post', 10, 2  );
     197add_filter( 'editable_slug',            'urldecode'                            );
     198add_filter( 'editable_slug',            'esc_textarea'                         );
     199add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object'         );
     200add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri'             );
     201add_filter( 'xmlrpc_pingback_error',    'xmlrpc_pingback_error'                );
     202add_filter( 'title_save_pre',           'trim'                                 );
     203add_filter( 'get_comment_metadata',     'wp_lazyload_comment_meta',     10, 2  );
    204204
    205205add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 );
    206206
  • wp-includes/formatting.php

     
    20582058        if ( empty($url) )
    20592059                return $matches[0];
    20602060
    2061         return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix;
     2061        return $matches[1] . "<a href=\"$url\">$url</a>" . $suffix;
    20622062}
    20632063
    20642064/**
     
    20862086                $ret = substr($dest, -1);
    20872087                $dest = substr($dest, 0, strlen($dest)-1);
    20882088        }
    2089         return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret";
     2089        return $matches[1] . "<a href=\"$dest\">$dest</a>$ret";
    20902090}
    20912091
    20922092/**
     
    21762176}
    21772177
    21782178/**
     2179 * Convert plaintext URI to HTML links in comments.
     2180 *
     2181 * @since 4.4.0
     2182 *
     2183 * @param  object $comment A comment.
     2184 * @return string Content with converted URIs.
     2185 */
     2186function make_comment_clickable( $text, $comment ) {
     2187        $text = make_clickable( $text );
     2188        $user_id = $comment->user_id > 0 ? $comment->user_id : null;
     2189        return wp_maybe_rel_nofollow_comment( $text, $user_id, 'unescaped' );
     2190}
     2191
     2192/**
    21792193 * Breaks a string into chunks by splitting at whitespace characters.
    21802194 * The length of each returned chunk is as close to the specified length goal as possible,
    21812195 * with the caveat that each chunk includes its trailing delimiter.
     
    22322246}
    22332247
    22342248/**
     2249 * Controls whether there is a rel=nofollow string in all HTML A elements
     2250 * in a comment, depending on if the user can edit comments or not.
     2251 *
     2252 * @since 4.1.0
     2253 *
     2254 * @param string $text      HTML text to filter
     2255 * @param int    $author_id User ID of the author of the comment
     2256 * @param string $escaped   'escaped' if the $text is already escaped, else 'unescaped'
     2257 */
     2258function wp_maybe_rel_nofollow_comment( $text, $author_id = null, $escaped = 'escaped' ) {
     2259        // Test for authors that can edit comments.
     2260        if ( null != $author_id && user_can( $author_id, 'edit_comment' ) ) {
     2261                // No need to add rel=nofollow.
     2262                return $text;
     2263        }
     2264       
     2265        return wp_rel_nofollow( $text, $escaped );
     2266}
     2267
     2268/**
    22352269 * Adds rel nofollow string to all HTML A elements in content.
    22362270 *
    22372271 * @since 1.5.0
    22382272 *
    2239  * @param string $text Content that may contain HTML A elements.
     2273 * @param string $text    Content that may contain HTML A elements.
     2274 * @param string $escaped Whether the text is escaped or unescaped
    22402275 * @return string Converted content.
    22412276 */
    2242 function wp_rel_nofollow( $text ) {
    2243         // This is a pre save filter, so text is already escaped.
    2244         $text = stripslashes($text);
    2245         $text = preg_replace_callback('|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text);
    2246         return wp_slash( $text );
     2277function wp_rel_nofollow( $text, $escaped = 'escaped' ) {
     2278        if ( 'escaped' == $escaped ) {
     2279                $text = stripslashes( $text );
     2280        }
     2281        $text = preg_replace_callback( '|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text );
     2282        if ( 'escaped' == $escaped ) {
     2283                $text = wp_slash( $text );
     2284        }
     2285        return $text;
    22472286}
    22482287
    22492288/**