Applied image attribute improvements from r52726 to galleries as well
authorRemember the dot <rememberthedot@users.mediawiki.org>
Wed, 15 Jul 2009 04:18:16 +0000 (04:18 +0000)
committerRemember the dot <rememberthedot@users.mediawiki.org>
Wed, 15 Jul 2009 04:18:16 +0000 (04:18 +0000)
includes/ImageGallery.php

index 3228b59..987d76a 100644 (file)
@@ -236,7 +236,7 @@ class ImageGallery
                $i = 0;
                foreach ( $this->mImages as $pair ) {
                        $nt = $pair[0];
-                       $text = $pair[1];
+                       $text = $pair[1]; # "text" means "caption" here
 
                        # Give extensions a chance to select the file revision for us
                        $time = $descQuery = false;
@@ -265,6 +265,15 @@ class ImageGallery
                                        . htmlspecialchars( $img->getLastError() ) . '</div>';
                        } else {
                                $vpad = floor( ( 1.25*$this->mHeights - $thumb->height ) /2 ) - 2;
+                               
+                               $imageParameters = array(
+                                       'desc-link' => true,
+                                       'desc-query' => $descQuery
+                               );
+                               # In the absence of a caption, fall back on providing screen readers with the filename as alt text
+                               if ( $text == '' ) {
+                                       $imageParameters['alt'] = $nt->getText();
+                               }
 
                                $thumbhtml = "\n\t\t\t".
                                        '<div class="thumb" style="padding: ' . $vpad . 'px 0; width: ' .($this->mWidths+30).'px;">'
@@ -272,7 +281,7 @@ class ImageGallery
                                        # handlers since they may emit block-level elements as opposed to simple <img> tags.
                                        # ref http://css-discuss.incutio.com/?page=CenteringBlockElement
                                        . '<div style="margin-left: auto; margin-right: auto; width: ' .$this->mWidths.'px;">'
-                                       . $thumb->toHtml( array( 'desc-link' => true, 'desc-query' => $descQuery ) ) . '</div></div>';
+                                       . $thumb->toHtml( $imageParameters ) . '</div></div>';
 
                                // Call parser transform hook
                                if ( $this->mParser && $img->getHandler() ) {