From ce448d5d7a76640c78630fcacc8bb50314ac2d09 Mon Sep 17 00:00:00 2001
From: Tim Starling
Date: Tue, 20 Jul 2010 10:28:00 +0000
Subject: [PATCH] * Fixed "link" parameter in image links with "thumb"
parameter, previously the link parameter was just ignored. The fix required
the relevant code to be factored out so both makeImageLink2() and
makeThumbLink2() could use it. * Fixed the coding style and escaping of some
nearby code. The lack of escaping on $url would have caused invalid HTML
(bare ampersand) if ugly URLs were combined with page parameters.
---
RELEASE-NOTES | 3 +-
includes/Linker.php | 59 ++++++++++++++++++++++---------------
maintenance/parserTests.txt | 7 +++++
3 files changed, 44 insertions(+), 25 deletions(-)
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index f90094711f..516d3f5832 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -281,7 +281,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
to the local alias.
* (bug 24296) Added converttitles parameter to convert titles to their
canonical language variant.
-
+* Fixed "link" parameter in image links with "thumb" parameter.
+
=== Languages updated in 1.17 ===
MediaWiki supports over 330 languages. Many localisations are updated
diff --git a/includes/Linker.php b/includes/Linker.php
index f97701ffa3..ebe0401df9 100644
--- a/includes/Linker.php
+++ b/includes/Linker.php
@@ -529,16 +529,7 @@ class Linker {
'title' => $fp['title'],
'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
- if ( !empty( $fp['link-url'] ) ) {
- $params['custom-url-link'] = $fp['link-url'];
- } elseif ( !empty( $fp['link-title'] ) ) {
- $params['custom-title-link'] = $fp['link-title'];
- } elseif ( !empty( $fp['no-link'] ) ) {
- // No link
- } else {
- $params['desc-link'] = true;
- $params['desc-query'] = $query;
- }
+ $params = $this->getImageLinkMTOParams( $fp, $query ) + $params;
$s = $thumb->toHtml( $params );
}
@@ -548,6 +539,27 @@ class Linker {
return str_replace("\n", ' ',$prefix.$s.$postfix);
}
+ /**
+ * Get the link parameters for MediaTransformOutput::toHtml() from given
+ * frame parameters supplied by the Parser.
+ * @param $frameParams The frame parameters
+ * @param $query An optional query string to add to description page links
+ */
+ function getImageLinkMTOParams( $frameParams, $query = '' ) {
+ $mtoParams = array();
+ if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
+ $mtoParams['custom-url-link'] = $frameParams['link-url'];
+ } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
+ $mtoParams['custom-title-link'] = $frameParams['link-title'];
+ } elseif ( !empty( $frameParams['no-link'] ) ) {
+ // No link
+ } else {
+ $mtoParams['desc-link'] = true;
+ $mtoParams['desc-query'] = $query;
+ }
+ return $mtoParams;
+ }
+
/**
* Make HTML for a thumbnail including image, border and caption
* @param $title Title object
@@ -632,32 +644,31 @@ class Linker {
$url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
}
- $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
-
$s = "";
if( !$exists ) {
$s .= $this->makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time==true );
- $zoomicon = '';
+ $zoomIcon = '';
} elseif ( !$thumb ) {
$s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
- $zoomicon = '';
+ $zoomIcon = '';
} else {
- $s .= $thumb->toHtml( array(
+ $params = array(
'alt' => $fp['alt'],
'title' => $fp['title'],
- 'img-class' => 'thumbimage',
- 'desc-link' => true,
- 'desc-query' => $query ) );
+ 'img-class' => 'thumbimage' );
+ $params = $this->getImageLinkMTOParams( $fp, $query ) + $params;
+ $s .= $thumb->toHtml( $params );
if ( isset( $fp['framed'] ) ) {
- $zoomicon="";
+ $zoomIcon = "";
} else {
- $zoomicon = '
';
+ $zoomIcon = '
';
}
}
- $s .= '
'.$zoomicon.$fp['caption']."
";
+ $s .= ' ' . $zoomIcon . $fp['caption'] . "
";
return str_replace("\n", ' ', $s);
}
diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt
index 617ad8be5b..4acace56a9 100644
--- a/maintenance/parserTests.txt
+++ b/maintenance/parserTests.txt
@@ -3289,7 +3289,14 @@ Image with link parameter (URL target) and unnamed parameter
!! end
+!! test
+Thumbnail image with link parameter
+!! input
+[[Image:foobar.jpg|thumb|link=http://example.com/|Title]]
+!! result
+
+!! end
!! test
Image with frame and link
--
2.20.1