r69597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69596‎ | r69597 | r69598 >
Date:10:28, 20 July 2010
Author:tstarling
Status:ok
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -3289,7 +3289,14 @@
32903290 </p>
32913291 !! end
32923292
 3293+!! test
 3294+Thumbnail image with link parameter
 3295+!! input
 3296+[[Image:foobar.jpg|thumb|link=http://example.com/|Title]]
 3297+!! result
 3298+<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="https://www.mediawiki.org/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>
32933299
 3300+!! end
32943301
32953302 !! test
32963303 Image with frame and link
Index: trunk/phase3/includes/Linker.php
@@ -529,16 +529,7 @@
530530 'title' => $fp['title'],
531531 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
532532 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
533 - if ( !empty( $fp['link-url'] ) ) {
534 - $params['custom-url-link'] = $fp['link-url'];
535 - } elseif ( !empty( $fp['link-title'] ) ) {
536 - $params['custom-title-link'] = $fp['link-title'];
537 - } elseif ( !empty( $fp['no-link'] ) ) {
538 - // No link
539 - } else {
540 - $params['desc-link'] = true;
541 - $params['desc-query'] = $query;
542 - }
 533+ $params = $this->getImageLinkMTOParams( $fp, $query ) + $params;
543534
544535 $s = $thumb->toHtml( $params );
545536 }
@@ -549,6 +540,27 @@
550541 }
551542
552543 /**
 544+ * Get the link parameters for MediaTransformOutput::toHtml() from given
 545+ * frame parameters supplied by the Parser.
 546+ * @param $frameParams The frame parameters
 547+ * @param $query An optional query string to add to description page links
 548+ */
 549+ function getImageLinkMTOParams( $frameParams, $query = '' ) {
 550+ $mtoParams = array();
 551+ if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
 552+ $mtoParams['custom-url-link'] = $frameParams['link-url'];
 553+ } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
 554+ $mtoParams['custom-title-link'] = $frameParams['link-title'];
 555+ } elseif ( !empty( $frameParams['no-link'] ) ) {
 556+ // No link
 557+ } else {
 558+ $mtoParams['desc-link'] = true;
 559+ $mtoParams['desc-query'] = $query;
 560+ }
 561+ return $mtoParams;
 562+ }
 563+
 564+ /**
553565 * Make HTML for a thumbnail including image, border and caption
554566 * @param $title Title object
555567 * @param $file File object or false if it doesn't exist
@@ -632,32 +644,31 @@
633645 $url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
634646 }
635647
636 - $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
637 -
638648 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
639649 if( !$exists ) {
640650 $s .= $this->makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time==true );
641 - $zoomicon = '';
 651+ $zoomIcon = '';
642652 } elseif ( !$thumb ) {
643653 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
644 - $zoomicon = '';
 654+ $zoomIcon = '';
645655 } else {
646 - $s .= $thumb->toHtml( array(
 656+ $params = array(
647657 'alt' => $fp['alt'],
648658 'title' => $fp['title'],
649 - 'img-class' => 'thumbimage',
650 - 'desc-link' => true,
651 - 'desc-query' => $query ) );
 659+ 'img-class' => 'thumbimage' );
 660+ $params = $this->getImageLinkMTOParams( $fp, $query ) + $params;
 661+ $s .= $thumb->toHtml( $params );
652662 if ( isset( $fp['framed'] ) ) {
653 - $zoomicon="";
 663+ $zoomIcon = "";
654664 } else {
655 - $zoomicon = '<div class="magnify">'.
656 - '<a href="'.$url.'" class="internal" title="'.$more.'">'.
657 - '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
658 - 'width="15" height="11" alt="" /></a></div>';
 665+ $zoomIcon = '<div class="magnify">'.
 666+ '<a href="' . htmlspecialchars( $url ) . '" class="internal" ' .
 667+ 'title="' . htmlspecialchars( wfMsg( 'thumbnail-more' ) ) . '">'.
 668+ '<img src="' . htmlspecialchars( $wgStylePath ) . '/common/images/magnify-clip.png" ' .
 669+ 'width="15" height="11" alt="" /></a></div>';
659670 }
660671 }
661 - $s .= ' <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
 672+ $s .= ' <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
662673 return str_replace("\n", ' ', $s);
663674 }
664675
Index: trunk/phase3/RELEASE-NOTES
@@ -281,7 +281,8 @@
282282 to the local alias.
283283 * (bug 24296) Added converttitles parameter to convert titles to their
284284 canonical language variant.
285 -
 285+* Fixed "link" parameter in image links with "thumb" parameter.
 286+
286287 === Languages updated in 1.17 ===
287288
288289 MediaWiki supports over 330 languages. Many localisations are updated

Follow-up revisions

RevisionCommit summaryAuthorDate
r72771Follow-up to r69597: note in the release notes that this also fixes "frame" a...emufarmers02:53, 11 September 2010

Status & tagging log