r42116 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42115‎ | r42116 | r42117 >
Date:21:20, 15 October 2008
Author:brion
Status:old
Tags:
Comment:
Fix for r41837 -- apply HTML stripping to explicit alt text as well as implicit.
Added parser test cases to confirm.
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -4362,6 +4362,7 @@
43634363 // manualthumb? downstream behavior seems odd with
43644364 // missing manual thumbs.
43654365 $validated = true;
 4366+ $value = $this->stripAltText( $value, $holders );
43664367 break;
43674368 case 'link':
43684369 $chars = self::EXT_LINK_URL_CLASS;
@@ -4412,23 +4413,8 @@
44134414
44144415 $params['frame']['caption'] = $caption;
44154416
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 );
44244418
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 -
44334419 # In the old days, [[Image:Foo|text...]] would set alt text. Later it
44344420 # came to also set the caption, ordinary text after the image -- which
44354421 # makes no sense, because that just repeats the text multiple times in
@@ -4449,7 +4435,7 @@
44504436 && !isset( $params['frame']['framed'] )
44514437 && !isset( $params['frame']['thumbnail'] )
44524438 && !isset( $params['frame']['manualthumb'] ) ) {
4453 - $params['frame']['alt'] = $tooltip;
 4439+ $params['frame']['alt'] = $params['frame']['title'];
44544440 }
44554441
44564442 wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
@@ -4464,7 +4450,26 @@
44654451
44664452 return $ret;
44674453 }
 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+ }
44684464
 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+
44694474 /**
44704475 * Set a flag in the output object indicating that the content is dynamic and
44714476 * shouldn't be cached.
Index: trunk/phase3/maintenance/parserTests.txt
@@ -3142,6 +3142,24 @@
31433143 !! end
31443144
31453145 !! 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
31463164 Link to image page- image page normally doesn't exists, hence edit link
31473165 Add test with existing image page
31483166 #<p><a href="https://www.mediawiki.org/wiki/Image:Test" title="Image:Test">Image:test</a>

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r41837(bug 368) Allow alt= attribute for images...simetrical16:33, 8 October 2008

Status & tagging log