From 083ec382c4afb0b43468130bdaf1e31dcb8918cd Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Tue, 18 Mar 2014 12:59:21 -0400 Subject: [PATCH] Handle conflicting image format options in predictable way. The PHP parser now uses the first image format option that appears, and ignores subsequent format options. This enforces the "zero or one" language in https://en.wikipedia.org/wiki/Wikipedia:Extended_image_syntax#Type and makes parser behavior more predictable. This also matches Parsoid behavior. Change-Id: Ifa32238b3d274123c7b98022cf688c33edfd7197 --- includes/parser/Parser.php | 8 +++++++ tests/parser/parserTests.txt | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index f2c4fbff7c..29fde6cad9 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -5329,6 +5329,7 @@ class Parser { $caption = ''; $params = array( 'frame' => array(), 'handler' => array(), 'horizAlign' => array(), 'vertAlign' => array() ); + $seenformat = false; foreach ( $parts as $part ) { $part = trim( $part ); list( $magicName, $value ) = $mwArray->matchVariableStartToEnd( $part ); @@ -5396,6 +5397,13 @@ class Parser { } } break; + case 'frameless': + case 'framed': + case 'thumbnail': + // use first appearing option, discard others. + $validated = ! $seenformat; + $seenformat = true; + break; default: # Most other things appear to be empty or numeric... $validated = ( $value === false || is_numeric( trim( $value ) ) ); diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 9808e5677a..2080f899ef 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -10141,6 +10141,52 @@ parsoid=wt2html,wt2wt,html2html

testing bold in alt

!! end +################### +# Conflicting image format options. +# First option specified should 'win'. +# All three cases in each test should be identical. + +!! test +Image with 'frameless' first. +!! wikitext +[[File:Foobar.jpg|frameless|caption]] + +[[File:Foobar.jpg|frameless|frame|caption]] + +[[File:Foobar.jpg|frameless|thumb|caption]] +!! html/php +

caption +

caption +

caption +

+!! end + +!! test +Image with 'frame' first. +!! wikitext +[[File:Foobar.jpg|frame|caption]] +[[File:Foobar.jpg|frame|frameless|caption]] +[[File:Foobar.jpg|frame|thumb|caption]] +!! html/php +
caption
+
caption
+
caption
+ +!! end + +!! test +Image with 'thumb' first. +!! wikitext +[[File:Foobar.jpg|thumb|caption]] +[[File:Foobar.jpg|thumb|frameless|caption]] +[[File:Foobar.jpg|thumb|frame|caption]] +!! html/php +
caption
+
caption
+
caption
+ +!! end + ################### # Image sizing. # See https://www.mediawiki.org/wiki/Help:Images#Size_and_frame -- 2.20.1