r83965 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83964‎ | r83965 | r83966 >
Date:21:08, 14 March 2011
Author:hartman
Status:resolved (Comments)
Tags:
Comment:
Fix overestimation of max-width when using perrow mode.
Also use const variables to make this more readable.

Fixes bug 27577
Follow up to r77411
Modified paths:
  • /trunk/phase3/includes/ImageGallery.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/parser/parserTests.txt
@@ -6732,7 +6732,7 @@
67336733 image:foobar.jpg
67346734 </gallery>
67356735 !! result
6736 -<ul class="gallery" style="max-width: 220px;_width: 220px;">
 6736+<ul class="gallery" style="max-width: 202px;_width: 202px;">
67376737 <li class='gallerycaption'>Foo <a href="https://www.mediawiki.org/wiki/Main_Page">Main Page</a></li>
67386738 <li class="gallerybox" style="width: 95px"><div style="width: 95px">
67396739 <div style="height: 70px;">Nonexistant.jpg</div>
Index: trunk/phase3/includes/ImageGallery.php
@@ -35,6 +35,13 @@
3636 private $mAttribs = array();
3737
3838 /**
 39+ * Fixed margins
 40+ */
 41+ const THUMB_PADDING = 30;
 42+ const GB_PADDING = 5;
 43+ const GB_BORDERS = 6;
 44+
 45+ /**
3946 * Create a new image gallery object.
4047 */
4148 function __construct( ) {
@@ -226,7 +233,7 @@
227234 $sk = $this->getSkin();
228235
229236 if ( $this->mPerRow > 0 ) {
230 - $maxwidth = $this->mPerRow * ( $this->mWidths + 50 );
 237+ $maxwidth = $this->mPerRow * ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING + self::GB_BORDERS );
231238 $oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : "";
232239 $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $oldStyle;
233240 }
@@ -258,11 +265,11 @@
259266
260267 if( !$img ) {
261268 # We're dealing with a non-image, spit out the name and be done with it.
262 - $thumbhtml = "\n\t\t\t".'<div style="height: '.(30 + $this->mHeights).'px;">'
 269+ $thumbhtml = "\n\t\t\t".'<div style="height: '.(self::THUMB_PADDING + $this->mHeights).'px;">'
263270 . htmlspecialchars( $nt->getText() ) . '</div>';
264271 } elseif( $this->mHideBadImages && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) {
265272 # The image is blacklisted, just show it as a text link.
266 - $thumbhtml = "\n\t\t\t".'<div style="height: '.(30 + $this->mHeights).'px;">' .
 273+ $thumbhtml = "\n\t\t\t".'<div style="height: '.(self::THUMB_PADDING + $this->mHeights).'px;">' .
267274 $sk->link(
268275 $nt,
269276 htmlspecialchars( $nt->getText() ),
@@ -273,13 +280,13 @@
274281 '</div>';
275282 } elseif( !( $thumb = $img->transform( $params ) ) ) {
276283 # Error generating thumbnail.
277 - $thumbhtml = "\n\t\t\t".'<div style="height: '.(30 + $this->mHeights).'px;">'
 284+ $thumbhtml = "\n\t\t\t".'<div style="height: '.(self::THUMB_PADDING + $this->mHeights).'px;">'
278285 . htmlspecialchars( $img->getLastError() ) . '</div>';
279286 } else {
280287 //We get layout problems with the margin, if the image is smaller
281288 //than the line-height, so we less margin in these cases.
282289 $minThumbHeight = $thumb->height > 17 ? $thumb->height : 17;
283 - $vpad = floor(( 30 + $this->mHeights - $minThumbHeight ) /2);
 290+ $vpad = floor(( self::THUMB_PADDING + $this->mHeights - $minThumbHeight ) /2);
284291
285292
286293 $imageParameters = array(
@@ -293,7 +300,7 @@
294301
295302 # Set both fixed width and min-height.
296303 $thumbhtml = "\n\t\t\t".
297 - '<div class="thumb" style="width: ' .($this->mWidths+30).'px;">'
 304+ '<div class="thumb" style="width: ' .($this->mWidths + self::THUMB_PADDING).'px;">'
298305 # Auto-margin centering for block-level elements. Needed now that we have video
299306 # handlers since they may emit block-level elements as opposed to simple <img> tags.
300307 # ref http://css-discuss.incutio.com/?page=CenteringBlockElement
@@ -339,8 +346,8 @@
340347 # Weird double wrapping in div needed due to FF2 bug
341348 # Can be safely removed if FF2 falls completely out of existance
342349 $s .=
343 - "\n\t\t" . '<li class="gallerybox" style="width: ' . ( $this->mWidths + 35 ) . 'px">'
344 - . '<div style="width: ' . ( $this->mWidths + 35 ) . 'px">'
 350+ "\n\t\t" . '<li class="gallerybox" style="width: ' . ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING ) . 'px">'
 351+ . '<div style="width: ' . ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING ) . 'px">'
345352 . $thumbhtml
346353 . "\n\t\t\t" . '<div class="gallerytext">' . "\n"
347354 . $textlink . $text . $nb

Follow-up revisions

RevisionCommit summaryAuthorDate
r85434MFT: r83885, r83891, r83897, r83902, r83903, r83934, r83965, r83979, r83988, ...demon13:38, 5 April 2011
r87266Adjust maxwidth calculation for galleries. Bug 27577diebuche18:00, 2 May 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r77411Give image <gallery>s fluid width...simetrical00:11, 29 November 2010

Comments

#Comment by GreenReaper (talk | contribs)   03:10, 2 May 2011

The maxwidth calculation seems off. I had to change it to get it to this for the specified number of columns to be used:

$maxwidth = $this->mPerRow * ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING + self::GB_BORDERS + 1) + 1;

Example: http://en.wikifur.com/wiki/Wikifur_gallery_%28Film/media,_logos,games,misc.%29 (running on 1.17) - try reducing max-width by even one pixel in Firebug on Firefox 4 and we get one less column.

#Comment by Kaldari (talk | contribs)   21:50, 4 July 2011

We might want to remove the underscore hack unless we really think we have people running parser tests in IE6 :)

#Comment by DieBuche (talk | contribs)   10:23, 15 July 2011

Was redone in r91573

Status & tagging log