(bug 368) Allow alt= attribute for images
authorAryeh Gregor <simetrical@users.mediawiki.org>
Sun, 28 Sep 2008 21:07:34 +0000 (21:07 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Sun, 28 Sep 2008 21:07:34 +0000 (21:07 +0000)
If the attribute is not specified, default to empty string, not repeating the caption.

RELEASE-NOTES
includes/parser/Parser.php
languages/messages/MessagesEn.php

index ace79ce..483b61b 100644 (file)
@@ -146,6 +146,8 @@ The following extensions are migrated into MediaWiki 1.14:
   $wgExternalLinkTarget
 * (bug 674) Allow admins to block users from editing specific articles and
   namespaces
+* (bug 368) Don't use caption for alt attribute; allow manual specification
+  using new "alt=" parameter for images
 
 === Bug fixes in 1.14 ===
 
index 9e8ed0c..8687091 100644 (file)
@@ -4186,7 +4186,7 @@ class Parser
                                'vertAlign' => array( 'baseline', 'sub', 'super', 'top', 'text-top', 'middle',
                                        'bottom', 'text-bottom' ),
                                'frame' => array( 'thumbnail', 'manualthumb', 'framed', 'frameless',
-                                       'upright', 'border' ),
+                                       'upright', 'border', 'alt' ),
                        );
                        static $internalParamMap;
                        if ( !$internalParamMap ) {
@@ -4222,16 +4222,17 @@ class Parser
        function makeImage( $title, $options, $holders = false ) {
                # Check if the options text is of the form "options|alt text"
                # Options are:
-               #  * thumbnail          make a thumbnail with enlarge-icon and caption, alignment depends on lang
-               #  * left               no resizing, just left align. label is used for alt= only
-               #  * right              same, but right aligned
-               #  * 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.
-               #  * 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
+               #  * thumbnail  make a thumbnail with enlarge-icon and caption, alignment depends on lang
+               #  * left       no resizing, just left align. label is used for alt= only
+               #  * right      same, but right aligned
+               #  * 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.
+               #  * 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
+               #  * alt        Text for HTML alt attribute (defaults to empty)
                # vertical-align values (no % or length right now):
                #  * baseline
                #  * sub
@@ -4300,7 +4301,8 @@ class Parser
                                        } else {
                                                # Validate internal parameters
                                                switch( $paramName ) {
-                                               case "manualthumb":
+                                               case 'manualthumb':
+                                               case 'alt':
                                                        /// @fixme - possibly check validity here?
                                                        /// downstream behavior seems odd with missing manual thumbs.
                                                        $validated = true;
@@ -4329,22 +4331,6 @@ class Parser
                        $params['frame']['valign'] = key( $params['vertAlign'] );
                }
 
-               # Strip bad stuff out of the alt text
-               # We can't just use replaceLinkHoldersText() here, because if this function
-               # is called from replaceInternalLinks2(), mLinkHolders won't be up to date.
-               if ( $holders ) {
-                       $alt = $holders->replaceText( $caption );
-               } else {
-                       $alt = $this->replaceLinkHoldersText( $caption );
-               }
-
-               # make sure there are no placeholders in thumbnail attributes
-               # that are later expanded to html- so expand them now and
-               # remove the tags
-               $alt = $this->mStripState->unstripBoth( $alt );
-               $alt = Sanitizer::stripAllTags( $alt );
-
-               $params['frame']['alt'] = $alt;
                $params['frame']['caption'] = $caption;
 
                wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
index dad954c..5a2bbf6 100644 (file)
@@ -287,6 +287,7 @@ $magicWords = array(
        'img_middle'             => array( 1,    'middle'                 ),
        'img_bottom'             => array( 1,    'bottom'                 ),
        'img_text_bottom'        => array( 1,    'text-bottom'            ),
+       'img_alt'                => array( 1,    'alt=$1', 'alt $1'       ),
        'int'                    => array( 0,    'INT:'                   ),
        'sitename'               => array( 1,    'SITENAME'               ),
        'ns'                     => array( 0,    'NS:'                    ),