Fixed inconsistent error return in Image::getThumbnail() -- was returning null if...
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 17 Jun 2006 04:11:21 +0000 (04:11 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 17 Jun 2006 04:11:21 +0000 (04:11 +0000)
includes/Image.php
includes/ImageGallery.php

index 3f5e642..0b1d8d6 100644 (file)
@@ -888,7 +888,7 @@ class Image
         *
         * @param integer $width        maximum width of the generated thumbnail
         * @param integer $height       maximum height of the image (optional)
-        * @return ThumbnailImage
+        * @return ThumbnailImage or null on failure
         * @public
         */
        function getThumbnail( $width, $height=-1 ) {
@@ -904,9 +904,6 @@ class Image
                }
                else $thumb= NULL; #not a bitmap or renderable image, don't try.
 
-               if( is_null( $thumb ) ) {
-                       $thumb = $this->iconThumb();
-               }
                return $thumb;
        }
 
@@ -936,7 +933,7 @@ class Image
         * Returns an object which can return the pathname, URL, and physical
         * pixel size of the thumbnail -- or null on failure.
         *
-        * @return ThumbnailImage
+        * @return ThumbnailImage or null on failure
         * @private
         */
        function renderThumb( $width, $useScript = true ) {
index 08528f5..4ae92d0 100644 (file)
@@ -98,7 +98,7 @@ class ImageGallery
         *
         */
        function toHTML() {
-               global $wgLang, $wgUser;
+               global $wgLang, $wgUser, $wgIgnoreImageErrors;
 
                $sk = $wgUser->getSkin();
 
@@ -146,16 +146,29 @@ class ImageGallery
 
                        $s .= ($i%4==0) ? '<tr>' : '';
                        $thumb = $img->getThumbnail( 120, 120 );
-                       $vpad = floor( ( 150 - $thumb->height ) /2 ) - 2;
-                       $s .= '<td><div class="gallerybox">' . '<div class="thumb" style="padding: ' . $vpad . 'px 0;">';
-
-                       # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
-                       # in version 4.8.6 generated crackpot html in its absence, see:
-                       # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
-                       $s .= $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div><div class="gallerytext">' . "\n" .
-                               $textlink . $text . $nb .
-                               '</div>';
-                       $s .= "</div></td>\n";
+                       if ( !$thumb && $wgIgnoreImageErrors ) {
+                               $thumb = $img->iconThumb();
+                       }
+                       if ( $thumb ) {
+                               $vpad = floor( ( 150 - $thumb->height ) /2 ) - 2;
+                               $s .= '<td><div class="gallerybox">' . '<div class="thumb" style="padding: ' . $vpad . 'px 0;">';
+
+                               # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
+                               # in version 4.8.6 generated crackpot html in its absence, see:
+                               # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
+                               $s .= $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '</div><div class="gallerytext">' . "\n" .
+                                       $textlink . $text . $nb .
+                                       '</div>';
+                               $s .= "</div></td>\n";
+                       } else {
+                               # Error during thumbnail generation
+                               $s .= '<td><div class="gallerybox" style="height: 152px;">' .
+                                       #htmlspecialchars( $nt->getText() ) . "<br />\n" .
+                                       htmlspecialchars( $img->getLastError() ) .
+                                       "</div><div class=\"gallerytext\">\n" .
+                                       $textlink . $text . $nb .
+                                       "</div></td>\n";
+                       }
                        $s .= ($i%4==3) ? '</tr>' : '';
                        $i++;
                }