r41837 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41836‎ | r41837 | r41838 >
Date:16:33, 8 October 2008
Author:simetrical
Status:old (Comments)
Tags:
Comment:
(bug 368) Allow alt= attribute for images

Alt text is now set in the following ways, in decreasing priority:

1) Set to the alt= parameter if present.
2) Set to the unnamed (caption) parameter if present, and if the image does not have the thumb or frame option set (i.e., if the unnamed parameter is not actually being used for a caption -- using it as both caption and alt text would just lead to text being repeated).
3) Set to the empty string.

Title text and captions should not be affected in any case. The only backward-compatibility effect (i.e., on images not using the new alt= syntax) should be that if previously the same text was repeated in the alt text and then again in the caption, the alt text will now be empty. Setting the alt parameter should never change the HTML output compared to not setting it, except of course changing the alt text.

All parser tests pass, except the usual ones.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/MediaTransformOutput.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -3128,11 +3128,20 @@
31293129 !! input
31303130 [[Image:Foobar.jpg|frame|left|This is a test image [[Main Page]]]]
31313131 !! result
3132 -<div class="thumb tleft"><div class="thumbinner" style="width:1943px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="This is a test image Main Page"><img alt="This is a test image Main Page" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" border="0" class="thumbimage" /></a> <div class="thumbcaption">This is a test image <a href="https://www.mediawiki.org/wiki/Main_Page" title="Main Page">Main Page</a></div></div></div>
 3132+<div class="thumb tleft"><div class="thumbinner" style="width:1943px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="This is a test image Main Page"><img alt="" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" border="0" class="thumbimage" /></a> <div class="thumbcaption">This is a test image <a href="https://www.mediawiki.org/wiki/Main_Page" title="Main Page">Main Page</a></div></div></div>
31333133
31343134 !! end
31353135
31363136 !! test
 3137+Image with frame and link and explicit alt
 3138+!! input
 3139+[[Image:Foobar.jpg|frame|left|This is a test image [[Main Page]]|alt=Altitude]]
 3140+!! result
 3141+<div class="thumb tleft"><div class="thumbinner" style="width:1943px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="This is a test image Main Page"><img alt="Altitude" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" border="0" class="thumbimage" /></a> <div class="thumbcaption">This is a test image <a href="https://www.mediawiki.org/wiki/Main_Page" title="Main Page">Main Page</a></div></div></div>
 3142+
 3143+!! end
 3144+
 3145+!! test
31373146 Link to image page- image page normally doesn't exists, hence edit link
31383147 Add test with existing image page
31393148 #<p><a href="https://www.mediawiki.org/wiki/Image:Test" title="Image:Test">Image:test</a>
@@ -3157,16 +3166,25 @@
31583167 !! input
31593168 [[Image:foobar.jpg|thumb|http://example.com]]
31603169 !! result
3161 -<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="http://example.com"><img alt="http://example.com" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div><a href="http://example.com" class="external free" title="http://example.com" rel="nofollow">http://example.com</a></div></div></div>
 3170+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="http://example.com"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div><a href="http://example.com" class="external free" title="http://example.com" rel="nofollow">http://example.com</a></div></div></div>
31623171
31633172 !! end
31643173
31653174 !! test
 3175+Thumbnail image caption with a free URL and explicit alt
 3176+!! input
 3177+[[Image:foobar.jpg|thumb|http://example.com|alt=Alteration]]
 3178+!! result
 3179+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="http://example.com"><img alt="Alteration" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div><a href="http://example.com" class="external free" title="http://example.com" rel="nofollow">http://example.com</a></div></div></div>
 3180+
 3181+!! end
 3182+
 3183+!! test
31663184 BUG 1887: A ISBN with a thumbnail
31673185 !! input
31683186 [[Image:foobar.jpg|thumb|ISBN 1235467890]]
31693187 !! result
3170 -<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="ISBN 1235467890"><img alt="ISBN 1235467890" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div><a href="https://www.mediawiki.org/wiki/Special:BookSources/1235467890" class="internal">ISBN 1235467890</a></div></div></div>
 3188+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="ISBN 1235467890"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div><a href="https://www.mediawiki.org/wiki/Special:BookSources/1235467890" class="internal">ISBN 1235467890</a></div></div></div>
31713189
31723190 !! end
31733191
@@ -3175,7 +3193,7 @@
31763194 !! input
31773195 [[Image:foobar.jpg|thumb|This is RFC 12354]]
31783196 !! result
3179 -<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="This is RFC 12354"><img alt="This is RFC 12354" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>This is <a href="http://tools.ietf.org/html/rfc12354" class="external" title="http://tools.ietf.org/html/rfc12354">RFC 12354</a></div></div></div>
 3197+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="This is RFC 12354"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>This is <a href="http://tools.ietf.org/html/rfc12354" class="external" title="http://tools.ietf.org/html/rfc12354">RFC 12354</a></div></div></div>
31803198
31813199 !! end
31823200
@@ -3184,7 +3202,7 @@
31853203 !! input
31863204 [[Image:foobar.jpg|thumb|Please mailto:[email protected]]]
31873205 !! result
3188 -<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="Please mailto:[email protected]"><img alt="Please mailto:[email protected]" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>Please <a href="mailto:[email protected]" class="external free" title="mailto:[email protected]" rel="nofollow">mailto:[email protected]</a></div></div></div>
 3206+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="Please mailto:[email protected]"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>Please <a href="mailto:[email protected]" class="external free" title="mailto:[email protected]" rel="nofollow">mailto:[email protected]</a></div></div></div>
31893207
31903208 !! end
31913209
@@ -3194,7 +3212,7 @@
31953213 !! input
31963214 [[Image:foobar.jpg|thumb|<math>2+2</math>]]
31973215 !! result
3198 -<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="&lt;math&gt;2+2&lt;/math&gt;"><img alt="&lt;math&gt;2+2&lt;/math&gt;" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>&lt;math&gt;2+2&lt;/math&gt;</div></div></div>
 3216+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="&lt;math&gt;2+2&lt;/math&gt;"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>&lt;math&gt;2+2&lt;/math&gt;</div></div></div>
31993217
32003218 !! end
32013219
@@ -3205,7 +3223,7 @@
32063224 !! input
32073225 [[Image:foobar.jpg|thumb|<math>2+2</math>]]
32083226 !! result
3209 -<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="2 + 2"><img alt="2 + 2" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div><span class="texhtml">2 + 2</span></div></div></div>
 3227+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="2 + 2"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div><span class="texhtml">2 + 2</span></div></div></div>
32103228
32113229 !! end
32123230
@@ -3278,7 +3296,7 @@
32793297 !! input
32803298 [[Image:Foobar.jpg|thumb|This is a caption with another [[Image:icon.png|image]] inside it!]]
32813299 !! result
3282 -<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="This is a caption with another Image:Icon.png inside it!"><img alt="This is a caption with another Image:Icon.png inside it!" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>This is a caption with another <a href="https://www.mediawiki.org/index.php?title=Special:Upload&amp;wpDestFile=Icon.png" class="new" title="Image:Icon.png">Image:Icon.png</a> inside it!</div></div></div>
 3300+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="This is a caption with another Image:Icon.png inside it!"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>This is a caption with another <a href="https://www.mediawiki.org/index.php?title=Special:Upload&amp;wpDestFile=Icon.png" class="new" title="Image:Icon.png">Image:Icon.png</a> inside it!</div></div></div>
32833301
32843302 !! end
32853303
@@ -3298,7 +3316,7 @@
32993317 !! input
33003318 [[Image:Foobar.jpg|thumb|200px|This caption has [irc://example.net irc] and [https://example.com Secure] ext links in it.]]
33013319 !! result
3302 -<div class="thumb tright"><div class="thumbinner" style="width:202px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="This caption has irc and Secure ext links in it."><img alt="This caption has irc and Secure ext links in it." src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>This caption has <a href="irc://example.net" class="external text" title="irc://example.net" rel="nofollow">irc</a> and <a href="https://example.com" class="external text" title="https://example.com" rel="nofollow">Secure</a> ext links in it.</div></div></div>
 3320+<div class="thumb tright"><div class="thumbinner" style="width:202px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="This caption has irc and Secure ext links in it."><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>This caption has <a href="irc://example.net" class="external text" title="irc://example.net" rel="nofollow">irc</a> and <a href="https://example.com" class="external text" title="https://example.com" rel="nofollow">Secure</a> ext links in it.</div></div></div>
33033321
33043322 !! end
33053323
@@ -7115,7 +7133,7 @@
71167134 !! input
71177135 [[Image:Foobar.jpg|thumb|http://x|hello]]
71187136 !! result
7119 -<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="hello"><img alt="hello" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>hello</div></div></div>
 7137+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="image" title="hello"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" border="0" class="thumbimage" /></a> <div class="thumbcaption"><div class="magnify"><a href="https://www.mediawiki.org/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/https/static-codereview.wikimedia.org/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>hello</div></div></div>
71207138
71217139 !! end
71227140
Index: trunk/phase3/includes/parser/Parser.php
@@ -4224,7 +4224,7 @@
42254225 'vertAlign' => array( 'baseline', 'sub', 'super', 'top', 'text-top', 'middle',
42264226 'bottom', 'text-bottom' ),
42274227 'frame' => array( 'thumbnail', 'manualthumb', 'framed', 'frameless',
4228 - 'upright', 'border', 'link' ),
 4228+ 'upright', 'border', 'link', 'alt' ),
42294229 );
42304230 static $internalParamMap;
42314231 if ( !$internalParamMap ) {
@@ -4260,16 +4260,17 @@
42614261 function makeImage( $title, $options, $holders = false ) {
42624262 # Check if the options text is of the form "options|alt text"
42634263 # Options are:
4264 - # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
4265 - # * left no resizing, just left align. label is used for alt= only
4266 - # * right same, but right aligned
4267 - # * none same, but not aligned
4268 - # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
4269 - # * center center the image
4270 - # * framed Keep original image size, no magnify-button.
4271 - # * frameless like 'thumb' but without a frame. Keeps user preferences for width
4272 - # * upright reduce width for upright images, rounded to full __0 px
4273 - # * border draw a 1px border around the image
 4264+ # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
 4265+ # * left no resizing, just left align. label is used for alt= only
 4266+ # * right same, but right aligned
 4267+ # * none same, but not aligned
 4268+ # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
 4269+ # * center center the image
 4270+ # * framed Keep original image size, no magnify-button.
 4271+ # * frameless like 'thumb' but without a frame. Keeps user preferences for width
 4272+ # * upright reduce width for upright images, rounded to full __0 px
 4273+ # * border draw a 1px border around the image
 4274+ # * alt Text for HTML alt attribute (defaults to empty)
42744275 # vertical-align values (no % or length right now):
42754276 # * baseline
42764277 # * sub
@@ -4338,9 +4339,11 @@
43394340 } else {
43404341 # Validate internal parameters
43414342 switch( $paramName ) {
4342 - case "manualthumb":
4343 - /// @fixme - possibly check validity here?
4344 - /// downstream behavior seems odd with missing manual thumbs.
 4343+ case 'manualthumb':
 4344+ case 'alt':
 4345+ // @fixme - possibly check validity here for
 4346+ // manualthumb? downstream behavior seems odd with
 4347+ // missing manual thumbs.
43454348 $validated = true;
43464349 break;
43474350 case 'link':
@@ -4390,24 +4393,48 @@
43914394 $params['frame']['valign'] = key( $params['vertAlign'] );
43924395 }
43934396
4394 - # Strip bad stuff out of the alt text
4395 - # We can't just use replaceLinkHoldersText() here, because if this function
4396 - # is called from replaceInternalLinks2(), mLinkHolders won't be up to date.
 4397+ $params['frame']['caption'] = $caption;
 4398+
 4399+ # Strip bad stuff out of the title (tooltip). We can't just use
 4400+ # replaceLinkHoldersText() here, because if this function is called
 4401+ # from replaceInternalLinks2(), mLinkHolders won't be up-to-date.
43974402 if ( $holders ) {
4398 - $alt = $holders->replaceText( $caption );
 4403+ $tooltip = $holders->replaceText( $caption );
43994404 } else {
4400 - $alt = $this->replaceLinkHoldersText( $caption );
 4405+ $tooltip = $this->replaceLinkHoldersText( $caption );
44014406 }
44024407
44034408 # make sure there are no placeholders in thumbnail attributes
44044409 # that are later expanded to html- so expand them now and
44054410 # remove the tags
4406 - $alt = $this->mStripState->unstripBoth( $alt );
4407 - $alt = Sanitizer::stripAllTags( $alt );
 4411+ $tooltip = $this->mStripState->unstripBoth( $tooltip );
 4412+ $tooltip = Sanitizer::stripAllTags( $tooltip );
44084413
4409 - $params['frame']['alt'] = $alt;
4410 - $params['frame']['caption'] = $caption;
 4414+ $params['frame']['title'] = $tooltip;
44114415
 4416+ # In the old days, [[Image:Foo|text...]] would set alt text. Later it
 4417+ # came to also set the caption, ordinary text after the image -- which
 4418+ # makes no sense, because that just repeats the text multiple times in
 4419+ # screen readers. It *also* came to set the title attribute.
 4420+ #
 4421+ # Now that we have an alt attribute, we should not set the alt text to
 4422+ # equal the caption: that's worse than useless, it just repeats the
 4423+ # text. This is the framed/thumbnail case. If there's no caption, we
 4424+ # use the unnamed parameter for alt text as well, just for the time be-
 4425+ # ing, if the unnamed param is set and the alt param is not.
 4426+ #
 4427+ # For the future, we need to figure out if we want to tweak this more,
 4428+ # e.g., introducing a title= parameter for the title; ignoring the un-
 4429+ # named parameter entirely for images without a caption; adding an ex-
 4430+ # plicit caption= parameter and preserving the old magic unnamed para-
 4431+ # meter for BC; ...
 4432+ if( $caption !== '' && !isset( $params['frame']['alt'] )
 4433+ && !isset( $params['frame']['framed'] )
 4434+ && !isset( $params['frame']['thumbnail'] )
 4435+ && !isset( $params['frame']['manualthumb'] ) ) {
 4436+ $params['frame']['alt'] = $tooltip;
 4437+ }
 4438+
44124439 wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
44134440
44144441 # Linker does the rest
Index: trunk/phase3/includes/Linker.php
@@ -730,11 +730,12 @@
731731 $page = isset( $hp['page'] ) ? $hp['page'] : false;
732732 if ( !isset( $fp['align'] ) ) $fp['align'] = '';
733733 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
 734+ # Backward compatibility, title used to always be equal to alt text
 735+ if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt'];
734736
735737 $prefix = $postfix = '';
736738
737 - if ( 'center' == $fp['align'] )
738 - {
 739+ if ( 'center' == $fp['align'] ) {
739740 $prefix = '<div class="center">';
740741 $postfix = '</div>';
741742 $fp['align'] = 'none';
@@ -765,7 +766,6 @@
766767 }
767768
768769 if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
769 -
770770 # Create a thumbnail. Alignment depends on language
771771 # writing direction, # right aligned for left-to-right-
772772 # languages ("Western languages"), left-aligned
@@ -800,6 +800,7 @@
801801 } else {
802802 $params = array(
803803 'alt' => $fp['alt'],
 804+ 'title' => $fp['title'],
804805 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
805806 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
806807 if ( !empty( $fp['link-url'] ) ) {
@@ -848,6 +849,8 @@
849850 $page = isset( $hp['page'] ) ? $hp['page'] : false;
850851 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
851852 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
 853+ # Backward compatibility, title used to always be equal to alt text
 854+ if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt'];
852855 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
853856
854857 if ( empty( $hp['width'] ) ) {
@@ -907,6 +910,7 @@
908911 } else {
909912 $s .= $thumb->toHtml( array(
910913 'alt' => $fp['alt'],
 914+ 'title' => $fp['title'],
911915 'img-class' => 'thumbimage',
912916 'desc-link' => true,
913917 'desc-query' => $query ) );
Index: trunk/phase3/includes/MediaTransformOutput.php
@@ -129,7 +129,8 @@
130130 * should be indicated with a value of true for true, and false or
131131 * absent for false.
132132 *
133 - * alt Alternate text or caption
 133+ * alt HTML alt attribute
 134+ * title HTML title attribute
134135 * desc-link Boolean, show a description link
135136 * file-link Boolean, show a file download link
136137 * valign vertical-align property, if the output is an inline element
@@ -150,14 +151,18 @@
151152 }
152153
153154 $alt = empty( $options['alt'] ) ? '' : $options['alt'];
 155+ # Note: if title is empty and alt is not, make the title empty, don't
 156+ # use alt; only use alt if title is not set
 157+ $title = !isset( $options['title'] ) ? $alt : $options['title'];
154158 $query = empty($options['desc-query']) ? '' : $options['desc-query'];
 159+
155160 if ( !empty( $options['custom-url-link'] ) ) {
156161 $linkAttribs = array( 'href' => $options['custom-url-link'] );
157162 } elseif ( !empty( $options['custom-title-link'] ) ) {
158163 $title = $options['custom-title-link'];
159164 $linkAttribs = array( 'href' => $title->getLinkUrl(), 'title' => $title->getFullText() );
160165 } elseif ( !empty( $options['desc-link'] ) ) {
161 - $linkAttribs = $this->getDescLinkAttribs( $alt, $query );
 166+ $linkAttribs = $this->getDescLinkAttribs( $title, $query );
162167 } elseif ( !empty( $options['file-link'] ) ) {
163168 $linkAttribs = array( 'href' => $this->file->getURL() );
164169 } else {
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -289,6 +289,7 @@
290290 'img_bottom' => array( 1, 'bottom' ),
291291 'img_text_bottom' => array( 1, 'text-bottom' ),
292292 'img_link' => array( 1, 'link=$1' ),
 293+ 'img_alt' => array( 1, 'alt=$1', 'alt $1' ),
293294 'int' => array( 0, 'INT:' ),
294295 'sitename' => array( 1, 'SITENAME' ),
295296 'ns' => array( 0, 'NS:' ),
Index: trunk/phase3/RELEASE-NOTES
@@ -156,6 +156,8 @@
157157 * Added "link" parameter to image links, to allow images to link to an
158158 arbitrary title or URL. This should replace inaccessible and incomplete
159159 solutions such as CSS-based overlays and ImageMap.
 160+* (bug 368) Don't use caption for alt attribute; allow manual specification
 161+ using new "alt=" parameter for images
160162
161163 === Bug fixes in 1.14 ===
162164

Follow-up revisions

RevisionCommit summaryAuthorDate
r41840Tweak to r41837 -- remove 'alt $1' alias for 'alt=$1', we're not sure we need...brion17:29, 8 October 2008
r42116Fix for r41837 -- apply HTML stripping to explicit alt text as well as implicit....brion21:20, 15 October 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r41364(bug 368) Allow alt= attribute for images...simetrical21:07, 28 September 2008

Comments

#Comment by Brion VIBBER (talk | contribs)   17:35, 8 October 2008

w00t!

One tiny tweak: removing the 'alt $1' alias for the keyword per IRC discussion (page and upright have such, but link and thumbnail don't). DOne in r41840.

Noticed another issue:

[[Image:Wiki.png|testing '''bold''' in alt]]

[[Image:Wiki.png|alt=testing '''bold''' in alt]]

render the alt text differently; the latter isn't stripping tags.

#Comment by Brion VIBBER (talk | contribs)   21:20, 15 October 2008

Fixed to my satisfcation in r42116

Status & tagging log