* Fixed "link" parameter in image links with "thumb" parameter, previously the link...
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 20 Jul 2010 10:28:00 +0000 (10:28 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 20 Jul 2010 10:28:00 +0000 (10:28 +0000)
* 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
includes/Linker.php
maintenance/parserTests.txt

index f900947..516d3f5 100644 (file)
@@ -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
index f97701f..ebe0401 100644 (file)
@@ -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 = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
                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 =  '<div class="magnify">'.
-                                       '<a href="'.$url.'" class="internal" title="'.$more.'">'.
-                                       '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
-                                       'width="15" height="11" alt="" /></a></div>';
+                               $zoomIcon =  '<div class="magnify">'.
+                                       '<a href="' . htmlspecialchars( $url ) . '" class="internal" ' .
+                                               'title="' . htmlspecialchars( wfMsg( 'thumbnail-more' ) ) . '">'.
+                                       '<img src="' . htmlspecialchars( $wgStylePath ) . '/common/images/magnify-clip.png" ' .
+                                               'width="15" height="11" alt="" /></a></div>';
                        }
                }
-               $s .= '  <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
+               $s .= '  <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
                return str_replace("\n", ' ', $s);
        }
 
index 617ad8b..4acace5 100644 (file)
@@ -3289,7 +3289,14 @@ Image with link parameter (URL target) and unnamed parameter
 </p>
 !! end
 
+!! test
+Thumbnail image with link parameter
+!! input
+[[Image:foobar.jpg|thumb|link=http://example.com/|Title]]
+!! result
+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="http://example.com/"><img alt="" src="http://example.com/images/3/3a/Foobar.jpg" width="180" height="20" class="thumbimage" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"><img src="/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>Title</div></div></div>
 
+!! end
 
 !! test
 Image with frame and link