Reverting r86749: The alt stuff is far too simplistic. One way to fix it would be...
authorLeo Koppelkamm <diebuche@users.mediawiki.org>
Sat, 23 Apr 2011 09:55:42 +0000 (09:55 +0000)
committerLeo Koppelkamm <diebuche@users.mediawiki.org>
Sat, 23 Apr 2011 09:55:42 +0000 (09:55 +0000)
includes/ImageGallery.php
includes/parser/Parser.php
tests/parser/parserTests.txt

index 9a37202..f490a38 100644 (file)
@@ -136,15 +136,14 @@ class ImageGallery
         * Add an image to the gallery.
         *
         * @param $title Title object of the image that is added to the gallery
-        * @param $html  String: Additional HTML text to be shown. The name and size of the image are always shown.
-        * @param $alt   String: Alt text for the image
+        * @param $html String: additional HTML text to be shown. The name and size of the image are always shown.
         */
-       function add( $title, $html = '', $alt = '' ) {
+       function add( $title, $html='' ) {
                if ( $title instanceof File ) {
                        // Old calling convention
                        $title = $title->getTitle();
                }
-               $this->mImages[] = array( $title, $html, $alt );
+               $this->mImages[] = array( $title, $html );
                wfDebug( "ImageGallery::add " . $title->getText() . "\n" );
        }
 
@@ -152,15 +151,14 @@ class ImageGallery
        * Add an image at the beginning of the gallery.
        *
        * @param $title Title object of the image that is added to the gallery
-       * @param $html  String: Additional HTML text to be shown. The name and size of the image are always shown.
-       * @param $alt   String: Alt text for the image
+       * @param $html  String:  Additional HTML text to be shown. The name and size of the image are always shown.
        */
-       function insert( $title, $html='', $alt='' ) {
+       function insert( $title, $html='' ) {
                if ( $title instanceof File ) {
                        // Old calling convention
                        $title = $title->getTitle();
                }
-               array_unshift( $this->mImages, array( &$title, $html, $alt ) );
+               array_unshift( $this->mImages, array( &$title, $html ) );
        }
 
 
@@ -220,16 +218,15 @@ class ImageGallery
                if ( $this->mPerRow > 0 ) {
                        $maxwidth = $this->mPerRow * ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING + self::GB_BORDERS );
                        $oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : ""; 
-                       # _width is ignored by any sane browser. IE6 doesn't know max-width so it uses _width instead
                        $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $oldStyle;
                }
 
                $attribs = Sanitizer::mergeAttributes(
                        array( 'class' => 'gallery' ), $this->mAttribs );
 
-               $output = Xml::openElement( 'ul', $attribs );
+               $s = Xml::openElement( 'ul', $attribs );
                if ( $this->mCaption ) {
-                       $output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
+                       $s .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
                }
 
                $params = array( 'width' => $this->mWidths, 'height' => $this->mHeights );
@@ -237,7 +234,6 @@ class ImageGallery
                foreach ( $this->mImages as $pair ) {
                        $nt = $pair[0];
                        $text = $pair[1]; # "text" means "caption" here
-                       $alt = $pair[2];
 
                        $descQuery = false;
                        if ( $nt->getNamespace() == NS_FILE ) {
@@ -276,19 +272,18 @@ class ImageGallery
                                $thumbhtml = "\n\t\t\t".'<div style="height: '.(self::THUMB_PADDING + $this->mHeights).'px;">'
                                        . htmlspecialchars( $img->getLastError() ) . '</div>';
                        } else {
-                               We get layout problems with the margin, if the image is smaller 
-                               # than the line-height (17), so we add less margin in these cases.
+                               //We get layout problems with the margin, if the image is smaller 
+                               //than the line-height, so we less margin in these cases.
                                $minThumbHeight =  $thumb->height > 17 ? $thumb->height : 17;
                                $vpad = floor(( self::THUMB_PADDING + $this->mHeights - $minThumbHeight ) /2);
                                
 
                                $imageParameters = array(
                                        'desc-link' => true,
-                                       'desc-query' => $descQuery,
-                                       'alt' => $alt,
+                                       'desc-query' => $descQuery
                                );
-                               # In the absence of both alt text and caption, fall back on providing screen readers with the filename as alt text
-                               if ( $alt == '' && $text == '' ) {
+                               # In the absence of a caption, fall back on providing screen readers with the filename as alt text
+                               if ( $text == '' ) {
                                        $imageParameters['alt'] = $nt->getText();
                                }
 
@@ -313,14 +308,14 @@ class ImageGallery
 
                        if( $this->mShowBytes ) {
                                if( $img ) {
-                                       $fileSize = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
+                                       $nb = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
                                                $wgLang->formatNum( $img->getSize() ) );
                                } else {
-                                       $fileSize = wfMsgHtml( 'filemissing' );
+                                       $nb = wfMsgHtml( 'filemissing' );
                                }
-                               $fileSize = "$fileSize<br />\n";
+                               $nb = "$nb<br />\n";
                        } else {
-                               $fileSize = '';
+                               $nb = '';
                        }
 
                        $textlink = $this->mShowFilename ?
@@ -337,20 +332,20 @@ class ImageGallery
                        # in version 4.8.6 generated crackpot html in its absence, see:
                        # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
 
-                       # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
+                       # Weird double wrapping in div needed due to FF2 bug
                        # Can be safely removed if FF2 falls completely out of existance
-                       $output .=
+                       $s .=
                                "\n\t\t" . '<li class="gallerybox" style="width: ' . ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING ) . 'px">'
                                        . '<div style="width: ' . ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING ) . 'px">'
                                        . $thumbhtml
                                        . "\n\t\t\t" . '<div class="gallerytext">' . "\n"
-                                               . $textlink . $text . $fileSize
+                                               . $textlink . $text . $nb
                                        . "\n\t\t\t</div>"
                                . "\n\t\t</div></li>";
                }
-               $output .= "\n</ul>";
+               $s .= "\n</ul>";
 
-               return $output;
+               return $s;
        }
 
        /**
index 3dcfe42..ad4ba77 100644 (file)
@@ -4733,37 +4733,21 @@ class Parser {
                        if ( strpos( $matches[0], '%' ) !== false ) {
                                $matches[1] = rawurldecode( $matches[1] );
                        }
-                       $title = Title::newFromText( $matches[1], NS_FILE );
-                       if ( is_null( $title ) ) {
+                       $tp = Title::newFromText( $matches[1], NS_FILE );
+                       $nt =& $tp;
+                       if ( is_null( $nt ) ) {
                                # Bogus title. Ignore these so we don't bomb out later.
                                continue;
                        }
-                       
-                       $label = '';
-                       $alt = '';
                        if ( isset( $matches[3] ) ) {
-                               // look for an |alt= definition while trying not to break existing
-                               // captions with multiple pipes (|) in it, until a more sensible grammar
-                               // is defined for images in galleries
-                               
-                               $altmatches = StringUtils::explode('|', $matches[3]);
-                               
-                               foreach ( $altmatches as $altmatch ) {
-                                       if ( substr( $altmatch, 0, 4 ) === 'alt=' ) {
-                                               $alt = $this->stripAltText( trim( substr( $altmatch, 4 ) ), false );
-                                       }
-                                       else {
-                                               // concatenate all other pipes
-                                               $label .= '|' . $altmatch;
-                                       }
-                               }
-                               // remove the first pipe
-                               $label = substr( $label, 1 );
+                               $label = $matches[3];
+                       } else {
+                               $label = '';
                        }
 
                        $html = $this->recursiveTagParse( trim( $label ) );
 
-                       $ig->add( $title, $html, $alt );
+                       $ig->add( $nt, $html );
                }
                return $ig->toHTML();
        }
index 97a65f4..fd28388 100644 (file)
@@ -7312,7 +7312,6 @@ File:Nonexistant.jpg|caption
 File:Nonexistant.jpg
 image:foobar.jpg|some '''caption''' [[Main Page]]
 image:foobar.jpg
-image:foobar.jpg|Blabla|alt= This is a foo-bar.|blabla.
 </gallery>
 !! result
 <ul class="gallery" style="max-width: 202px;_width: 202px;">
@@ -7341,13 +7340,6 @@ image:foobar.jpg|Blabla|alt= This is a foo-bar.|blabla.
                        <div class="gallerytext">
                        </div>
                </div></li>
-               <li class="gallerybox" style="width: 95px"><div style="width: 95px">
-                       <div class="thumb" style="width: 90px;"><div style="margin:26px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="This is a foo-bar." src="http://example.com/images/3/3a/Foobar.jpg" width="60" height="7" /></a></div></div>
-                       <div class="gallerytext">
-<p>Blabla|blabla.
-</p>
-                       </div>
-               </div></li>
 </ul>
 
 !! end
@@ -7432,6 +7424,17 @@ foobar.jpg
 
 !! end
 
+!! test
+Gallery with wikitext inside caption
+!! input
+<gallery>
+File:Wiki.png|[[File:Wiki.png|20px|desc|alt=inneralt]]|alt=galleryalt
+File:Wiki.png|{{tl|test|alt=param}}|alt=galleryalt
+</gallery>
+!! result
+
+!! end
+
 !! test
 HTML Hex character encoding (spells the word "JavaScript")
 !! input