From 6e522d63e615bb662d4a44e29c97394726868ca0 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Sun, 31 Oct 2010 21:53:29 +0000 Subject: [PATCH] Upscale thumbnails of SVGs if the nominal size of the SVG is smaller than the thumbnail size. Fixes bug 19633. Requires r75748 --- RELEASE-NOTES | 1 + includes/Linker.php | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index edb3400db9..82ce949694 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -379,6 +379,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 23731) Clarified "n links" message on Special:MostLinkedTemplates * (bug 25642) A exception is now thrown instead of a fatal error when using $wgSMTP without PEAR mail package +* (bug 19633) When possible, Upscale small SVGs when creating thumbnails. === API changes in 1.17 === * (bug 22738) Allow filtering by action type on query=logevent. diff --git a/includes/Linker.php b/includes/Linker.php index 3c27747dba..acedce275c 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -433,6 +433,7 @@ class Linker { * to transform(). Typical keys are "width" and "page". * @param $time String: timestamp of the file, set as false for current * @param $query String: query params for desc url + * @param $widthOption: Used by the parser to remember the user preference thumbnailsize * @return String: HTML for an image, with links, wrappers, etc. */ function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "", $widthOption = null ) { @@ -442,7 +443,6 @@ class Linker { return $res; } - global $wgContLang, $wgThumbLimits, $wgThumbUpright; if ( $file && !$file->allowInlineDisplay() ) { wfDebug( __METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" ); return $this->link( $title ); @@ -469,28 +469,31 @@ class Linker { $hp['width'] = $file->getWidth( $page ); if ( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) { + global $wgThumbLimits, $wgThumbUpright; if ( !isset( $widthOption ) || !isset( $wgThumbLimits[$widthOption] ) ) { - $widthOption = User::getDefaultOption( 'thumbsize' ); + $widthOption = User::getDefaultOption( 'thumbsize' ); } // Reduce width for upright images when parameter 'upright' is used if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) { $fp['upright'] = $wgThumbUpright; } - // Use width which is smaller: real image width or user preference width // For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs $prefWidth = isset( $fp['upright'] ) ? round( $wgThumbLimits[$widthOption] * $fp['upright'], -1 ) : $wgThumbLimits[$widthOption]; - if ( $hp['width'] <= 0 || $prefWidth < $hp['width'] ) { - if ( !isset( $hp['height'] ) ) { - $hp['width'] = $prefWidth; - } + + // Use width which is smaller: real image width or user preference width + // Unless image is scalable vector. + if ( !isset( $hp['height'] ) && ( $hp['width'] <= 0 || + $prefWidth < $hp['width'] || $file->isVectorized() ) ) { + $hp['width'] = $prefWidth; } } } - if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) { + if ( $file && ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) ) { + global $wgContLang; # Create a thumbnail. Alignment depends on language # writing direction, # right aligned for left-to-right- # languages ("Western languages"), left-aligned @@ -513,7 +516,7 @@ class Linker { } } - if ( $file && $hp['width'] ) { + if ( $file && isset( $hp['width'] ) ) { # Create a resized image, without the additional thumbnail features $thumb = $file->transform( $hp ); } else { -- 2.20.1