Fix for r41837 -- apply HTML stripping to explicit alt text as well as implicit.
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 15 Oct 2008 21:20:13 +0000 (21:20 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 15 Oct 2008 21:20:13 +0000 (21:20 +0000)
Added parser test cases to confirm.

includes/parser/Parser.php
maintenance/parserTests.txt

index 0021e98..7b2f231 100644 (file)
@@ -4362,6 +4362,7 @@ class Parser
                                                        // manualthumb? downstream behavior seems odd with
                                                        // missing manual thumbs.
                                                        $validated = true;
+                                                       $value = $this->stripAltText( $value, $holders );
                                                        break;
                                                case 'link':
                                                        $chars = self::EXT_LINK_URL_CLASS;
@@ -4412,22 +4413,7 @@ class Parser
 
                $params['frame']['caption'] = $caption;
 
-               # Strip bad stuff out of the title (tooltip).  We can't just use
-               # replaceLinkHoldersText() here, because if this function is called
-               # from replaceInternalLinks2(), mLinkHolders won't be up-to-date.
-               if ( $holders ) {
-                       $tooltip = $holders->replaceText( $caption );
-               } else {
-                       $tooltip = $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
-               $tooltip = $this->mStripState->unstripBoth( $tooltip );
-               $tooltip = Sanitizer::stripAllTags( $tooltip );
-
-               $params['frame']['title'] = $tooltip;
+               $params['frame']['title'] = $this->stripAltText( $caption, $holders );
 
                # 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
@@ -4449,7 +4435,7 @@ class Parser
                && !isset( $params['frame']['framed'] )
                && !isset( $params['frame']['thumbnail'] )
                && !isset( $params['frame']['manualthumb'] ) ) {
-                       $params['frame']['alt'] = $tooltip;
+                       $params['frame']['alt'] = $params['frame']['title'];
                }
 
                wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
@@ -4464,6 +4450,25 @@ class Parser
 
                return $ret;
        }
+       
+       protected function stripAltText( $caption, $holders ) {
+               # Strip bad stuff out of the title (tooltip).  We can't just use
+               # replaceLinkHoldersText() here, because if this function is called
+               # from replaceInternalLinks2(), mLinkHolders won't be up-to-date.
+               if ( $holders ) {
+                       $tooltip = $holders->replaceText( $caption );
+               } else {
+                       $tooltip = $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
+               $tooltip = $this->mStripState->unstripBoth( $tooltip );
+               $tooltip = Sanitizer::stripAllTags( $tooltip );
+               
+               return $tooltip;
+       }
 
        /**
         * Set a flag in the output object indicating that the content is dynamic and
index 0990f39..34666b9 100644 (file)
@@ -3141,6 +3141,24 @@ Image with frame and link and explicit alt
 
 !! end
 
+!! test
+Image with wiki markup in implicit alt
+!! input
+[[Image:Foobar.jpg|testing '''bold''' in alt]]
+!! result
+<p><a href="/wiki/Image:Foobar.jpg" class="image" title="testing bold in alt"><img alt="testing bold in alt" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" border="0" /></a>
+</p>
+!! end
+
+!! test
+Image with wiki markup in explicit alt
+!! input
+[[Image:Foobar.jpg|alt=testing '''bold''' in alt]]
+!! result
+<p><a href="/wiki/Image:Foobar.jpg" class="image" title="Foobar.jpg"><img alt="testing bold in alt" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" border="0" /></a>
+</p>
+!! end
+
 !! test
 Link to image page- image page normally doesn't exists, hence edit link
 Add test with existing image page