Page MenuHomePhabricator

git-1_19.patch

Authored By
• bzimport
Nov 21 2014, 11:12 PM
Size
5 KB
Referenced Files
None
Subscribers
None

git-1_19.patch

From 9fee08add48181377d10799f2530a2fad4c9f481 Mon Sep 17 00:00:00 2001
From: csteipp <csteipp@wikimedia.org>
Date: Mon, 10 Sep 2012 12:19:28 -0700
Subject: [PATCH] (bug 24437) Add nofollow to image link
Add Parser's extLinkAttribs attributes when an image has a link
parameter, when generating the html. Currently, these may include
rel="nofollow" and the target attribute.
This will correctly add rel="nofollow", respecting $wgNoFollowLinks,
$wgNoFollowDomainExceptions, and $wgNoFollowNsExceptions settings.
Updated parser tests for expected results, added new tests for
$wgNoFollowLinks and $wgNoFollowDomainExceptions exceptions.
Change-Id: If9c524a43f81f1a744886be5178200a6e7a0482c
---
includes/Linker.php | 7 +++++++
includes/media/MediaTransformOutput.php | 8 ++++++++
tests/parser/parserTests.txt | 30 ++++++++++++++++++++++++++----
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/includes/Linker.php b/includes/Linker.php
index 0b813ac..62474af 100644
--- a/includes/Linker.php
+++ b/includes/Linker.php
@@ -619,6 +619,13 @@ class Linker {
if ( isset( $frameParams['link-target'] ) ) {
$mtoParams['custom-target-link'] = $frameParams['link-target'];
}
+ $extLinkAttrs = $wgParser->getExternalLinkAttribs( $frameParams['link-url'] );
+ foreach ( $extLinkAttrs as $name => $val ) {
+ // Currently could include:
+ // 'parser-extlink-rel'
+ // 'parser-extlink-target'
+ $mtoParams['parser-extlink-'.$name] = $val;
+ }
} elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
$mtoParams['custom-title-link'] = self::normaliseSpecialPage( $frameParams['link-title'] );
} elseif ( !empty( $frameParams['no-link'] ) ) {
diff --git a/includes/media/MediaTransformOutput.php b/includes/media/MediaTransformOutput.php
index fcfb2f4..051474e 100644
--- a/includes/media/MediaTransformOutput.php
+++ b/includes/media/MediaTransformOutput.php
@@ -221,6 +221,9 @@ class ThumbnailImage extends MediaTransformOutput {
* custom-url-link Custom URL to link to
* custom-title-link Custom Title object to link to
* custom target-link Value of the target attribute, for custom-target-link
+ * parser-extlink-* Attributes added by parser for external links:
+ * parser-extlink-rel: add rel="nofollow"
+ * parser-extlink-target: link target, but overridden by custom-target-link
*
* For images, desc-link and file-link are implemented as a click-through. For
* sounds and videos, they may be displayed in other ways.
@@ -243,6 +246,11 @@ class ThumbnailImage extends MediaTransformOutput {
}
if ( !empty( $options['custom-target-link'] ) ) {
$linkAttribs['target'] = $options['custom-target-link'];
+ } elseif ( !empty( $options['parser-extlink-target'] ) ) {
+ $linkAttribs['target'] = $options['parser-extlink-target'];
+ }
+ if ( !empty( $options['parser-extlink-rel'] ) ) {
+ $linkAttribs['rel'] = $options['parser-extlink-rel'];
}
} elseif ( !empty( $options['custom-title-link'] ) ) {
$title = $options['custom-title-link'];
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index 11a5516..acaf322 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -3734,7 +3734,7 @@ Image with link parameter, URL target
!! input
[[Image:foobar.jpg|link=http://example.com/]]
!! result
-<p><a href="http://example.com/"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
+<p><a href="http://example.com/" rel="nofollow"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! end
@@ -3745,7 +3745,29 @@ Image with link parameter, wgExternalLinkTarget
!! config
wgExternalLinkTarget='foobar'
!! result
-<p><a href="http://example.com/" target="foobar"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
+<p><a href="http://example.com/" target="foobar" rel="nofollow"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
+</p>
+!! end
+
+!! test
+Image with link parameter, wgNoFollowLinks set to false
+!! input
+[[Image:foobar.jpg|link=http://example.com/]]
+!! config
+wgNoFollowLinks=false
+!! result
+<p><a href="http://example.com/"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
+</p>
+!! end
+
+!! test
+Image with link parameter, wgNoFollowDomainExceptions
+!! input
+[[Image:foobar.jpg|link=http://example.com/]]
+!! config
+wgNoFollowDomainExceptions='example.com'
+!! result
+<p><a href="http://example.com/"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! end
@@ -3756,7 +3778,7 @@ Image with link parameter, wgExternalLinkTarget, unnamed parameter
!! config
wgExternalLinkTarget='foobar'
!! result
-<p><a href="http://example.com/" title="Title" target="foobar"><img alt="Title" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
+<p><a href="http://example.com/" title="Title" target="foobar" rel="nofollow"><img alt="Title" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! end
@@ -3783,7 +3805,7 @@ Image with link parameter (URL target) and unnamed parameter
!! input
[[Image:foobar.jpg|link=http://example.com/|Title]]
!! result
-<p><a href="http://example.com/" title="Title"><img alt="Title" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
+<p><a href="http://example.com/" title="Title" rel="nofollow"><img alt="Title" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! end
--
1.7.5.4

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6527
Default Alt Text
git-1_19.patch (5 KB)

Event Timeline