Making WordPress.org

Changeset 11583


Ignore:
Timestamp:
02/18/2022 08:06:03 AM (19 months ago)
Author:
dd32
Message:

Trac: Mark links in ticket descriptions/comments as rel="ugc nofollow". Take two.

[11548] was previously applying to all 'searchable' elements which includes the code browser.
The code browser uses a different String class, and being treated as a Markup string caused it to strip content that was unexpected within it.
This implements [11548] again verifying the specific string classes which we can alter, and narrowing it further by only applying to the ticket/comment classes and only when ext-link is present, to reduce potential breakage.

Fixes #4950.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/trac.wordpress.org/templates/site.html

    r11570 r11583  
    314314    <textarea class="${select('@class')} wp-exclude-emoji" id="${select('@id')}" name="${select('@name')}" rows="${select('@rows')}" cols="${select('@cols')}">${select('*|comment()|text()')}</textarea>
    315315</py:match>
     316
     317<!--! Mark description/comment links as nofollow user-generated-content. -->
     318<div py:match="div[contains(@class,'description') or contains(@class,'comment')]" py:attrs="select('@*')">
     319    <?python
     320    from genshi.core import TEXT, Markup
     321    def nofollow_ugc(stream):
     322        for kind, data, pos in stream:
     323            if kind is TEXT and isinstance( data, Markup ) and ( 'ext-link' in data ):
     324                data = Markup( data.replace( '<' + 'a class="ext-link"', '<' + 'a class="ext-link" rel="ugc nofollow"' ) )
     325            yield kind, data, pos
     326    ?>
     327    ${nofollow_ugc(select('*|comment()|text()'))}
     328</div>
    316329
    317330<body py:match="body" id="wordpress-org" class="${project_slug} trac wporg-make make-${project_slug}" py:attrs="select('@*')">
Note: See TracChangeset for help on using the changeset viewer.