From: C. Scott Ananian Date: Wed, 27 Feb 2013 00:12:12 +0000 (-0500) Subject: Fix link target and retina thumbnails for manual thumbnails. (Bug 45405.) X-Git-Tag: 1.31.0-rc.0~20179^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=11adcad08b1818d79b18fe8185277bc9a7531431;p=lhc%2Fweb%2Fwiklou.git Fix link target and retina thumbnails for manual thumbnails. (Bug 45405.) The output for [[Image:Bad.jpg|thumb=Foobar.jpg|Title]] used to be:
Title
Note that the target of the is the thumb, not the original image, and that the srcset is loading the full resolution version of Bad.jpg. The attached patches fix the link target and srcset issues (suppressing the srcset when a manual thumb is used). It also adds a new "Thumb.png" pseudo-file to the parserTests so that we can write new tests documenting how manual thumbnails are expected to work, and adds the 'php' option to the thumbnail tests (since the Parsoid parser generates different output). Change-Id: I5be80bfce855b85f9debf3ef1776b877d1f84b9f --- diff --git a/includes/Linker.php b/includes/Linker.php index a347549dfd..e4222e3c49 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -612,7 +612,7 @@ class Linker { $hp['width'] = $file->getWidth( $page ); } - if ( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) { + if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) { global $wgThumbLimits, $wgThumbUpright; if ( $widthOption === null || !isset( $wgThumbLimits[$widthOption] ) ) { $widthOption = User::getDefaultOption( 'thumbsize' ); @@ -797,6 +797,7 @@ class Linker { } $thumb = false; $noscale = false; + $manualthumb = false; if ( !$exists ) { $outerWidth = $hp['width'] + 2; @@ -808,6 +809,7 @@ class Linker { $manual_img = wfFindFile( $manual_title ); if ( $manual_img ) { $thumb = $manual_img->getUnscaledThumb( $hp ); + $manualthumb = true; } else { $exists = false; } @@ -840,6 +842,12 @@ class Linker { if ( $page ) { $url = wfAppendQuery( $url, 'page=' . urlencode( $page ) ); } + if ( $manualthumb && + !isset( $fp['link-title'] ) && + !isset( $fp['link-url'] ) && + !isset( $fp['no-link'] ) ) { + $fp['link-url'] = $url; + } $s = "
"; if ( !$exists ) { @@ -849,7 +857,7 @@ class Linker { $s .= wfMessage( 'thumbnail_error', '' )->escaped(); $zoomIcon = ''; } else { - if ( !$noscale ) { + if ( !$noscale && !$manualthumb ) { self::processResponsiveImages( $file, $thumb, $hp ); } $params = array( diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index 32b8154670..3d34f34c27 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -869,18 +869,36 @@ class ParserTest { $this->uploadDir = $this->setupUploadDir(); $user = User::createNew( 'WikiSysop' ); $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) ); + # note that the size/width/height/bits/etc of the file + # are actually set by inspecting the file itself; the arguments + # to recordUpload2 have no effect. That said, we try to make things + # match up so it is less confusing to readers of the code & tests. $image->recordUpload2( '', 'Upload of some lame file', 'Some lame file', array( - 'size' => 12345, + 'size' => 7881, 'width' => 1941, 'height' => 220, - 'bits' => 24, + 'bits' => 8, 'media_type' => MEDIATYPE_BITMAP, 'mime' => 'image/jpeg', 'metadata' => serialize( array() ), - 'sha1' => wfBaseConvert( '', 16, 36, 31 ), + 'sha1' => wfBaseConvert( '1', 16, 36, 31 ), 'fileExists' => true ), $this->db->timestamp( '20010115123500' ), $user ); + $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Thumb.png' ) ); + # again, note that size/width/height below are ignored; see above. + $image->recordUpload2( '', 'Upload of some lame thumbnail', 'Some lame thumbnail', array( + 'size' => 22589, + 'width' => 135, + 'height' => 135, + 'bits' => 8, + 'media_type' => MEDIATYPE_BITMAP, + 'mime' => 'image/png', + 'metadata' => serialize( array() ), + 'sha1' => wfBaseConvert( '2', 16, 36, 31 ), + 'fileExists' => true + ), $this->db->timestamp( '20130225203040' ), $user ); + # This image will be blacklisted in [[MediaWiki:Bad image list]] $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) ); $image->recordUpload2( '', 'zomgnotcensored', 'Borderline image', array( @@ -891,7 +909,7 @@ class ParserTest { 'media_type' => MEDIATYPE_BITMAP, 'mime' => 'image/jpeg', 'metadata' => serialize( array() ), - 'sha1' => wfBaseConvert( '', 16, 36, 31 ), + 'sha1' => wfBaseConvert( '3', 16, 36, 31 ), 'fileExists' => true ), $this->db->timestamp( '20010115123500' ), $user ); } @@ -960,6 +978,8 @@ class ParserTest { wfMkdirParents( $dir . '/3/3a', null, __METHOD__ ); copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" ); + wfMkdirParents( $dir . '/e/ea', null, __METHOD__ ); + copy( "$IP/skins/monobook/wiki.png", "$dir/e/ea/Thumb.png" ); wfMkdirParents( $dir . '/0/09', null, __METHOD__ ); copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" ); @@ -1008,6 +1028,8 @@ class ParserTest { "$dir/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg", "$dir/thumb/3/3a/Foobar.jpg/960px-Foobar.jpg", + "$dir/e/ea/Thumb.png", + "$dir/0/09/Bad.jpg", "$dir/math/f/a/5/fa50b8b616463173474302ca3e63586b.png", @@ -1024,6 +1046,9 @@ class ParserTest { "$dir/thumb/3/3a", "$dir/thumb/3", + "$dir/e/ea", + "$dir/e", + "$dir/0/09/", "$dir/0/", "$dir/thumb", diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 4a15470352..d3bd6a5a7f 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -4782,7 +4782,7 @@ Magic Word: {{NUMBEROFFILES}} !! input {{NUMBEROFFILES}} !! result -

2 +

3

!! end @@ -7151,6 +7151,8 @@ Image with link parameter (URL target) and unnamed parameter !! test Thumbnail image with link parameter +!! options +php !! input [[Image:foobar.jpg|thumb|link=http://example.com/|Title]] !! result @@ -7158,6 +7160,61 @@ Thumbnail image with link parameter !! end +!! test +Manually-specified thumbnail image +!! options +php +!! input +[[Image:Foobar.jpg|thumb=Thumb.png|Title]] +!! result +
Title
+ +!! end + +!! test +Manually-specified thumbnail image with explicit link to wiki page +!! options +php +!! input +[[Image:Foobar.jpg|thumb=Thumb.png|link=Main Page|Title]] +!! result +
Title
+ +!! end + +!! test +Manually-specified thumbnail image with explicit link to url +!! options +php +!! input +[[Image:Foobar.jpg|thumb=Thumb.png|link=http://example.com|Title]] +!! result +
Title
+ +!! end + +!! test +Manually-specified thumbnail image with explicit no link +!! options +php +!! input +[[Image:Foobar.jpg|thumb=Thumb.png|link=|Title]] +!! result +
Title
+ +!! end + +!! test +Manually-specified thumbnail image with explicit link and alt text +!! options +php +!! input +[[Image:Foobar.jpg|thumb=Thumb.png|link=Main Page|alt=alttext|Title]] +!! result +
alttext
Title
+ +!! end + !! test Image with frame and link !! input @@ -9580,7 +9637,7 @@ Fuzz testing: image with bogus manual thumbnail !!input [[Image:foobar.jpg|thumbnail= ]] !!result -
Error creating thumbnail:
+
Error creating thumbnail:
!!end diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index 5732beb3dc..77311b90a9 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -187,6 +187,10 @@ class NewParserTest extends MediaWikiTestCase { # We will upload the actual files later. Note that if anything causes LocalFile::load() # to be triggered before then, it will break via maybeUpgrade() setting the fileExists # member to false and storing it in cache. + # note that the size/width/height/bits/etc of the file + # are actually set by inspecting the file itself; the arguments + # to recordUpload2 have no effect. That said, we try to make things + # match up so it is less confusing to readers of the code & tests. $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) ); if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) { $image->recordUpload2( @@ -194,19 +198,39 @@ class NewParserTest extends MediaWikiTestCase { 'Upload of some lame file', 'Some lame file', array( - 'size' => 12345, + 'size' => 7881, 'width' => 1941, 'height' => 220, - 'bits' => 24, + 'bits' => 8, 'media_type' => MEDIATYPE_BITMAP, 'mime' => 'image/jpeg', 'metadata' => serialize( array() ), - 'sha1' => wfBaseConvert( '', 16, 36, 31 ), + 'sha1' => wfBaseConvert( '1', 16, 36, 31 ), 'fileExists' => true ), $this->db->timestamp( '20010115123500' ), $user ); } + $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Thumb.png' ) ); + if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) { + $image->recordUpload2( + '', // archive name + 'Upload of some lame thumbnail', + 'Some lame thumbnail', + array( + 'size' => 22589, + 'width' => 135, + 'height' => 135, + 'bits' => 8, + 'media_type' => MEDIATYPE_BITMAP, + 'mime' => 'image/png', + 'metadata' => serialize( array() ), + 'sha1' => wfBaseConvert( '2', 16, 36, 31 ), + 'fileExists' => true ), + $this->db->timestamp( '20130225203040' ), $user + ); + } + # This image will be blacklisted in [[MediaWiki:Bad image list]] $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) ); if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) { @@ -222,7 +246,7 @@ class NewParserTest extends MediaWikiTestCase { 'media_type' => MEDIATYPE_BITMAP, 'mime' => 'image/jpeg', 'metadata' => serialize( array() ), - 'sha1' => wfBaseConvert( '', 16, 36, 31 ), + 'sha1' => wfBaseConvert( '3', 16, 36, 31 ), 'fileExists' => true ), $this->db->timestamp( '20010115123500' ), $user ); @@ -429,6 +453,10 @@ class NewParserTest extends MediaWikiTestCase { $backend->store( array( 'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => "$base/local-public/3/3a/Foobar.jpg" ) ); + $backend->prepare( array( 'dir' => "$base/local-public/e/ea" ) ); + $backend->store( array( + 'src' => "$IP/skins/monobook/wiki.png", 'dst' => "$base/local-public/e/ea/Thumb.png" + ) ); $backend->prepare( array( 'dir' => "$base/local-public/0/09" ) ); $backend->store( array( 'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => "$base/local-public/0/09/Bad.jpg" @@ -478,8 +506,9 @@ class NewParserTest extends MediaWikiTestCase { "$base/local-thumb/3/3a/Foobar.jpg/70px-Foobar.jpg", "$base/local-thumb/3/3a/Foobar.jpg/960px-Foobar.jpg", + "$base/local-public/e/ea/Thumb.png", + "$base/local-public/0/09/Bad.jpg", - "$base/local-thumb/0/09/Bad.jpg", "$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png", )