r52726 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52725‎ | r52726 | r52727 >
Date:05:13, 3 July 2009
Author:rememberthedot
Status:resolved (Comments)
Tags:
Comment:
Title attributes are now always blank on framed and thumbnailed images, and default to blank on inline images instead of defaulting to the image's filename. Additionally, the alt attribute now defaults to the filename on framed and thumbnailed images if no caption or alt attribute is specified.

I was unable to run the parser test suite ("MediaWiki internal error"), so the test suite may need to be updated to reflect these changes.
Modified paths:
  • /trunk/phase3/HISTORY (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/MediaTransformOutput.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/HISTORY
@@ -134,6 +134,10 @@
135135 on a different database
136136 * Add a class if 'missingsummary' is triggered to allow styling of the summary
137137 line
 138+* Title attributes are now always blank on framed and thumbnailed images, and default to blank
 139+ on inline images instead of defaulting to the image's filename. Additionally, the alt
 140+ attribute now defaults to the filename on framed and thumbnailed images if no caption or alt
 141+ attribute is specified.
138142
139143 === Bug fixes in 1.15 ===
140144 * (bug 16968) Special:Upload no longer throws useless warnings.
Index: trunk/phase3/includes/parser/Parser.php
@@ -1582,29 +1582,29 @@
15831583 # Don't allow internal links to pages containing
15841584 # PROTO: where PROTO is a valid URL protocol; these
15851585 # should be external links.
1586 - if (preg_match('/^\b(?:' . wfUrlProtocols() . ')/', $m[1])) {
 1586+ if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
15871587 $s .= $prefix . '[[' . $line ;
15881588 wfProfileOut( __METHOD__."-misc" );
15891589 continue;
15901590 }
15911591
15921592 # Make subpage if necessary
1593 - if( $useSubpages ) {
 1593+ if ( $useSubpages ) {
15941594 $link = $this->maybeDoSubpageLink( $m[1], $text );
15951595 } else {
15961596 $link = $m[1];
15971597 }
15981598
1599 - $noforce = (substr($m[1], 0, 1) !== ':');
 1599+ $noforce = (substr( $m[1], 0, 1 ) !== ':');
16001600 if (!$noforce) {
16011601 # Strip off leading ':'
1602 - $link = substr($link, 1);
 1602+ $link = substr( $link, 1 );
16031603 }
16041604
16051605 wfProfileOut( __METHOD__."-misc" );
16061606 wfProfileIn( __METHOD__."-title" );
1607 - $nt = Title::newFromText( $this->mStripState->unstripNoWiki($link) );
1608 - if( $nt === NULL ) {
 1607+ $nt = Title::newFromText( $this->mStripState->unstripNoWiki( $link ) );
 1608+ if ( $nt === NULL ) {
16091609 $s .= $prefix . '[[' . $line;
16101610 wfProfileOut( __METHOD__."-title" );
16111611 continue;
@@ -1614,9 +1614,9 @@
16151615 $iw = $nt->getInterWiki();
16161616 wfProfileOut( __METHOD__."-title" );
16171617
1618 - if ($might_be_img) { # if this is actually an invalid link
 1618+ if ( $might_be_img ) { # if this is actually an invalid link
16191619 wfProfileIn( __METHOD__."-might_be_img" );
1620 - if ($ns == NS_FILE && $noforce) { #but might be an image
 1620+ if ( $ns == NS_FILE && $noforce ) { #but might be an image
16211621 $found = false;
16221622 while ( true ) {
16231623 #look at the next 'line' to see if we can close it there
@@ -1660,14 +1660,14 @@
16611661 }
16621662
16631663 $wasblank = ( '' == $text );
1664 - if( $wasblank ) $text = $link;
 1664+ if ( $wasblank ) $text = $link;
16651665
16661666 # Link not escaped by : , create the various objects
1667 - if( $noforce ) {
 1667+ if ( $noforce ) {
16681668
16691669 # Interwikis
16701670 wfProfileIn( __METHOD__."-interwiki" );
1671 - if( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
 1671+ if ( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
16721672 $this->mOutput->addLanguageLink( $nt->getFullText() );
16731673 $s = rtrim($s . $prefix);
16741674 $s .= trim($trail, "\n") == '' ? '': $prefix . $trail;
@@ -1679,12 +1679,19 @@
16801680 if ( $ns == NS_FILE ) {
16811681 wfProfileIn( __METHOD__."-image" );
16821682 if ( !wfIsBadImage( $nt->getDBkey(), $this->mTitle ) ) {
1683 - # recursively parse links inside the image caption
1684 - # actually, this will parse them in any other parameters, too,
1685 - # but it might be hard to fix that, and it doesn't matter ATM
1686 - $text = $this->replaceExternalLinks($text);
1687 - $holders->merge( $this->replaceInternalLinks2( $text ) );
1688 -
 1683+ if ( $wasblank ) {
 1684+ # if no parameters were passed, $text
 1685+ # becomes something like "File:Foo.png",
 1686+ # which we don't want to pass on to the
 1687+ # image generator
 1688+ $text = '';
 1689+ } else {
 1690+ # recursively parse links inside the image caption
 1691+ # actually, this will parse them in any other parameters, too,
 1692+ # but it might be hard to fix that, and it doesn't matter ATM
 1693+ $text = $this->replaceExternalLinks($text);
 1694+ $holders->merge( $this->replaceInternalLinks2( $text ) );
 1695+ }
16891696 # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
16901697 $s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text, $holders ) ) . $trail;
16911698 }
@@ -4375,7 +4382,8 @@
43764383 # * none same, but not aligned
43774384 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
43784385 # * center center the image
4379 - # * framed Keep original image size, no magnify-button.
 4386+ # * frame Keep original image size, no magnify-button.
 4387+ # * framed Same as "frame"
43804388 # * frameless like 'thumb' but without a frame. Keeps user preferences for width
43814389 # * upright reduce width for upright images, rounded to full __0 px
43824390 # * border draw a 1px border around the image
@@ -4515,7 +4523,11 @@
45164524
45174525 $params['frame']['caption'] = $caption;
45184526
4519 - $params['frame']['title'] = $this->stripAltText( $caption, $holders );
 4527+ # Will the image be presented in a frame, with the caption below?
 4528+ $imageIsFramed = isset( $params['frame']['frame'] ) ||
 4529+ isset( $params['frame']['framed'] ) ||
 4530+ isset( $params['frame']['thumbnail'] ) ||
 4531+ isset( $params['frame']['manualthumb'] );
45204532
45214533 # In the old days, [[Image:Foo|text...]] would set alt text. Later it
45224534 # came to also set the caption, ordinary text after the image -- which
@@ -4533,11 +4545,27 @@
45344546 # named parameter entirely for images without a caption; adding an ex-
45354547 # plicit caption= parameter and preserving the old magic unnamed para-
45364548 # meter for BC; ...
4537 - if( $caption !== '' && !isset( $params['frame']['alt'] )
4538 - && !isset( $params['frame']['framed'] )
4539 - && !isset( $params['frame']['thumbnail'] )
4540 - && !isset( $params['frame']['manualthumb'] ) ) {
4541 - $params['frame']['alt'] = $params['frame']['title'];
 4549+ if ( $imageIsFramed ) { # Framed image
 4550+ if ( $caption === '' && !isset( $params['frame']['alt'] ) ) {
 4551+ # No caption or alt text, add the filename as the alt text so
 4552+ # that screen readers at least get some description of the image
 4553+ $params['frame']['alt'] = $title->getText();
 4554+ }
 4555+ # Do not set $params['frame']['title'] because tooltips don't make sense
 4556+ # for framed images
 4557+ } else { # Inline image
 4558+ if ( !isset( $params['frame']['alt'] ) ) {
 4559+ # No alt text, use the "caption" for the alt text
 4560+ if ( $caption !== '') {
 4561+ $params['frame']['alt'] = $this->stripAltText( $caption, $holders );
 4562+ } else {
 4563+ # No caption, fall back to using the filename for the
 4564+ # alt text
 4565+ $params['frame']['alt'] = $title->getText();
 4566+ }
 4567+ }
 4568+ # Use the "caption" for the tooltip text
 4569+ $params['frame']['title'] = $this->stripAltText( $caption, $holders );
45424570 }
45434571
45444572 wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
Index: trunk/phase3/includes/Linker.php
@@ -447,8 +447,7 @@
448448 $page = isset( $hp['page'] ) ? $hp['page'] : false;
449449 if ( !isset( $fp['align'] ) ) $fp['align'] = '';
450450 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
451 - # Backward compatibility, title used to always be equal to alt text
452 - if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt'];
 451+ if ( !isset( $fp['title'] ) ) $fp['title'] = '';
453452
454453 $prefix = $postfix = '';
455454
@@ -566,8 +565,7 @@
567566 $page = isset( $hp['page'] ) ? $hp['page'] : false;
568567 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
569568 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
570 - # Backward compatibility, title used to always be equal to alt text
571 - if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt'];
 569+ if ( !isset( $fp['title'] ) ) $fp['title'] = '';
572570 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
573571
574572 if ( empty( $hp['width'] ) ) {
Index: trunk/phase3/includes/MediaTransformOutput.php
@@ -86,9 +86,6 @@
8787 $query .= $query ? '&'.$params : $params;
8888 }
8989 $title = $this->file->getTitle();
90 - if ( strval( $alt ) === '' ) {
91 - $alt = $title->getText();
92 - }
9390 return array(
9491 'href' => $this->file->getTitle()->getLocalURL( $query ),
9592 'class' => 'image',
@@ -164,7 +161,7 @@
165162 } elseif ( !empty( $options['custom-title-link'] ) ) {
166163 $title = $options['custom-title-link'];
167164 $linkAttribs = array( 'href' => $title->getLinkUrl(),
168 - 'title' => empty( $options['alt'] ) ? $title->getFullText() : $alt );
 165+ 'title' => $alt );
169166 } elseif ( !empty( $options['desc-link'] ) ) {
170167 $linkAttribs = $this->getDescLinkAttribs( $title, $query );
171168 } elseif ( !empty( $options['file-link'] ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r53098Updated parser tests for r52726. Also fixed some corner cases and updated the...rememberthedot04:47, 11 July 2009
r53287Applied image attribute improvements from r52726 to galleries as wellrememberthedot04:18, 15 July 2009
r53288Updated parser test for r52726 and r53287rememberthedot04:19, 15 July 2009

Comments

#Comment by Simetrical (talk | contribs)   19:42, 5 July 2009

"Additionally, the alt attribute now defaults to the filename on framed and thumbnailed images if no caption or alt attribute is specified."

This is instead of what? A blank alt text might be more useful than this.

#Comment by Remember the dot (talk | contribs)   01:43, 7 July 2009

Previously, screen readers got nothing if there was no caption on a framed or thumbnailed image. I figured it would be kinder to let them at least give them some description of the image, even if it's just what's in the file name. Of course, if there is a caption, the alt attribute defaults to blank rather than repeating it.

Alt attributes on inline images still default to the file name as they have done for as long as I know.

To be honest, I'm not sure what the best solution is here. What do you think? Do you know any screen reader users that might have a stronger opinion?

#Comment by Simetrical (talk | contribs)   01:54, 7 July 2009

I would definitely support asking someone who actually uses a screen reader! In practice, I'm not sure whether empty alt text, no alt text, or semi-useless but distinctive alt text is better, in the case where no good alt text is available. It would be really helpful to know this.

#Comment by Graham87 (talk | contribs)   05:03, 7 July 2009

I use a screen reader, [[W:JAWS (screen reader)|]]. I'd prefer to have at least *some* alt text rather than none at all. If no alt text is given, JAWS will read out the file name like this: "Long_cane_folded.jpg/300px-Long_cane_folded". In versions before the latest one, if JAWS encounters an image on Wikipedia with no alt text, it would read "link graphic <image filename>". In the latest version, as I've just discovered, it will just read "link <filename>", which is much more confusing. I can't think of an easy solution because MediaWiki can differentiate between image captions and alt text, and they are both important pieces of information.

I've made a quick sandbox at User:Graham87/sandbox12 for experiments with image captions and alt text. Feel free to add any test cases there.

#Comment by Simetrical (talk | contribs)   05:57, 7 July 2009

Okay, so let's stick with the filename as alt text, then, if none is provided.

#Comment by Graham87 (talk | contribs)   05:06, 7 July 2009

Gah, why doesn't the pipe trick work on this page? I meant JAWS, of course. :-)

#Comment by Xeno (talk | contribs)   19:38, 10 July 2009

Not sure if this is appropriate to comment on here, so apologies if not, but would it be possible to provide the alternate text at the File: page, and have it be used as the default when the image is used, if it isn't provided explicitly? See w:WP:VPT#Would it be possible to hard-code alternate text for images, i.e. at the File: description page?.

#Comment by Simetrical (talk | contribs)   19:42, 10 July 2009

You probably can't provide good general-purpose alt text. Alt text doesn't describe the image visually, it provides an appropriate replacement for the image, and what replacement is appropriate depends on how it's used. The alt text needs to correspond to the specific reason the image is used in the article, which will vary between articles.

But yes, this is the wrong place to comment. Try Bugzilla.

#Comment by Simetrical (talk | contribs)   22:56, 10 July 2009

This needs to update parser tests.

#Comment by Remember the dot (talk | contribs)   02:29, 11 July 2009

I noticed--I'm working on it now. I had a terrible time getting my MediaWiki installation working--first I had to add log_user_text to the logging table to get uploads to work, then I finally figured out that I had to truncate the l10n_cache table every time I wanted to run parserTests.php.

So, long story short, I'm working on it.

#Comment by Remember the dot (talk | contribs)   04:51, 11 July 2009

Parser tests updated in r53098. 21 tests failing before this revision, 21 tests failing after the parser test update (and they're the same tests! ;-).

#Comment by Simetrical (talk | contribs)   22:32, 14 July 2009

git bisect says that this commit is still the cause of "<references> after <gallery>" being broken.

#Comment by Simetrical (talk | contribs)   22:36, 14 July 2009

I meant, of course, "<references> after <gallery>". I always forget that wikitext works here.

#Comment by Remember the dot (talk | contribs)   04:21, 15 July 2009

Try it again; r53287 and r53288 should have fixed it.

#Comment by Duesentrieb (talk | contribs)   12:35, 18 September 2009

title attribute went missing (at least on the live site), see bugzilla:20712

#Comment by Graham87 (talk | contribs)   10:47, 19 September 2009

Status & tagging log