r41364 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41363‎ | r41364 | r41365 >
Date:21:07, 28 September 2008
Author:simetrical
Status:old (Comments)
Tags:
Comment:
(bug 368) Allow alt= attribute for images

If the attribute is not specified, default to empty string, not repeating the caption.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES
@@ -146,6 +146,8 @@
147147 $wgExternalLinkTarget
148148 * (bug 674) Allow admins to block users from editing specific articles and
149149 namespaces
 150+* (bug 368) Don't use caption for alt attribute; allow manual specification
 151+ using new "alt=" parameter for images
150152
151153 === Bug fixes in 1.14 ===
152154
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -287,6 +287,7 @@
288288 'img_middle' => array( 1, 'middle' ),
289289 'img_bottom' => array( 1, 'bottom' ),
290290 'img_text_bottom' => array( 1, 'text-bottom' ),
 291+ 'img_alt' => array( 1, 'alt=$1', 'alt $1' ),
291292 'int' => array( 0, 'INT:' ),
292293 'sitename' => array( 1, 'SITENAME' ),
293294 'ns' => array( 0, 'NS:' ),
Index: trunk/phase3/includes/parser/Parser.php
@@ -4186,7 +4186,7 @@
41874187 'vertAlign' => array( 'baseline', 'sub', 'super', 'top', 'text-top', 'middle',
41884188 'bottom', 'text-bottom' ),
41894189 'frame' => array( 'thumbnail', 'manualthumb', 'framed', 'frameless',
4190 - 'upright', 'border' ),
 4190+ 'upright', 'border', 'alt' ),
41914191 );
41924192 static $internalParamMap;
41934193 if ( !$internalParamMap ) {
@@ -4222,16 +4222,17 @@
42234223 function makeImage( $title, $options, $holders = false ) {
42244224 # Check if the options text is of the form "options|alt text"
42254225 # Options are:
4226 - # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
4227 - # * left no resizing, just left align. label is used for alt= only
4228 - # * right same, but right aligned
4229 - # * none same, but not aligned
4230 - # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
4231 - # * center center the image
4232 - # * framed Keep original image size, no magnify-button.
4233 - # * frameless like 'thumb' but without a frame. Keeps user preferences for width
4234 - # * upright reduce width for upright images, rounded to full __0 px
4235 - # * border draw a 1px border around the image
 4226+ # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
 4227+ # * left no resizing, just left align. label is used for alt= only
 4228+ # * right same, but right aligned
 4229+ # * none same, but not aligned
 4230+ # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
 4231+ # * center center the image
 4232+ # * framed Keep original image size, no magnify-button.
 4233+ # * frameless like 'thumb' but without a frame. Keeps user preferences for width
 4234+ # * upright reduce width for upright images, rounded to full __0 px
 4235+ # * border draw a 1px border around the image
 4236+ # * alt Text for HTML alt attribute (defaults to empty)
42364237 # vertical-align values (no % or length right now):
42374238 # * baseline
42384239 # * sub
@@ -4300,7 +4301,8 @@
43014302 } else {
43024303 # Validate internal parameters
43034304 switch( $paramName ) {
4304 - case "manualthumb":
 4305+ case 'manualthumb':
 4306+ case 'alt':
43054307 /// @fixme - possibly check validity here?
43064308 /// downstream behavior seems odd with missing manual thumbs.
43074309 $validated = true;
@@ -4329,22 +4331,6 @@
43304332 $params['frame']['valign'] = key( $params['vertAlign'] );
43314333 }
43324334
4333 - # Strip bad stuff out of the alt text
4334 - # We can't just use replaceLinkHoldersText() here, because if this function
4335 - # is called from replaceInternalLinks2(), mLinkHolders won't be up to date.
4336 - if ( $holders ) {
4337 - $alt = $holders->replaceText( $caption );
4338 - } else {
4339 - $alt = $this->replaceLinkHoldersText( $caption );
4340 - }
4341 -
4342 - # make sure there are no placeholders in thumbnail attributes
4343 - # that are later expanded to html- so expand them now and
4344 - # remove the tags
4345 - $alt = $this->mStripState->unstripBoth( $alt );
4346 - $alt = Sanitizer::stripAllTags( $alt );
4347 -
4348 - $params['frame']['alt'] = $alt;
43494335 $params['frame']['caption'] = $caption;
43504336
43514337 wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r41407Revert r41364 -- broke 22 parser test cases with change of alt behavior....brion00:21, 30 September 2008
r41837(bug 368) Allow alt= attribute for images...simetrical16:33, 8 October 2008

Comments

#Comment by Brion VIBBER (talk | contribs)   20:36, 30 September 2008

This caused parser test regressions; reverted in r41407:

Revert r41364 -- broke 22 parser test cases with change of alt behavior.

The caption was originally defined *as* the alt text (defaulting to the image file name if there is no alt text). Note that a separate caption text is only displayed in some display modes ('frame' and 'thumb', iirc), and not by default.

Please run the parser tests and check the effect you have on them. If it's really an appropriate change, then update the test cases. If you're not sure, consider backing out pending further discussion.  :)

It might be appropriate to not set the 'alt' attribute for frame/thumb cases, but definitely not for inline images where we already have a way of setting the alt text which you're removing!

#Comment by Brion VIBBER (talk | contribs)   20:37, 30 September 2008

Reopened bug 368.

Status & tagging log