Index: trunk/phase3/tests/parser/parserTests.txt |
— | — | @@ -7312,6 +7312,7 @@ |
7313 | 7313 | File:Nonexistant.jpg |
7314 | 7314 | image:foobar.jpg|some '''caption''' [[Main Page]] |
7315 | 7315 | image:foobar.jpg |
| 7316 | +image:foobar.jpg|Blabla|alt=This is a foo-bar.|blabla. |
7316 | 7317 | </gallery> |
7317 | 7318 | !! result |
7318 | 7319 | <ul class="gallery" style="max-width: 202px;_width: 202px;"> |
— | — | @@ -7340,11 +7341,45 @@ |
7341 | 7342 | <div class="gallerytext"> |
7342 | 7343 | </div> |
7343 | 7344 | </div></li> |
| 7345 | + <li class="gallerybox" style="width: 95px"><div style="width: 95px"> |
| 7346 | + <div class="thumb" style="width: 90px;"><div style="margin:26px auto;"><a href="https://www.mediawiki.org/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> |
| 7347 | + <div class="gallerytext"> |
| 7348 | +<p>Blabla|blabla. |
| 7349 | +</p> |
| 7350 | + </div> |
| 7351 | + </div></li> |
7344 | 7352 | </ul> |
7345 | 7353 | |
7346 | 7354 | !! end |
7347 | 7355 | |
7348 | 7356 | !! test |
| 7357 | +Gallery with wikitext inside caption |
| 7358 | +!! input |
| 7359 | +<gallery> |
| 7360 | +File:foobar.jpg|[[File:foobar.jpg|20px|desc|alt=inneralt]]|alt=galleryalt |
| 7361 | +File:foobar.jpg|{{Test|unamedParam|alt=param}}|alt=galleryalt |
| 7362 | +</gallery> |
| 7363 | +!! result |
| 7364 | +<ul class="gallery"> |
| 7365 | + <li class="gallerybox" style="width: 155px"><div style="width: 155px"> |
| 7366 | + <div class="thumb" style="width: 150px;"><div style="margin:66px auto;"><a href="https://www.mediawiki.org/wiki/File:Foobar.jpg" class="image"><img alt="galleryalt" src="http://example.com/images/3/3a/Foobar.jpg" width="120" height="14" /></a></div></div> |
| 7367 | + <div class="gallerytext"> |
| 7368 | +<p><a href="https://www.mediawiki.org/wiki/File:Foobar.jpg" class="image" title="desc"><img alt="inneralt" src="http://example.com/images/3/3a/Foobar.jpg" width="20" height="2" /></a> |
| 7369 | +</p> |
| 7370 | + </div> |
| 7371 | + </div></li> |
| 7372 | + <li class="gallerybox" style="width: 155px"><div style="width: 155px"> |
| 7373 | + <div class="thumb" style="width: 150px;"><div style="margin:66px auto;"><a href="https://www.mediawiki.org/wiki/File:Foobar.jpg" class="image"><img alt="galleryalt" src="http://example.com/images/3/3a/Foobar.jpg" width="120" height="14" /></a></div></div> |
| 7374 | + <div class="gallerytext"> |
| 7375 | +<p>This is a test template |
| 7376 | +</p> |
| 7377 | + </div> |
| 7378 | + </div></li> |
| 7379 | +</ul> |
| 7380 | + |
| 7381 | +!! end |
| 7382 | + |
| 7383 | +!! test |
7349 | 7384 | gallery (with showfilename option) |
7350 | 7385 | !! input |
7351 | 7386 | <gallery showfilename> |
— | — | @@ -7425,33 +7460,6 @@ |
7426 | 7461 | !! end |
7427 | 7462 | |
7428 | 7463 | !! test |
7429 | | -Gallery with wikitext inside caption |
7430 | | -!! input |
7431 | | -<gallery> |
7432 | | -File:Wiki.png|[[File:Wiki.png|20px|desc|alt=inneralt]]|alt=galleryalt |
7433 | | -File:Wiki.png|{{tl|test|alt=param}}|alt=galleryalt |
7434 | | -</gallery> |
7435 | | -!! result |
7436 | | -<ul class="gallery"> |
7437 | | - <li class="gallerybox" style="width: 155px"><div style="width: 155px"> |
7438 | | - <div style="height: 150px;">Wiki.png</div> |
7439 | | - <div class="gallerytext"> |
7440 | | -<p><a href="https://www.mediawiki.org/index.php?title=Special:Upload&wpDestFile=Wiki.png" class="new" title="File:Wiki.png">desc</a>|alt=galleryalt |
7441 | | -</p> |
7442 | | - </div> |
7443 | | - </div></li> |
7444 | | - <li class="gallerybox" style="width: 155px"><div style="width: 155px"> |
7445 | | - <div style="height: 150px;">Wiki.png</div> |
7446 | | - <div class="gallerytext"> |
7447 | | -<p><a href="https://www.mediawiki.org/index.php?title=Template:Tl&action=edit&redlink=1" class="new" title="Template:Tl (page does not exist)">Template:Tl</a>|alt=galleryalt |
7448 | | -</p> |
7449 | | - </div> |
7450 | | - </div></li> |
7451 | | -</ul> |
7452 | | - |
7453 | | -!! end |
7454 | | - |
7455 | | -!! test |
7456 | 7464 | HTML Hex character encoding (spells the word "JavaScript") |
7457 | 7465 | !! input |
7458 | 7466 | JavaScript |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -4733,21 +4733,38 @@ |
4734 | 4734 | if ( strpos( $matches[0], '%' ) !== false ) { |
4735 | 4735 | $matches[1] = rawurldecode( $matches[1] ); |
4736 | 4736 | } |
4737 | | - $tp = Title::newFromText( $matches[1], NS_FILE ); |
4738 | | - $nt =& $tp; |
4739 | | - if ( is_null( $nt ) ) { |
| 4737 | + $title = Title::newFromText( $matches[1], NS_FILE ); |
| 4738 | + if ( is_null( $title ) ) { |
4740 | 4739 | # Bogus title. Ignore these so we don't bomb out later. |
4741 | 4740 | continue; |
4742 | 4741 | } |
| 4742 | + |
| 4743 | + $label = ''; |
| 4744 | + $alt = ''; |
4743 | 4745 | if ( isset( $matches[3] ) ) { |
4744 | | - $label = $matches[3]; |
4745 | | - } else { |
4746 | | - $label = ''; |
| 4746 | + // look for an |alt= definition while trying not to break existing |
| 4747 | + // captions with multiple pipes (|) in it, until a more sensible grammar |
| 4748 | + // is defined for images in galleries |
| 4749 | + |
| 4750 | + $matches[3] = $this->recursiveTagParse( trim( $matches[3] ) ); |
| 4751 | + $altmatches = StringUtils::explode('|', $matches[3]); |
| 4752 | + $magicWordAlt = MagicWord::get( 'img_alt' ); |
| 4753 | + |
| 4754 | + foreach ( $altmatches as $altmatch ) { |
| 4755 | + $match = $magicWordAlt->matchVariableStartToEnd( $altmatch ); |
| 4756 | + if ( $match ) { |
| 4757 | + $alt = $this->stripAltText( $match, false ); |
| 4758 | + } |
| 4759 | + else { |
| 4760 | + // concatenate all other pipes |
| 4761 | + $label .= '|' . $altmatch; |
| 4762 | + } |
| 4763 | + } |
| 4764 | + // remove the first pipe |
| 4765 | + $label = substr( $label, 1 ); |
4747 | 4766 | } |
4748 | 4767 | |
4749 | | - $html = $this->recursiveTagParse( trim( $label ) ); |
4750 | | - |
4751 | | - $ig->add( $nt, $html ); |
| 4768 | + $ig->add( $title, $label, $alt ); |
4752 | 4769 | } |
4753 | 4770 | return $ig->toHTML(); |
4754 | 4771 | } |
Index: trunk/phase3/includes/MagicWord.php |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | var $mRegexStart = ''; |
37 | 37 | var $mBaseRegex = ''; |
38 | 38 | var $mVariableRegex = ''; |
| 39 | + var $mVariableStartToEndRegex = ''; |
39 | 40 | var $mModified = false; |
40 | 41 | var $mFound = false; |
41 | 42 | |
Index: trunk/phase3/includes/ImageGallery.php |
— | — | @@ -136,14 +136,15 @@ |
137 | 137 | * Add an image to the gallery. |
138 | 138 | * |
139 | 139 | * @param $title Title object of the image that is added to the gallery |
140 | | - * @param $html String: additional HTML text to be shown. The name and size of the image are always shown. |
| 140 | + * @param $html String: Additional HTML text to be shown. The name and size of the image are always shown. |
| 141 | + * @param $alt String: Alt text for the image |
141 | 142 | */ |
142 | | - function add( $title, $html='' ) { |
| 143 | + function add( $title, $html = '', $alt = '' ) { |
143 | 144 | if ( $title instanceof File ) { |
144 | 145 | // Old calling convention |
145 | 146 | $title = $title->getTitle(); |
146 | 147 | } |
147 | | - $this->mImages[] = array( $title, $html ); |
| 148 | + $this->mImages[] = array( $title, $html, $alt ); |
148 | 149 | wfDebug( "ImageGallery::add " . $title->getText() . "\n" ); |
149 | 150 | } |
150 | 151 | |
— | — | @@ -151,14 +152,15 @@ |
152 | 153 | * Add an image at the beginning of the gallery. |
153 | 154 | * |
154 | 155 | * @param $title Title object of the image that is added to the gallery |
155 | | - * @param $html String: Additional HTML text to be shown. The name and size of the image are always shown. |
| 156 | + * @param $html String: Additional HTML text to be shown. The name and size of the image are always shown. |
| 157 | + * @param $alt String: Alt text for the image |
156 | 158 | */ |
157 | | - function insert( $title, $html='' ) { |
| 159 | + function insert( $title, $html='', $alt='' ) { |
158 | 160 | if ( $title instanceof File ) { |
159 | 161 | // Old calling convention |
160 | 162 | $title = $title->getTitle(); |
161 | 163 | } |
162 | | - array_unshift( $this->mImages, array( &$title, $html ) ); |
| 164 | + array_unshift( $this->mImages, array( &$title, $html, $alt ) ); |
163 | 165 | } |
164 | 166 | |
165 | 167 | |
— | — | @@ -218,15 +220,16 @@ |
219 | 221 | if ( $this->mPerRow > 0 ) { |
220 | 222 | $maxwidth = $this->mPerRow * ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING + self::GB_BORDERS ); |
221 | 223 | $oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : ""; |
| 224 | + # _width is ignored by any sane browser. IE6 doesn't know max-width so it uses _width instead |
222 | 225 | $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $oldStyle; |
223 | 226 | } |
224 | 227 | |
225 | 228 | $attribs = Sanitizer::mergeAttributes( |
226 | 229 | array( 'class' => 'gallery' ), $this->mAttribs ); |
227 | 230 | |
228 | | - $s = Xml::openElement( 'ul', $attribs ); |
| 231 | + $output = Xml::openElement( 'ul', $attribs ); |
229 | 232 | if ( $this->mCaption ) { |
230 | | - $s .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>"; |
| 233 | + $output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>"; |
231 | 234 | } |
232 | 235 | |
233 | 236 | $params = array( 'width' => $this->mWidths, 'height' => $this->mHeights ); |
— | — | @@ -234,6 +237,7 @@ |
235 | 238 | foreach ( $this->mImages as $pair ) { |
236 | 239 | $nt = $pair[0]; |
237 | 240 | $text = $pair[1]; # "text" means "caption" here |
| 241 | + $alt = $pair[2]; |
238 | 242 | |
239 | 243 | $descQuery = false; |
240 | 244 | if ( $nt->getNamespace() == NS_FILE ) { |
— | — | @@ -272,18 +276,19 @@ |
273 | 277 | $thumbhtml = "\n\t\t\t".'<div style="height: '.(self::THUMB_PADDING + $this->mHeights).'px;">' |
274 | 278 | . htmlspecialchars( $img->getLastError() ) . '</div>'; |
275 | 279 | } else { |
276 | | - //We get layout problems with the margin, if the image is smaller |
277 | | - //than the line-height, so we less margin in these cases. |
| 280 | + # We get layout problems with the margin, if the image is smaller |
| 281 | + # than the line-height (17), so we add less margin in these cases. |
278 | 282 | $minThumbHeight = $thumb->height > 17 ? $thumb->height : 17; |
279 | 283 | $vpad = floor(( self::THUMB_PADDING + $this->mHeights - $minThumbHeight ) /2); |
280 | 284 | |
281 | 285 | |
282 | 286 | $imageParameters = array( |
283 | 287 | 'desc-link' => true, |
284 | | - 'desc-query' => $descQuery |
| 288 | + 'desc-query' => $descQuery, |
| 289 | + 'alt' => $alt, |
285 | 290 | ); |
286 | | - # In the absence of a caption, fall back on providing screen readers with the filename as alt text |
287 | | - if ( $text == '' ) { |
| 291 | + # In the absence of both alt text and caption, fall back on providing screen readers with the filename as alt text |
| 292 | + if ( $alt == '' && $text == '' ) { |
288 | 293 | $imageParameters['alt'] = $nt->getText(); |
289 | 294 | } |
290 | 295 | |
— | — | @@ -308,14 +313,14 @@ |
309 | 314 | |
310 | 315 | if( $this->mShowBytes ) { |
311 | 316 | if( $img ) { |
312 | | - $nb = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'), |
| 317 | + $fileSize = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'), |
313 | 318 | $wgLang->formatNum( $img->getSize() ) ); |
314 | 319 | } else { |
315 | | - $nb = wfMsgHtml( 'filemissing' ); |
| 320 | + $fileSize = wfMsgHtml( 'filemissing' ); |
316 | 321 | } |
317 | | - $nb = "$nb<br />\n"; |
| 322 | + $fileSize = "$fileSize<br />\n"; |
318 | 323 | } else { |
319 | | - $nb = ''; |
| 324 | + $fileSize = ''; |
320 | 325 | } |
321 | 326 | |
322 | 327 | $textlink = $this->mShowFilename ? |
— | — | @@ -332,20 +337,20 @@ |
333 | 338 | # in version 4.8.6 generated crackpot html in its absence, see: |
334 | 339 | # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar |
335 | 340 | |
336 | | - # Weird double wrapping in div needed due to FF2 bug |
| 341 | + # Weird double wrapping (the extra div inside the li) needed due to FF2 bug |
337 | 342 | # Can be safely removed if FF2 falls completely out of existance |
338 | | - $s .= |
| 343 | + $output .= |
339 | 344 | "\n\t\t" . '<li class="gallerybox" style="width: ' . ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING ) . 'px">' |
340 | 345 | . '<div style="width: ' . ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING ) . 'px">' |
341 | 346 | . $thumbhtml |
342 | 347 | . "\n\t\t\t" . '<div class="gallerytext">' . "\n" |
343 | | - . $textlink . $text . $nb |
| 348 | + . $textlink . $text . $fileSize |
344 | 349 | . "\n\t\t\t</div>" |
345 | 350 | . "\n\t\t</div></li>"; |
346 | 351 | } |
347 | | - $s .= "\n</ul>"; |
| 352 | + $output .= "\n</ul>"; |
348 | 353 | |
349 | | - return $s; |
| 354 | + return $output; |
350 | 355 | } |
351 | 356 | |
352 | 357 | /** |