Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -4362,6 +4362,7 @@ |
4363 | 4363 | // manualthumb? downstream behavior seems odd with |
4364 | 4364 | // missing manual thumbs. |
4365 | 4365 | $validated = true; |
| 4366 | + $value = $this->stripAltText( $value, $holders ); |
4366 | 4367 | break; |
4367 | 4368 | case 'link': |
4368 | 4369 | $chars = self::EXT_LINK_URL_CLASS; |
— | — | @@ -4412,23 +4413,8 @@ |
4413 | 4414 | |
4414 | 4415 | $params['frame']['caption'] = $caption; |
4415 | 4416 | |
4416 | | - # Strip bad stuff out of the title (tooltip). We can't just use |
4417 | | - # replaceLinkHoldersText() here, because if this function is called |
4418 | | - # from replaceInternalLinks2(), mLinkHolders won't be up-to-date. |
4419 | | - if ( $holders ) { |
4420 | | - $tooltip = $holders->replaceText( $caption ); |
4421 | | - } else { |
4422 | | - $tooltip = $this->replaceLinkHoldersText( $caption ); |
4423 | | - } |
| 4417 | + $params['frame']['title'] = $this->stripAltText( $caption, $holders ); |
4424 | 4418 | |
4425 | | - # make sure there are no placeholders in thumbnail attributes |
4426 | | - # that are later expanded to html- so expand them now and |
4427 | | - # remove the tags |
4428 | | - $tooltip = $this->mStripState->unstripBoth( $tooltip ); |
4429 | | - $tooltip = Sanitizer::stripAllTags( $tooltip ); |
4430 | | - |
4431 | | - $params['frame']['title'] = $tooltip; |
4432 | | - |
4433 | 4419 | # In the old days, [[Image:Foo|text...]] would set alt text. Later it |
4434 | 4420 | # came to also set the caption, ordinary text after the image -- which |
4435 | 4421 | # makes no sense, because that just repeats the text multiple times in |
— | — | @@ -4449,7 +4435,7 @@ |
4450 | 4436 | && !isset( $params['frame']['framed'] ) |
4451 | 4437 | && !isset( $params['frame']['thumbnail'] ) |
4452 | 4438 | && !isset( $params['frame']['manualthumb'] ) ) { |
4453 | | - $params['frame']['alt'] = $tooltip; |
| 4439 | + $params['frame']['alt'] = $params['frame']['title']; |
4454 | 4440 | } |
4455 | 4441 | |
4456 | 4442 | wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) ); |
— | — | @@ -4464,7 +4450,26 @@ |
4465 | 4451 | |
4466 | 4452 | return $ret; |
4467 | 4453 | } |
| 4454 | + |
| 4455 | + protected function stripAltText( $caption, $holders ) { |
| 4456 | + # Strip bad stuff out of the title (tooltip). We can't just use |
| 4457 | + # replaceLinkHoldersText() here, because if this function is called |
| 4458 | + # from replaceInternalLinks2(), mLinkHolders won't be up-to-date. |
| 4459 | + if ( $holders ) { |
| 4460 | + $tooltip = $holders->replaceText( $caption ); |
| 4461 | + } else { |
| 4462 | + $tooltip = $this->replaceLinkHoldersText( $caption ); |
| 4463 | + } |
4468 | 4464 | |
| 4465 | + # make sure there are no placeholders in thumbnail attributes |
| 4466 | + # that are later expanded to html- so expand them now and |
| 4467 | + # remove the tags |
| 4468 | + $tooltip = $this->mStripState->unstripBoth( $tooltip ); |
| 4469 | + $tooltip = Sanitizer::stripAllTags( $tooltip ); |
| 4470 | + |
| 4471 | + return $tooltip; |
| 4472 | + } |
| 4473 | + |
4469 | 4474 | /** |
4470 | 4475 | * Set a flag in the output object indicating that the content is dynamic and |
4471 | 4476 | * shouldn't be cached. |
Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -3142,6 +3142,24 @@ |
3143 | 3143 | !! end |
3144 | 3144 | |
3145 | 3145 | !! test |
| 3146 | +Image with wiki markup in implicit alt |
| 3147 | +!! input |
| 3148 | +[[Image:Foobar.jpg|testing '''bold''' in alt]] |
| 3149 | +!! result |
| 3150 | +<p><a href="https://www.mediawiki.org/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> |
| 3151 | +</p> |
| 3152 | +!! end |
| 3153 | + |
| 3154 | +!! test |
| 3155 | +Image with wiki markup in explicit alt |
| 3156 | +!! input |
| 3157 | +[[Image:Foobar.jpg|alt=testing '''bold''' in alt]] |
| 3158 | +!! result |
| 3159 | +<p><a href="https://www.mediawiki.org/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> |
| 3160 | +</p> |
| 3161 | +!! end |
| 3162 | + |
| 3163 | +!! test |
3146 | 3164 | Link to image page- image page normally doesn't exists, hence edit link |
3147 | 3165 | Add test with existing image page |
3148 | 3166 | #<p><a href="https://www.mediawiki.org/wiki/Image:Test" title="Image:Test">Image:test</a> |