Title attributes are now always blank on framed and thumbnailed images, and default...
authorRemember the dot <rememberthedot@users.mediawiki.org>
Fri, 3 Jul 2009 05:13:58 +0000 (05:13 +0000)
committerRemember the dot <rememberthedot@users.mediawiki.org>
Fri, 3 Jul 2009 05:13:58 +0000 (05:13 +0000)
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.

HISTORY
includes/Linker.php
includes/MediaTransformOutput.php
includes/parser/Parser.php

diff --git a/HISTORY b/HISTORY
index 234216b..6d6f35d 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -134,6 +134,10 @@ Change notes from older releases. For current info see RELEASE-NOTES.
   on a different database
 * Add a class if 'missingsummary' is triggered to allow styling of the summary
   line
+* 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.
 
 === Bug fixes in 1.15 ===
 * (bug 16968) Special:Upload no longer throws useless warnings.
index 48339e1..2a77edb 100644 (file)
@@ -447,8 +447,7 @@ class Linker {
                $page = isset( $hp['page'] ) ? $hp['page'] : false;
                if ( !isset( $fp['align'] ) ) $fp['align'] = '';
                if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
-               # Backward compatibility, title used to always be equal to alt text
-               if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt'];
+               if ( !isset( $fp['title'] ) ) $fp['title'] = '';
 
                $prefix = $postfix = '';
 
@@ -566,8 +565,7 @@ class Linker {
                $page = isset( $hp['page'] ) ? $hp['page'] : false;
                if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
                if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
-               # Backward compatibility, title used to always be equal to alt text
-               if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt'];
+               if ( !isset( $fp['title'] ) ) $fp['title'] = '';
                if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
 
                if ( empty( $hp['width'] ) ) {
index 9c0d121..e19a0c6 100644 (file)
@@ -86,9 +86,6 @@ abstract class MediaTransformOutput {
                        $query .= $query ? '&'.$params : $params;
                }
                $title = $this->file->getTitle();
-               if ( strval( $alt ) === '' ) {
-                       $alt = $title->getText();
-               }
                return array(
                        'href' => $this->file->getTitle()->getLocalURL( $query ),
                        'class' => 'image',
@@ -164,7 +161,7 @@ class ThumbnailImage extends MediaTransformOutput {
                } elseif ( !empty( $options['custom-title-link'] ) ) {
                        $title = $options['custom-title-link'];
                        $linkAttribs = array( 'href' => $title->getLinkUrl(),
-                                       'title' => empty( $options['alt'] ) ? $title->getFullText() : $alt );
+                                       'title' => $alt );
                } elseif ( !empty( $options['desc-link'] ) ) {
                        $linkAttribs = $this->getDescLinkAttribs( $title, $query );
                } elseif ( !empty( $options['file-link'] ) ) {
index 68ca150..f4fc484 100644 (file)
@@ -1582,29 +1582,29 @@ class Parser
                        # Don't allow internal links to pages containing
                        # PROTO: where PROTO is a valid URL protocol; these
                        # should be external links.
-                       if (preg_match('/^\b(?:' . wfUrlProtocols() . ')/', $m[1])) {
+                       if ( preg_match( '/^\b(?:' . wfUrlProtocols() . ')/', $m[1] ) ) {
                                $s .= $prefix . '[[' . $line ;
                                wfProfileOut( __METHOD__."-misc" );
                                continue;
                        }
 
                        # Make subpage if necessary
-                       if( $useSubpages ) {
+                       if ( $useSubpages ) {
                                $link = $this->maybeDoSubpageLink( $m[1], $text );
                        } else {
                                $link = $m[1];
                        }
 
-                       $noforce = (substr($m[1], 0, 1) !== ':');
+                       $noforce = (substr( $m[1], 0, 1 ) !== ':');
                        if (!$noforce) {
                                # Strip off leading ':'
-                               $link = substr($link, 1);
+                               $link = substr( $link, 1 );
                        }
 
                        wfProfileOut( __METHOD__."-misc" );
                        wfProfileIn( __METHOD__."-title" );
-                       $nt = Title::newFromText( $this->mStripState->unstripNoWiki($link) );
-                       if( $nt === NULL ) {
+                       $nt = Title::newFromText( $this->mStripState->unstripNoWiki( $link ) );
+                       if ( $nt === NULL ) {
                                $s .= $prefix . '[[' . $line;
                                wfProfileOut( __METHOD__."-title" );
                                continue;
@@ -1614,9 +1614,9 @@ class Parser
                        $iw = $nt->getInterWiki();
                        wfProfileOut( __METHOD__."-title" );
 
-                       if ($might_be_img) { # if this is actually an invalid link
+                       if ( $might_be_img ) { # if this is actually an invalid link
                                wfProfileIn( __METHOD__."-might_be_img" );
-                               if ($ns == NS_FILE && $noforce) { #but might be an image
+                               if ( $ns == NS_FILE && $noforce ) { #but might be an image
                                        $found = false;
                                        while ( true ) {
                                                #look at the next 'line' to see if we can close it there
@@ -1660,14 +1660,14 @@ class Parser
                        }
 
                        $wasblank = ( '' == $text );
-                       if( $wasblank ) $text = $link;
+                       if ( $wasblank ) $text = $link;
 
                        # Link not escaped by : , create the various objects
-                       if( $noforce ) {
+                       if ( $noforce ) {
 
                                # Interwikis
                                wfProfileIn( __METHOD__."-interwiki" );
-                               if( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
+                               if ( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName( $iw ) ) {
                                        $this->mOutput->addLanguageLink( $nt->getFullText() );
                                        $s = rtrim($s . $prefix);
                                        $s .= trim($trail, "\n") == '' ? '': $prefix . $trail;
@@ -1679,12 +1679,19 @@ class Parser
                                if ( $ns == NS_FILE ) {
                                        wfProfileIn( __METHOD__."-image" );
                                        if ( !wfIsBadImage( $nt->getDBkey(), $this->mTitle ) ) {
-                                               # recursively parse links inside the image caption
-                                               # actually, this will parse them in any other parameters, too,
-                                               # but it might be hard to fix that, and it doesn't matter ATM
-                                               $text = $this->replaceExternalLinks($text);
-                                               $holders->merge( $this->replaceInternalLinks2( $text ) );
-
+                                               if ( $wasblank ) {
+                                                       # if no parameters were passed, $text
+                                                       # becomes something like "File:Foo.png",
+                                                       # which we don't want to pass on to the
+                                                       # image generator
+                                                       $text = '';
+                                               } else {
+                                                       # recursively parse links inside the image caption
+                                                       # actually, this will parse them in any other parameters, too,
+                                                       # but it might be hard to fix that, and it doesn't matter ATM
+                                                       $text = $this->replaceExternalLinks($text);
+                                                       $holders->merge( $this->replaceInternalLinks2( $text ) );
+                                               }
                                                # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
                                                $s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text, $holders ) ) . $trail;
                                        }
@@ -4375,7 +4382,8 @@ class Parser
                #  * none       same, but not aligned
                #  * ___px      scale to ___ pixels width, no aligning. e.g. use in taxobox
                #  * center     center the image
-               #  * framed     Keep original image size, no magnify-button.
+               #  * frame      Keep original image size, no magnify-button.
+               #  * framed     Same as "frame"
                #  * frameless  like 'thumb' but without a frame. Keeps user preferences for width
                #  * upright    reduce width for upright images, rounded to full __0 px
                #  * border     draw a 1px border around the image
@@ -4515,7 +4523,11 @@ class Parser
 
                $params['frame']['caption'] = $caption;
 
-               $params['frame']['title'] = $this->stripAltText( $caption, $holders );
+               # Will the image be presented in a frame, with the caption below?
+               $imageIsFramed = isset( $params['frame']['frame'] ) ||
+                                isset( $params['frame']['framed'] ) ||
+                                isset( $params['frame']['thumbnail'] ) ||
+                                isset( $params['frame']['manualthumb'] );
 
                # In the old days, [[Image:Foo|text...]] would set alt text.  Later it
                # came to also set the caption, ordinary text after the image -- which
@@ -4533,11 +4545,27 @@ class Parser
                # named parameter entirely for images without a caption; adding an ex-
                # plicit caption= parameter and preserving the old magic unnamed para-
                # meter for BC; ...
-               if( $caption !== '' && !isset( $params['frame']['alt'] )
-               && !isset( $params['frame']['framed'] )
-               && !isset( $params['frame']['thumbnail'] )
-               && !isset( $params['frame']['manualthumb'] ) ) {
-                       $params['frame']['alt'] = $params['frame']['title'];
+               if ( $imageIsFramed ) { # Framed image
+                       if ( $caption === '' && !isset( $params['frame']['alt'] ) ) {
+                               # No caption or alt text, add the filename as the alt text so
+                               # that screen readers at least get some description of the image
+                               $params['frame']['alt'] = $title->getText();
+                       }
+                       # Do not set $params['frame']['title'] because tooltips don't make sense
+                       # for framed images
+               } else { # Inline image
+                       if ( !isset( $params['frame']['alt'] ) ) {
+                               # No alt text, use the "caption" for the alt text
+                               if ( $caption !== '') {
+                                       $params['frame']['alt'] = $this->stripAltText( $caption, $holders );
+                               } else {
+                                       # No caption, fall back to using the filename for the
+                                       # alt text
+                                       $params['frame']['alt'] = $title->getText();
+                               }
+                       }
+                       # Use the "caption" for the tooltip text
+                       $params['frame']['title'] = $this->stripAltText( $caption, $holders );
                }
 
                wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );