$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' );
}
$thumb = false;
$noscale = false;
+ $manualthumb = false;
if ( !$exists ) {
$outerWidth = $hp['width'] + 2;
$manual_img = wfFindFile( $manual_title );
if ( $manual_img ) {
$thumb = $manual_img->getUnscaledThumb( $hp );
+ $manualthumb = true;
} else {
$exists = false;
}
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 ) {
$s .= wfMessage( 'thumbnail_error', '' )->escaped();
$zoomIcon = '';
} else {
- if ( !$noscale ) {
+ if ( !$noscale && !$manualthumb ) {
self::processResponsiveImages( $file, $thumb, $hp );
}
$params = array(
$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(
'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 );
}
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" );
"$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",
"$dir/thumb/3/3a",
"$dir/thumb/3",
+ "$dir/e/ea",
+ "$dir/e",
+
"$dir/0/09/",
"$dir/0/",
"$dir/thumb",
!! input
{{NUMBEROFFILES}}
!! result
-<p>2
+<p>3
</p>
!! end
!! test
Thumbnail image with link parameter
+!! options
+php
!! input
[[Image:foobar.jpg|thumb|link=http://example.com/|Title]]
!! result
!! 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
!!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
# 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(
'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() ) ) ) {
'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
);
$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"
"$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",
)