Merge "Fix link target and retina thumbnails for manual thumbnails. (Bug 45405.)"
authorBrion VIBBER <brion@wikimedia.org>
Fri, 29 Mar 2013 17:48:41 +0000 (17:48 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 29 Mar 2013 17:48:41 +0000 (17:48 +0000)
includes/Linker.php
tests/parser/parserTest.inc
tests/parser/parserTests.txt
tests/phpunit/includes/parser/NewParserTest.php

index a347549..e4222e3 100644 (file)
@@ -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 = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
                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(
index 32b8154..3d34f34 100644 (file)
@@ -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",
index 4a15470..d3bd6a5 100644 (file)
@@ -4782,7 +4782,7 @@ Magic Word: {{NUMBEROFFILES}}
 !! input
 {{NUMBEROFFILES}}
 !! result
-<p>2
+<p>3
 </p>
 !! 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
+<div class="thumb tright"><div class="thumbinner" style="width:137px;"><a href="/wiki/File:Foobar.jpg"><img alt="" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" 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
+Manually-specified thumbnail image with explicit link to wiki page
+!! options
+php
+!! input
+[[Image:Foobar.jpg|thumb=Thumb.png|link=Main Page|Title]]
+!! result
+<div class="thumb tright"><div class="thumbinner" style="width:137px;"><a href="/wiki/Main_Page" title="Main Page"><img alt="" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" 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
+Manually-specified thumbnail image with explicit link to url
+!! options
+php
+!! input
+[[Image:Foobar.jpg|thumb=Thumb.png|link=http://example.com|Title]]
+!! result
+<div class="thumb tright"><div class="thumbinner" style="width:137px;"><a href="http://example.com"><img alt="" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" 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
+Manually-specified thumbnail image with explicit no link
+!! options
+php
+!! input
+[[Image:Foobar.jpg|thumb=Thumb.png|link=|Title]]
+!! result
+<div class="thumb tright"><div class="thumbinner" style="width:137px;"><img alt="" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" class="thumbimage" />  <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
+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
+<div class="thumb tright"><div class="thumbinner" style="width:137px;"><a href="/wiki/Main_Page" title="Main Page"><img alt="alttext" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" 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
 !! input
@@ -9580,7 +9637,7 @@ Fuzz testing: image with bogus manual thumbnail
 !!input
 [[Image:foobar.jpg|thumbnail= ]]
 !!result
-<div class="thumb tright"><div class="thumbinner" style="width:1943px;">Error creating thumbnail:   <div class="thumbcaption"></div></div></div>
+<div class="thumb tright"><div class="thumbinner" style="width:182px;">Error creating thumbnail:   <div class="thumbcaption"></div></div></div>
 
 !!end
 
index 5732beb..77311b9 100644 (file)
@@ -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",
                        )