r86752 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86751‎ | r86752 | r86753 >
Date:09:55, 23 April 2011
Author:diebuche
Status:ok
Tags:
Comment:
Reverting r86749: The alt stuff is far too simplistic. One way to fix it would be to generalize makeImage() in the parser to process gallery params as well, but I don't have time to that now
Modified paths:
  • /trunk/phase3/includes/ImageGallery.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/parser/parserTests.txt
@@ -7312,7 +7312,6 @@
73137313 File:Nonexistant.jpg
73147314 image:foobar.jpg|some '''caption''' [[Main Page]]
73157315 image:foobar.jpg
7316 -image:foobar.jpg|Blabla|alt= This is a foo-bar.|blabla.
73177316 </gallery>
73187317 !! result
73197318 <ul class="gallery" style="max-width: 202px;_width: 202px;">
@@ -7341,13 +7340,6 @@
73427341 <div class="gallerytext">
73437342 </div>
73447343 </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>
73527344 </ul>
73537345
73547346 !! end
@@ -7433,6 +7425,17 @@
74347426 !! end
74357427
74367428 !! 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+
 7437+!! end
 7438+
 7439+!! test
74377440 HTML Hex character encoding (spells the word "JavaScript")
74387441 !! input
74397442 &#x4A;&#x061;&#x0076;&#x00061;&#x000053;&#x0000063;&#114;&#x0000069;&#00000112;&#x0000000074;
Index: trunk/phase3/includes/parser/Parser.php
@@ -4733,37 +4733,21 @@
47344734 if ( strpos( $matches[0], '%' ) !== false ) {
47354735 $matches[1] = rawurldecode( $matches[1] );
47364736 }
4737 - $title = Title::newFromText( $matches[1], NS_FILE );
4738 - if ( is_null( $title ) ) {
 4737+ $tp = Title::newFromText( $matches[1], NS_FILE );
 4738+ $nt =& $tp;
 4739+ if ( is_null( $nt ) ) {
47394740 # Bogus title. Ignore these so we don't bomb out later.
47404741 continue;
47414742 }
4742 -
4743 - $label = '';
4744 - $alt = '';
47454743 if ( isset( $matches[3] ) ) {
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 - $altmatches = StringUtils::explode('|', $matches[3]);
4751 -
4752 - foreach ( $altmatches as $altmatch ) {
4753 - if ( substr( $altmatch, 0, 4 ) === 'alt=' ) {
4754 - $alt = $this->stripAltText( trim( substr( $altmatch, 4 ) ), false );
4755 - }
4756 - else {
4757 - // concatenate all other pipes
4758 - $label .= '|' . $altmatch;
4759 - }
4760 - }
4761 - // remove the first pipe
4762 - $label = substr( $label, 1 );
 4744+ $label = $matches[3];
 4745+ } else {
 4746+ $label = '';
47634747 }
47644748
47654749 $html = $this->recursiveTagParse( trim( $label ) );
47664750
4767 - $ig->add( $title, $html, $alt );
 4751+ $ig->add( $nt, $html );
47684752 }
47694753 return $ig->toHTML();
47704754 }
Index: trunk/phase3/includes/ImageGallery.php
@@ -136,15 +136,14 @@
137137 * Add an image to the gallery.
138138 *
139139 * @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.
141 - * @param $alt String: Alt text for the image
 140+ * @param $html String: additional HTML text to be shown. The name and size of the image are always shown.
142141 */
143 - function add( $title, $html = '', $alt = '' ) {
 142+ function add( $title, $html='' ) {
144143 if ( $title instanceof File ) {
145144 // Old calling convention
146145 $title = $title->getTitle();
147146 }
148 - $this->mImages[] = array( $title, $html, $alt );
 147+ $this->mImages[] = array( $title, $html );
149148 wfDebug( "ImageGallery::add " . $title->getText() . "\n" );
150149 }
151150
@@ -152,15 +151,14 @@
153152 * Add an image at the beginning of the gallery.
154153 *
155154 * @param $title Title object of the image that is added to the gallery
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
 155+ * @param $html String: Additional HTML text to be shown. The name and size of the image are always shown.
158156 */
159 - function insert( $title, $html='', $alt='' ) {
 157+ function insert( $title, $html='' ) {
160158 if ( $title instanceof File ) {
161159 // Old calling convention
162160 $title = $title->getTitle();
163161 }
164 - array_unshift( $this->mImages, array( &$title, $html, $alt ) );
 162+ array_unshift( $this->mImages, array( &$title, $html ) );
165163 }
166164
167165
@@ -220,16 +218,15 @@
221219 if ( $this->mPerRow > 0 ) {
222220 $maxwidth = $this->mPerRow * ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING + self::GB_BORDERS );
223221 $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
225222 $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $oldStyle;
226223 }
227224
228225 $attribs = Sanitizer::mergeAttributes(
229226 array( 'class' => 'gallery' ), $this->mAttribs );
230227
231 - $output = Xml::openElement( 'ul', $attribs );
 228+ $s = Xml::openElement( 'ul', $attribs );
232229 if ( $this->mCaption ) {
233 - $output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
 230+ $s .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
234231 }
235232
236233 $params = array( 'width' => $this->mWidths, 'height' => $this->mHeights );
@@ -237,7 +234,6 @@
238235 foreach ( $this->mImages as $pair ) {
239236 $nt = $pair[0];
240237 $text = $pair[1]; # "text" means "caption" here
241 - $alt = $pair[2];
242238
243239 $descQuery = false;
244240 if ( $nt->getNamespace() == NS_FILE ) {
@@ -276,19 +272,18 @@
277273 $thumbhtml = "\n\t\t\t".'<div style="height: '.(self::THUMB_PADDING + $this->mHeights).'px;">'
278274 . htmlspecialchars( $img->getLastError() ) . '</div>';
279275 } else {
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.
 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.
282278 $minThumbHeight = $thumb->height > 17 ? $thumb->height : 17;
283279 $vpad = floor(( self::THUMB_PADDING + $this->mHeights - $minThumbHeight ) /2);
284280
285281
286282 $imageParameters = array(
287283 'desc-link' => true,
288 - 'desc-query' => $descQuery,
289 - 'alt' => $alt,
 284+ 'desc-query' => $descQuery
290285 );
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 == '' ) {
 286+ # In the absence of a caption, fall back on providing screen readers with the filename as alt text
 287+ if ( $text == '' ) {
293288 $imageParameters['alt'] = $nt->getText();
294289 }
295290
@@ -313,14 +308,14 @@
314309
315310 if( $this->mShowBytes ) {
316311 if( $img ) {
317 - $fileSize = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
 312+ $nb = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
318313 $wgLang->formatNum( $img->getSize() ) );
319314 } else {
320 - $fileSize = wfMsgHtml( 'filemissing' );
 315+ $nb = wfMsgHtml( 'filemissing' );
321316 }
322 - $fileSize = "$fileSize<br />\n";
 317+ $nb = "$nb<br />\n";
323318 } else {
324 - $fileSize = '';
 319+ $nb = '';
325320 }
326321
327322 $textlink = $this->mShowFilename ?
@@ -337,20 +332,20 @@
338333 # in version 4.8.6 generated crackpot html in its absence, see:
339334 # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
340335
341 - # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
 336+ # Weird double wrapping in div needed due to FF2 bug
342337 # Can be safely removed if FF2 falls completely out of existance
343 - $output .=
 338+ $s .=
344339 "\n\t\t" . '<li class="gallerybox" style="width: ' . ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING ) . 'px">'
345340 . '<div style="width: ' . ( $this->mWidths + self::THUMB_PADDING + self::GB_PADDING ) . 'px">'
346341 . $thumbhtml
347342 . "\n\t\t\t" . '<div class="gallerytext">' . "\n"
348 - . $textlink . $text . $fileSize
 343+ . $textlink . $text . $nb
349344 . "\n\t\t\t</div>"
350345 . "\n\t\t</div></li>";
351346 }
352 - $output .= "\n</ul>";
 347+ $s .= "\n</ul>";
353348
354 - return $output;
 349+ return $s;
355350 }
356351
357352 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r86789follow up r86752 with some content for the result of “Gallery with wikitext...mah19:57, 23 April 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86749Add ability to use add alt texts for images in galleries ( Bug 18682 ). Patch...diebuche07:27, 23 April 2011

Status & tagging log