Merge "Add dotall modifier to EDITSECTION_REGEX"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sun, 18 Dec 2016 02:53:47 +0000 (02:53 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sun, 18 Dec 2016 02:53:47 +0000 (02:53 +0000)
1  2 
includes/parser/ParserOutput.php
tests/parser/parserTests.txt

@@@ -188,9 -188,7 +188,9 @@@ class ParserOutput extends CacheTime 
         */
        private $mExtensionData = [];
  
 -      /** @var array $mLimitReportData Parser limit report data. */
 +      /**
 +       * @var array $mLimitReportData Parser limit report data.
 +       */
        private $mLimitReportData = [];
  
        /**
        private $mMaxAdaptiveExpiry = INF;
  
        const EDITSECTION_REGEX =
-               '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
+               '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#s';
  
        // finalizeAdaptiveCacheExpiry() uses TTL = MAX( m * PARSE_TIME + b, MIN_AR_TTL)
        // Current values imply that m=3933.333333 and b=-333.333333
         * @code
         *    $parser->getOutput()->my_ext_foo = '...';
         * @endcode
 -       *
         */
        public function setProperty( $name, $value ) {
                $this->mProperties[$name] = $value;
        /**
         * Sets parser limit report data for a key
         *
 -       * If $value consist of a list of two floats, it will be interpreted as
 -       * (actual value, maximum allowed value). The presence of a "-" in $key will cause
 -       * the first part of the key to be interpreted as a namespace.
 +       * The key is used as the prefix for various messages used for formatting:
 +       *  - $key: The label for the field in the limit report
 +       *  - $key-value-text: Message used to format the value in the "NewPP limit
 +       *      report" HTML comment. If missing, uses $key-format.
 +       *  - $key-value-html: Message used to format the value in the preview
 +       *      limit report table. If missing, uses $key-format.
 +       *  - $key-value: Message used to format the value. If missing, uses "$1".
 +       *
 +       * Note that all values are interpreted as wikitext, and so should be
 +       * encoded with htmlspecialchars() as necessary, but should avoid complex
 +       * HTML for sanity of display in the "NewPP limit report" comment.
         *
         * @since 1.22
 -       * @param string $key Data key
 -       * @param mixed $value Data value One of (float, string, bool, JSON serializable array)
 +       * @param string $key Message key
 +       * @param mixed $value Appropriate for Message::params()
         */
        public function setLimitReportData( $key, $value ) {
 -              if ( is_array( $value ) ) {
 -                      if ( array_keys( $value ) === [ 0, 1 ]
 -                              && is_numeric( $value[0] )
 -                              && is_numeric( $value[1] )
 -                      ) {
 -                              $data = [ 'value' => $value[0], 'limit' => $value[1] ];
 -                      } else {
 -                              $data = $value;
 -                      }
 -              } else {
 -                      $data = $value;
 -              }
 -
 -              if ( strpos( $key, '-' ) ) {
 -                      list( $ns, $name ) = explode( '-', $key, 2 );
 -                      $this->mLimitReportData[$ns][$name] = $data;
 -              } else {
 -                      $this->mLimitReportData[$key] = $data;
 -              }
 +              $this->mLimitReportData[$key] = $value;
        }
  
        /**
@@@ -1,5 -1,5 +1,5 @@@
  # MediaWiki Parser test cases
 -# Some taken from http://meta.wikimedia.org/wiki/Parser_testing
 +# Some taken from https://meta.wikimedia.org/wiki/Parser_testing
  # All (C) their respective authors and released under the GPL
  #
  # The syntax should be fairly self-explanatory.
@@@ -271,12 -271,6 +271,12 @@@ Template:EmptyTRWithHTMLAttrTes
  </table>
  !!endarticle
  
 +!! article
 +Template:CircularRef
 +!! text
 +<ref>{{CircularRef}}</ref>
 +!! endarticle
 +
  ###
  ### Basic tests
  ###
@@@ -286,15 -280,6 +286,15 @@@ Blank inpu
  !! html
  !! end
  
 +!! test
 +CircularRef
 +!! wikitext
 +{{CircularRef}}
 +<references />
 +!! html/parsoid
 +<p><span about="#mwt1" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Transclusion  mw:Extension/ref" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"CircularRef","href":"./Template:CircularRef"},"params":{},"i":0}}]}'><a href="#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></span></p>
 +<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">Error: Expansion loop detected at <a data-parsoid='{"a":{"href":null},"sa":{"href":"Template:CircularRef"}}'>Template:CircularRef</a></span></li></ol>
 +!! end
  
  !! test
  Simple paragraph
@@@ -528,6 -513,17 +528,17 @@@ Extra newlines between heading and cont
  </p>
  !! end
  
+ !! test
+ Heading with line break in nowiki
+ !! wikitext
+ == A <nowiki>B
+ C</nowiki> ==
+ !! html
+ <h2><span class="mw-headline" id="A_B.0AC">A B
+ C</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: A B&#10;C">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
+ !! end
  !! test
  Parsing an URL
  !! wikitext
@@@ -539,7 -535,7 +550,7 @@@ http://fr.wikipedia.org/wiki/ð\9f\8d
  !! end
  
  # Note that the html+tidy output removes the spaces after the <li>,
 -# which is a bug (http://sourceforge.net/p/tidy/bugs/945/, etc).
 +# which is a bug (https://sourceforge.net/p/tidy/bugs/945/, etc).
  # This is an issue for all tests with lists.  We intentionally do
  # *not* add html+tidy clauses for these, as we don't want to
  # document/test the broken behavior.  (Parsoid matches the non-tidy
@@@ -1245,7 -1241,7 +1256,7 @@@ Text-level semantic html elements in wi
  !! end
  
  # test cases taken from
 -# http://www.w3.org/TR/html5/text-level-semantics.html#the-ruby-element
 +# https://www.w3.org/TR/html5/text-level-semantics.html#the-ruby-element
  !! test
  Ruby markup (W3C-style)
  !! wikitext
@@@ -1308,7 -1304,7 +1319,7 @@@ Non-word characters don't terminate ta
  </p>
  !! end
  
 -# There is a tidy bug here: http://sourceforge.net/p/tidy/bugs/946/
 +# There is a tidy bug here: https://sourceforge.net/p/tidy/bugs/946/
  # If the non-word-character tag made it through the sanitizer, tidy
  # would munge it up.
  !! test
@@@ -1435,15 -1431,6 +1446,15 @@@ sed abit
  </span></p>
  !! end
  
 +!! test
 +Don't parse <nowiki><span class="error"></nowiki> (T149622)
 +!! wikitext
 +<nowiki><span class="error"></nowiki>
 +!! html/php
 +<p>&lt;span class="error"&gt;
 +</p>
 +!! end
 +
  !! test
  nowiki 3
  !! wikitext
@@@ -2727,12 -2714,10 +2738,12 @@@ Templates: Handle empty comment-and-ws-
  <!--should be ignored-->
   <!--should be ignored as well-->
  bar}}
 -!! html
 +!! html/php
  <p>foo
  bar
  </p>
 +!! html/parsoid
 +<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo\n&lt;!--should be ignored-->\n &lt;!--should be ignored as well-->\nbar"}},"i":0}}]}'>foo <!--should be ignored--> <!--should be ignored as well--> bar</p>
  !! end
  
  !! test
@@@ -2742,28 -2727,15 +2753,28 @@@ Templates: Handle comments in the targe
  <!-- should be ignored -->
  |foo}}
  
 +{{echo
 +<!-- should be ignored and spaces on next line should not trip us up (T147742) -->
 +  |foo}}
 +
  {{echo<!-- should be ignored -->
  |foo}}
  
  {{echo<!-- should be ignored -->|foo}}
  
  {{<!-- should be ignored -->echo|foo}}
 -!!html/parsoid
 +!! html/php
 +<p>foo
 +</p><p>foo
 +</p><p>foo
 +</p><p>foo
 +</p><p>foo
 +</p>
 +!! html/parsoid
  <p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo\n&lt;!-- should be ignored -->\n","href":"./Template:Echo"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</p>
  
 +<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo\n&lt;!-- should be ignored and spaces on next line should not trip us up (T147742) -->\n  ","href":"./Template:Echo"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</p>
 +
  <p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo&lt;!-- should be ignored -->\n","href":"./Template:Echo"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</p>
  
  <p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo&lt;!-- should be ignored -->","href":"./Template:Echo"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</p>
@@@ -2785,13 -2757,7 +2796,13 @@@ Templates: Handle comments in paramete
  {{echo|1<!-- should be ignored -->=foo}}
  
  {{echo|<!-- should be ignored -->1=foo}}
 -!!html/parsoid
 +!! html/php
 +<p>foo
 +</p><p>foo
 +</p><p>foo
 +</p><p>foo
 +</p>
 +!! html/parsoid
  <p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo","key":{"wt":"1\n&lt;!-- should be ignored -->"}}},"i":0}}]}'>foo</p>
  
  <p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo","key":{"wt":"&lt;!-- should be ignored -->\n1"}}},"i":0}}]}'>foo</p>
  Templates: Other wikitext in parameter names (bug 67657)
  !! wikitext
  {{echo|''1''=foo}}
 -!!html/parsoid
 -<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"&#39;&#39;1&#39;&#39;":{"wt":"foo"}},"i":0}}]}'>{{{1}}}</p>
 -!!html/php
 +!! html/php
  <p>{{{1}}}
  </p>
 +!! html/parsoid
 +<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"&#39;&#39;1&#39;&#39;":{"wt":"foo"}},"i":0}}]}'>{{{1}}}</p>
  !!end
  
  #--------------------------------------------------------------------
@@@ -3708,6 -3674,7 +3719,6 @@@ Definition and unordered list using wik
  !! end
  
  !! test
 -
  Definition list with empty definition and following paragraph
  !! wikitext
  ; term:
@@@ -3884,7 -3851,7 +3895,7 @@@ Definition Lists: Hacky use to indent t
  ## All Parsoid only definition list tests have this difference.
  ##
  ## See also: https://phabricator.wikimedia.org/T8569
 -## and http://lists.wikimedia.org/pipermail/wikitext-l/2011-November/000483.html
 +## and https://lists.wikimedia.org/pipermail/wikitext-l/2011-November/000483.html
  
  !! test
  Table / list interaction: indented table with lists in table contents
@@@ -5238,7 -5205,7 +5249,7 @@@ http://www.example.com/?title=AT%26
  <p><a rel="mw:ExtLink" href="http://www.example.com/?title=AT%26T">http://www.example.com/?title=AT%26T</a></p>
  !! end
  
 -# According to http://www.w3.org/TR/2011/WD-html5-20110525/Overview.html#parsing-urls a plain
 +# According to https://www.w3.org/TR/2011/WD-html5-20110525/Overview.html#parsing-urls a plain
  # % is actually legal in HTML5. Any change in output would need testing though.
  !! test
  Bug 4781, 5267: %25 in URL
@@@ -5825,7 -5792,7 +5836,7 @@@ Plain ''italic'''s plai
  
  # This should not produce <table></table> as <table><tr><td></td></tr></table>
  # is the bare minimum required by the spec, see:
 -# http://www.w3.org/TR/xhtml-modularization/dtd_module_defs.html#a_module_Basic_Tables
 +# https://www.w3.org/TR/xhtml-modularization/dtd_module_defs.html#a_module_Basic_Tables
  # Parsoid team replies: empty table tags are legal in HTML5
  !! test
  A table with no data.
@@@ -7461,23 -7428,6 +7472,23 @@@ Piped link with no link tex
  <p>[[Thomas Bek (bishop of St David's)|]]</p>
  !! end
  
 +!! test
 +Piped link with empty link text
 +!! wikitext
 +[[Main Page|<nowiki />]] - empty nowiki
 +[[Main Page| ]] - empty space
 +[[Main Page|&nbsp;]] - empty non breaking space
 +!! html/php
 +<p><a href="/wiki/Main_Page" title="Main Page"></a> - empty nowiki
 +<a href="/wiki/Main_Page" title="Main Page"> </a> - empty space
 +<a href="/wiki/Main_Page" title="Main Page">&#160;</a> - empty non breaking space
 +</p>
 +!! html/parsoid
 +<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page"><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki />"}'/></a> - empty nowiki
 +<a rel="mw:WikiLink" href="./Main_Page" title="Main Page"> </a> - empty space
 +<a rel="mw:WikiLink" href="./Main_Page" title="Main Page"><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span></a> - empty non breaking space</p>
 +!! end
 +
  !! test
  Broken link
  !! wikitext
@@@ -7617,6 -7567,8 +7628,6 @@@ Link with multiple pipe
  </p>
  !! end
  
 -# Note that parsoid does not munge anchor text; all non-space
 -# characters are valid in HTML5 ids.
  !! test
  Anchor containing a #. (bug 63430)
  !! wikitext
  <p><a href="/wiki/Main_Page#And.23Link" title="Main Page">Main Page#And#Link</a>
  </p>
  !! html/parsoid
 -<p><a rel="mw:WikiLink" href="./Main_Page#And%23Link" title="Main Page">Main Page#And#Link</a></p>
 +<p><a rel="mw:WikiLink" href="./Main_Page#And.23Link" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#And.23Link"},"sa":{"href":"Main Page#And#Link"}}'>Main Page#And#Link</a></p>
  !! end
  
  !! test
@@@ -7740,16 -7692,18 +7751,16 @@@ Link containing % as a double hex seque
  </p>
  !!end
  
 -# note that parsoid does not munge anchor text; all non-space
 -# characters are valid in HTML5 anchors.
 +## Example for such a section: == < ==
  !! test
  Link containing "#<" and "#>" % as a hex sequences- these are valid section anchors
 -Example for such a section: == < ==
  !! wikitext
  [[%23%3c]][[%23%3e]]
  !! html/php
  <p><a href="#.3C">#&lt;</a><a href="#.3E">#&gt;</a>
  </p>
  !! html/parsoid
 -<p><a rel="mw:WikiLink" href="./Main_Page#%3C" title="Main Page">#&lt;</a><a rel="mw:WikiLink" href="./Main_Page#%3E" title="Main Page">#></a></p>
 +<p><a rel="mw:WikiLink" href="./Main_Page#.3C" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#.3C"},"sa":{"href":"%23%3c"}}'>#&lt;</a><a rel="mw:WikiLink" href="./Main_Page#.3E" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#.3E"},"sa":{"href":"%23%3e"}}'>#></a></p>
  !! end
  
  !! test
@@@ -8269,7 -8223,7 +8280,7 @@@ Link with angle bracket after ancho
  <p><a href="/wiki/Foo#.3Cbar.3E" title="Foo">Foo#&lt;bar&gt;</a>
  </p>
  !! html/parsoid
 -<p><a rel="mw:WikiLink" href="./Foo#%3Cbar%3E" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo#%3Cbar%3E"},"sa":{"href":"Foo#&lt;bar>"}}'>Foo#&lt;bar></a></p>
 +<p><a rel="mw:WikiLink" href="./Foo#.3Cbar.3E" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo#.3Cbar.3E"},"sa":{"href":"Foo#&lt;bar>"}}'>Foo#&lt;bar></a></p>
  !! end
  
  ###
@@@ -8327,23 -8281,6 +8338,23 @@@ Interwiki link with fragment (bug 2130
  </p>
  !! end
  
 +!! test
 +Link scenarios with escaped fragments
 +!! wikitext
 +[[#Is this great?]]
 +[[Foo#Is this great?]]
 +[[meatball:Foo#Is this great?]]
 +!! html/php
 +<p><a href="#Is_this_great.3F">#Is this great?</a>
 +<a href="/wiki/Foo#Is_this_great.3F" title="Foo">Foo#Is this great?</a>
 +<a href="http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F" class="extiw" title="meatball:Foo">meatball:Foo#Is this great?</a>
 +</p>
 +!! html/parsoid
 +<p><a rel="mw:WikiLink" href="./Main_Page#Is_this_great.3F" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#Is_this_great.3F"},"sa":{"href":"#Is this great?"}}'>#Is this great?</a>
 +<a rel="mw:WikiLink" href="./Foo#Is_this_great.3F" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo#Is_this_great.3F"},"sa":{"href":"Foo#Is this great?"}}'>Foo#Is this great?</a>
 +<a rel="mw:ExtLink" href="http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F" title="meatball:Foo" data-parsoid='{"stx":"simple","a":{"href":"http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F"},"sa":{"href":"meatball:Foo#Is this great?"},"isIW":true}'>meatball:Foo#Is this great?</a></p>
 +!! end
 +
  # Ideally the wikipedia: prefix here should be proto-relative too
  # [CSA]: this is kind of a bogus test, as the PHP parser test doesn't
  # define the 'en' prefix, and originally the test used 'wikipedia',
@@@ -10408,6 -10345,7 +10419,6 @@@ language=d
  </p>
  !! end
  
 -
  !! test
  Urlencode
  !! wikitext
  {{urlencode:hi world?!|WIKI}}
  {{urlencode:hi world?!|PATH}}
  {{urlencode:hi world?!|QUERY}}
 -!! html
 +!! html/php
  <p>hi+world%3F%21
  hi_world%3F!
  hi%20world%3F%21
@@@ -15962,7 -15900,7 +15973,7 @@@ parsoid=wt2html,html2htm
  <div id="title.3D">HTML rocks</div>
  
  !! html/parsoid
 -<div id="title=" data-parsoid='{"stx":"html"}'>HTML rocks</div>
 +<div id="title.3D" data-parsoid='{"stx":"html"}'>HTML rocks</div>
  !! end
  
  !! test
@@@ -17140,11 -17078,9 +17151,11 @@@ Table not started</td></tr></table
  Sanitizer: Escaping of spaces, multibyte characters, colons & other stuff in id=""
  !! wikitext
  <span id="æ: v">byte</span>[[#æ: v|backlink]]
 -!! html
 +!! html/php
  <p><span id=".C3.A6:_v">byte</span><a href="#.C3.A6:_v">backlink</a>
  </p>
 +!! html/parsoid
 +<p><span id=".C3.A6:_v" data-parsoid='{"stx":"html","a":{"id":".C3.A6:_v"},"sa":{"id":"æ: v"}}'>byte</span><a rel="mw:WikiLink" href="./Main_Page#.C3.A6:_v" data-parsoid='{"stx":"piped","a":{"href":"./Main_Page#.C3.A6:_v"},"sa":{"href":"#æ: v"}}'>backlink</a></p>
  !! end
  
  # In HTML5, the restrictions are that id must contain at least one character,
@@@ -18893,14 -18829,8 +18904,14 @@@ title=[[Parser test]
  !! end
  ### Note: Above tests excludes the "{{NUMBEROFADMINS}}" magic word because it generates a MySQL error when included.
  
 +## Parsoid thinks the "centre" here is a property, not a caption.
  !! test
  Gallery
 +!! options
 +parsoid={
 +  "modes": ["wt2html"],
 +  "nativeGallery": true
 +}
  !! wikitext
  <gallery>
  image1.png |
@@@ -18912,7 -18842,7 +18923,7 @@@ image4    |300px| centr
  [[x|xx]]]]
  * image6
  </gallery>
 -!! html
 +!! html/php
  <ul class="gallery mw-gallery-traditional">
                <li class="gallerybox" style="width: 155px"><div style="width: 155px">
                        <div class="thumb" style="height: 150px;">Image1.png</div>
                </div></li>
  </ul>
  
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt3" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">image1.png </span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">image2.gif</span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">image3</span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">image4    </span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;"> image5.svg</span></div><div class="gallerytext"> <a rel="mw:ExtLink" href="http://///////">http://///////</a></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">* image6</span></div><div class="gallerytext"></div></li>
 +</ul>
  !! end
  
  !! test
 -Gallery (with options)
 +Gallery (with options, html)
 +!! options
 +parsoid={
 +  "modes": ["wt2html", "html2html"],
 +  "nativeGallery": true
 +}
  !! wikitext
 -<gallery widths='70px' heights='40px' perrow='2' caption='Foo [[Main Page]]' >
 +<gallery widths="70px" heights="40px" perrow="2" caption="Foo [[Main Page]]">
  File:Nonexistent.jpg|caption
  File:Nonexistent.jpg
  image:foobar.jpg|some '''caption''' [[Main Page]]
  image:foobar.jpg
  image:foobar.jpg|Blabla|alt=This is a foo-bar.|blabla.
  </gallery>
 -!! html
 +!! html/php
 +<ul class="gallery mw-gallery-traditional" style="max-width: 226px;_width: 226px;">
 +      <li class='gallerycaption'>Foo <a href="/wiki/Main_Page" title="Main Page">Main Page</a></li>
 +              <li class="gallerybox" style="width: 105px"><div style="width: 105px">
 +                      <div class="thumb" style="height: 70px;">Nonexistent.jpg</div>
 +                      <div class="gallerytext">
 +<p>caption
 +</p>
 +                      </div>
 +              </div></li>
 +              <li class="gallerybox" style="width: 105px"><div style="width: 105px">
 +                      <div class="thumb" style="height: 70px;">Nonexistent.jpg</div>
 +                      <div class="gallerytext">
 +                      </div>
 +              </div></li>
 +              <li class="gallerybox" style="width: 105px"><div style="width: 105px">
 +                      <div class="thumb" style="width: 100px;"><div style="margin:31px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" width="70" height="8" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/105px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/140px-Foobar.jpg 2x" /></a></div></div>
 +                      <div class="gallerytext">
 +<p>some <b>caption</b> <a href="/wiki/Main_Page" title="Main Page">Main Page</a>
 +</p>
 +                      </div>
 +              </div></li>
 +              <li class="gallerybox" style="width: 105px"><div style="width: 105px">
 +                      <div class="thumb" style="width: 100px;"><div style="margin:31px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" width="70" height="8" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/105px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/140px-Foobar.jpg 2x" /></a></div></div>
 +                      <div class="gallerytext">
 +                      </div>
 +              </div></li>
 +              <li class="gallerybox" style="width: 105px"><div style="width: 105px">
 +                      <div class="thumb" style="width: 100px;"><div style="margin:31px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="This is a foo-bar." src="http://example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" width="70" height="8" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/105px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/140px-Foobar.jpg 2x" /></a></div></div>
 +                      <div class="gallerytext">
 +<p>blabla.
 +</p>
 +                      </div>
 +              </div></li>
 +</ul>
 +
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" style="max-width: 226px; _width: 226px;" typeof="mw:Extension/gallery" about="#mwt3" data-mw='{"name":"gallery","attrs":{"widths":"70px","heights":"40px","perrow":"2"},"body":{}}'>
 +<li class="gallerycaption">Foo <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext">caption</div></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext">some <b>caption</b> <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></div></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img alt="This is a foo-bar." resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext">blabla.</div></li>
 +</ul>
 +!! end
 +
 +!! test
 +Gallery (with options, extsrc)
 +!! options
 +parsoid={
 +  "nativeGallery": false
 +}
 +!! wikitext
 +<gallery widths="70px" heights="40px" perrow="2" caption="Foo [[Main Page]]">
 +File:Nonexistent.jpg|caption
 +File:Nonexistent.jpg
 +image:foobar.jpg|some '''caption''' [[Main Page]]
 +image:foobar.jpg
 +image:foobar.jpg|Blabla|alt=This is a foo-bar.|blabla.
 +</gallery>
 +!! html/php
  <ul class="gallery mw-gallery-traditional" style="max-width: 226px;_width: 226px;">
        <li class='gallerycaption'>Foo <a href="/wiki/Main_Page" title="Main Page">Main Page</a></li>
                <li class="gallerybox" style="width: 105px"><div style="width: 105px">
                </div></li>
  </ul>
  
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" style="max-width: 226px; _width: 226px;" typeof="mw:Extension/gallery" about="#mwt3" data-parsoid='{}' data-mw='{"name":"gallery","attrs":{"widths":"70px","heights":"40px","perrow":"2","caption":"Foo [[Main Page]]"},"body":{"extsrc":"\nFile:Nonexistent.jpg|caption\nFile:Nonexistent.jpg\nimage:foobar.jpg|some &#39;&#39;&#39;caption&#39;&#39;&#39; [[Main Page]]\nimage:foobar.jpg\nimage:foobar.jpg|Blabla|alt=This is a foo-bar.|blabla.\n"}}'>
 +<li class="gallerycaption">Foo <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext">caption</div></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext">some <b>caption</b> <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></div></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img alt="This is a foo-bar." resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext">blabla.</div></li>
 +</ul>
  !! end
  
  !! test
  Gallery with link that has fragment
 +!! options
 +parsoid={
 +  "modes": ["wt2html", "html2html"],
 +  "nativeGallery": true
 +}
  !! wikitext
  <gallery>
  image:foobar.jpg|link=Main_Page
  image:foobar.jpg|link=Main_Page#section
  image:foobar.jpg|link=Main Page#section|caption
  </gallery>
 -!! html
 +!! html/php
  <ul class="gallery mw-gallery-traditional">
                <li class="gallerybox" style="width: 155px"><div style="width: 155px">
                        <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/Main_Page"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
                </div></li>
  </ul>
  
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./Main_Page"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./Main_Page#section"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./Main_Page#section"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext">caption</div></li>
 +</ul>
 +!! end
 +
 +## Whoops, Parsoid shouldn't be parsing templates in the attribute caption!
 +!! test
 +Gallery with template inside caption
 +!! options
 +parsoid={
 +  "nativeGallery": true
 +}
 +!! wikitext
 +<gallery caption="{{echo|hi}}">
 +File:Foobar.jpg|{{echo|ho}}
 +</gallery>
 +!! html/php
 +<ul class="gallery mw-gallery-traditional">
 +      <li class='gallerycaption'>{{echo|hi}}</li>
 +              <li class="gallerybox" style="width: 155px"><div style="width: 155px">
 +                      <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
 +                      <div class="gallerytext">
 +<p>ho
 +</p>
 +                      </div>
 +              </div></li>
 +</ul>
 +
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt6" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerycaption"><span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi"}},"i":0}}]}'>hi</span></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><span about="#mwt5" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"ho"}},"i":0}}]}'>ho</span></div></li>
 +</ul>
  !! end
  
  !! test
  Gallery with wikitext inside caption
 +!! options
 +parsoid={
 +  "nativeGallery": true
 +}
  !! wikitext
  <gallery>
 -File:foobar.jpg|[[File:foobar.jpg|20px|desc|alt=inneralt]]|alt=galleryalt
 -File:foobar.jpg|{{Test|unamedParam|alt=param}}|alt=galleryalt
 +File:Foobar.jpg|alt=galleryalt|[[File:Foobar.jpg|alt=inneralt|20x20px|desc]]
 +File:Foobar.jpg|alt=galleryalt|{{Test|unamedParam|alt=param}}
  </gallery>
 -!! html
 +!! html/php
  <ul class="gallery mw-gallery-traditional">
                <li class="gallerybox" style="width: 155px"><div style="width: 155px">
                        <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
                </div></li>
  </ul>
  
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt6" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><span typeof="mw:Image" data-mw='{"caption":"desc"}'><a href="./File:Foobar.jpg"><img alt="inneralt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/20px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="2" width="20"/></a></span></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><span about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Test","href":"./Template:Test"},"params":{"1":{"wt":"unamedParam"},"alt":{"wt":"param"}},"i":0}}]}'>This is a test template</span></div></li>
 +</ul>
  !! end
  
  !! test
 -gallery (with showfilename option)
 +Gallery (with showfilename option)
 +!! options
 +parsoid={
 +  "nativeGallery": true
 +}
  !! wikitext
 -<gallery showfilename>
 +<gallery showfilename="">
  File:Nonexistent.jpg|caption
  File:Nonexistent.jpg
 -image:foobar.jpg|some '''caption''' [[Main Page]]
 +File:Foobar.jpg|some '''caption''' [[Main Page]]
  File:Foobar.jpg
  </gallery>
 -!! html
 +!! html/php
  <ul class="gallery mw-gallery-traditional">
                <li class="gallerybox" style="width: 155px"><div style="width: 155px">
                        <div class="thumb" style="height: 150px;">Nonexistent.jpg</div>
@@@ -19239,23 -19031,10 +19250,23 @@@ some <b>caption</b> <a href="/wiki/Main
                </div></li>
  </ul>
  
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt3" data-mw='{"name":"gallery","attrs":{"showfilename":""},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"><a href="./File:Nonexistent.jpg" class="galleryfilename galleryfilename-truncate" title="File:Nonexistent.jpg">File:Nonexistent.jpg</a>caption</div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"><a href="./File:Nonexistent.jpg" class="galleryfilename galleryfilename-truncate" title="File:Nonexistent.jpg">File:Nonexistent.jpg</a></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><a href="./File:Foobar.jpg" class="galleryfilename galleryfilename-truncate" title="File:Foobar.jpg">File:Foobar.jpg</a>some <b>caption</b> <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><a href="./File:Foobar.jpg" class="galleryfilename galleryfilename-truncate" title="File:Foobar.jpg">File:Foobar.jpg</a></div></li>
 +</ul>
  !! end
  
 +## Should Parsoid be preserving these variations?
  !! test
  Gallery (with namespace-less filenames)
 +!! options
 +parsoid={
 +  "modes": ["wt2html", "html2html"],
 +  "nativeGallery": true
 +}
  !! wikitext
  <gallery>
  File:Nonexistent.jpg
@@@ -19263,7 -19042,7 +19274,7 @@@ Nonexistent.jp
  image:foobar.jpg
  foobar.jpg
  </gallery>
 -!! html
 +!! html/php
  <ul class="gallery mw-gallery-traditional">
                <li class="gallerybox" style="width: 155px"><div style="width: 155px">
                        <div class="thumb" style="height: 150px;">Nonexistent.jpg</div>
                </div></li>
  </ul>
  
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">Nonexistent.jpg</span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
 +</ul>
 +!! end
 +
 +!! test
 +Gallery override link with WikiLink (T36852)
 +!! options
 +parsoid={
 +  "nativeGallery": true
 +}
 +!! wikitext
 +<gallery>
 +File:Foobar.jpg|alt=galleryalt|link=InterWikiLink
 +</gallery>
 +!! html/php
 +<ul class="gallery mw-gallery-traditional">
 +              <li class="gallerybox" style="width: 155px"><div style="width: 155px">
 +                      <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/InterWikiLink"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
 +                      <div class="gallerytext">
 +                      </div>
 +              </div></li>
 +</ul>
 +
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-parsoid='{"dsr":[0,70,2,2]}' data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./InterWikiLink"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
 +</ul>
 +!! end
 +
 +!! test
 +Gallery override link with absolute external link (T36852)
 +!! options
 +parsoid={
 +  "nativeGallery": true
 +}
 +!! wikitext
 +<gallery>
 +File:Foobar.jpg|alt=galleryalt|link=http://www.example.org
 +</gallery>
 +!! html/php
 +<ul class="gallery mw-gallery-traditional">
 +              <li class="gallerybox" style="width: 155px"><div style="width: 155px">
 +                      <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="http://www.example.org"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
 +                      <div class="gallerytext">
 +                      </div>
 +              </div></li>
 +</ul>
 +
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="http://www.example.org"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
 +</ul>
 +!! end
 +
 +!! test
 +Gallery override link with malicious javascript (T36852)
 +!! options
 +parsoid={
 +  "modes": ["wt2html", "html2html"],
 +  "nativeGallery": true
 +}
 +!! wikitext
 +<gallery>
 +File:Foobar.jpg|alt=galleryalt|link=" onclick="alert('malicious javascript code!');
 +</gallery>
 +!! html/php
 +<ul class="gallery mw-gallery-traditional">
 +              <li class="gallerybox" style="width: 155px"><div style="width: 155px">
 +                      <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/%22_onclick%3D%22alert(%27malicious_javascript_code!%27);"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
 +                      <div class="gallerytext">
 +                      </div>
 +              </div></li>
 +</ul>
 +
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./&quot;_onclick=&quot;alert('malicious_javascript_code!');"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
 +</ul>
 +!! end
 +
 +!! test
 +Gallery with invalid title as link (T45964)
 +!! options
 +parsoid={
 +  "modes": ["wt2html", "html2html"],
 +  "nativeGallery": true
 +}
 +!! wikitext
 +<gallery>
 +File:Foobar.jpg|link=<
 +</gallery>
 +!! html/php
 +<ul class="gallery mw-gallery-traditional">
 +              <li class="gallerybox" style="width: 155px"><div style="width: 155px">
 +                      <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
 +                      <div class="gallerytext">
 +                      </div>
 +              </div></li>
 +</ul>
 +
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext">link=&lt;</div></li>
 +</ul>
  !! end
  
  !! test
@@@ -19439,7 -19109,7 +19450,7 @@@ parsoid=wt2html,wt2wt,html2htm
  <p><span typeof="mw:Entity">î</span><span typeof="mw:Entity">î</span></p>
  !! end
  
 -# See: http://www.w3.org/TR/html5/syntax.html#character-references
 +# See: https://www.w3.org/TR/html5/syntax.html#character-references
  # Note that U+000C (form feed) is not a valid XML character, so
  # it is banned even though allowed in HTML5.
  !! test
@@@ -20595,17 -20265,6 +20606,17 @@@ language=sr variant=sr-e
  </p>
  !! end
  
 +!! test
 +T146304: Don't break template parsing if language converter markup is in the parameter.
 +!! options
 +language=sr variant=sr-ec
 +!! wikitext
 +{{echo|-{R|foo}-}}
 +!! html/php
 +<p>foo
 +</p>
 +!! end
 +
  # FIXME: This test is currently broken in the PHP parser (bug 52661)
  !! test
  Don't break image parsing if language converter markup is in the caption.
@@@ -21266,7 -20925,7 +21277,7 @@@ Edit comment with link with more than o
  comment
  !! wikitext
  [[Main Page|Many|pipes]]
 -!! html
 +!! html/php
  <a href="/wiki/Main_Page" title="Main Page">Many|pipes</a>
  !! end
  
@@@ -21276,7 -20935,7 +21287,7 @@@ Complex edit comment with link with mor
  comment
  !! wikitext
  Created page with "<noinclude>[[Category:Requests for permissions/Bot|{{subst:#titleparts:{{subst:PAGENAME}}|1|3}}]]</noinclude> === [[User:MineoBot|]] 8=== {{Request for permissions/links|Mineo..."
 -!! html
 +!! html/php
  Created page with &quot;&lt;noinclude&gt;<a href="/index.php?title=Category:Requests_for_permissions/Bot&amp;action=edit&amp;redlink=1" class="new" title="Category:Requests for permissions/Bot (page does not exist)">{{subst:#titleparts:{{subst:PAGENAME}}|1|3}}</a>&lt;/noinclude&gt; === <a href="/index.php?title=User:MineoBot&amp;action=edit&amp;redlink=1" class="new" title="User:MineoBot (page does not exist)">User:MineoBot</a> 8=== {{Request for permissions/links|Mineo...&quot;
  !! end
  
@@@ -22077,7 -21736,7 +22088,7 @@@ Strip marker in urlencod
  {{urlencode:x<nowiki/>y|wiki}}
  {{urlencode:x<nowiki/>y|path}}
  {{urlencode:x<pre id="one">two</pre>y}}
 -!! html
 +!! html/php
  <p>xy
  xy
  xy
@@@ -22215,7 -21874,81 +22226,7 @@@ Ignore pipe between table row attribute
  
  !! end
  
 -!!test
 -Gallery override link with WikiLink (bug 34852)
 -!! wikitext
 -<gallery>
 -File:foobar.jpg|caption|alt=galleryalt|link=InterWikiLink
 -</gallery>
 -!! html
 -<ul class="gallery mw-gallery-traditional">
 -              <li class="gallerybox" style="width: 155px"><div style="width: 155px">
 -                      <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/InterWikiLink"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
 -                      <div class="gallerytext">
 -<p>caption
 -</p>
 -                      </div>
 -              </div></li>
 -</ul>
 -
 -!! end
 -
 -!!test
 -Gallery override link with absolute external link (bug 34852)
 -!! wikitext
 -<gallery>
 -File:foobar.jpg|caption|alt=galleryalt|link=http://www.example.org
 -</gallery>
 -!! html
 -<ul class="gallery mw-gallery-traditional">
 -              <li class="gallerybox" style="width: 155px"><div style="width: 155px">
 -                      <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="http://www.example.org"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
 -                      <div class="gallerytext">
 -<p>caption
 -</p>
 -                      </div>
 -              </div></li>
 -</ul>
 -
 -!! end
 -
 -!!test
 -Gallery override link with malicious javascript (bug 34852)
 -!! wikitext
 -<gallery>
 -File:foobar.jpg|caption|alt=galleryalt|link=" onclick="alert('malicious javascript code!');
 -</gallery>
 -!! html
 -<ul class="gallery mw-gallery-traditional">
 -              <li class="gallerybox" style="width: 155px"><div style="width: 155px">
 -                      <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/%22_onclick%3D%22alert(%27malicious_javascript_code!%27);"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
 -                      <div class="gallerytext">
 -<p>caption
 -</p>
 -                      </div>
 -              </div></li>
 -</ul>
 -
 -!! end
 -
 -!!test
 -Gallery with invalid title as link (bug 43964)
 -!! wikitext
 -<gallery>
 -File:foobar.jpg|link=<
 -</gallery>
 -!! html
 -<ul class="gallery mw-gallery-traditional">
 -              <li class="gallerybox" style="width: 155px"><div style="width: 155px">
 -                      <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
 -                      <div class="gallerytext">
 -                      </div>
 -              </div></li>
 -</ul>
 -
 -!! end
 -
 -!!test
 +!! test
  Language parser function
  !! wikitext
  {{#language:ar}}
@@@ -22632,20 -22365,19 +22643,20 @@@ Ref: 13. ref-tags are not SOL-transpare
  </ol>
  !!end
  
 -!!test
 +## Roundtripping fails because of nowiki'ing
 +!! test
  Ref: 14. A nested ref-tag should be emitted as plain text
 +!! options
 +parsoid=wt2html
  !! wikitext
  <ref>foo <ref>bar</ref> baz</ref>
  
  <references />
  !! html/parsoid
 -<p><span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span>
 -</p>
 -<ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'>
 -<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo &lt;ref>bar&lt;/ref> baz</span></li>
 -</ol>
 -!!end
 +<p><span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></span> baz&lt;/ref></p>
 +
 +<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">foo &lt;ref>bar</span></li></ol>
 +!! end
  
  !!test
  Ref: 15. ref-tags with identical names should get identical indexes
  foo<ol class="mw-references" typeof="mw:Extension/references" about="#mwt2" data-mw='{"name":"references","attrs":{}}'></ol>
  !! end
  
 -#### ----------------------------------------------------------------
 -#### Parsoid-only testing of Parsoid's impl of LST
 -#### Not implemented yet, see
 -#### https://www.mediawiki.org/wiki/Parsoid/HTML_based_LST
 -#### ----------------------------------------------------------------
 -
 -!! test
 -LST Sections: 1. Simple section start and end
 -!! options
 -parsoid={ "suppressErrors": true }
 -!! wikitext
 -<section begin="2011-05-16" />
 -<section end="2014-04-10 (MW 1.23wmf22)" />
 -!! html/parsoid
 -<p><meta typeof="mw:Extension/LabeledSectionTransclusion/begin" content="2011-05-16"/>
 -<meta typeof="mw:Extension/LabeledSectionTransclusion/end" content="2014-04-10 (MW 1.23wmf22)"/></p>
 -!! end
 -
  #--------- Test stripping of empty nodes in template content ----------
  !!test
  Empty LI and TR nodes should be stripped from template content
@@@ -26616,93 -26366,6 +26627,93 @@@ parsoid=html2wt,wt2w
  </table>
  !! end
  
 +!! test
 +T149209: WTS: Handle newlines in table cells properly
 +!! options
 +parsoid=html2wt
 +!! html/parsoid
 +<table>
 +<tbody>
 +<tr><td>a
 +b
 +</td><td data-parsoid='{"stx_v":"row"}'>c</td></tr>
 +<tr><td><p>x</p>
 +</td><td data-parsoid='{"stx_v":"row", "startTagSrc": "{{!}}{{!}}"}'>y</td></tr>
 +</tbody></table>
 +<table>
 +<tbody>
 +<tr><th>a
 +b
 +</th><th data-parsoid='{"stx_v":"row"}'>c</th></tr>
 +<tr><th><p>x</h>
 +</th><th data-parsoid='{"stx_v":"row"}'>y</th></tr>
 +</tbody></table>
 +!! wikitext
 +{|
 +|a
 +b
 +|c
 +|-
 +|x
 +{{!}}y
 +|}
 +{|
 +!a
 +b
 +!c
 +|-
 +!x
 +!y
 +|}
 +!! end
 +
 +!! test
 +T149209: Selser: Handle newlines in table cells properly
 +!! options
 +parsoid={
 +  "modes": ["selser"],
 +  "changes": [
 +    [ "#h1", "html", "a\nb\n" ],
 +    [ "#h2", "html", "a\nb\n" ],
 +    [ "#c1", "html", "a\nb\n" ],
 +    [ "#c2", "html", "<p>a</p>" ],
 +    [ "#c3", "html", "<p>a</p>" ]
 +  ]
 +}
 +!! wikitext
 +{|
 +! id="h1" |edit-me!!1
 +|-
 +! id="h2" |edit-me||2
 +|-
 +| id="c1" |edit-me||3
 +|-
 +| id="c2" |edit-me||4
 +|-
 +| id="c3" |edit-me||p||q||r
 +|}
 +!! wikitext/edited
 +{|
 +! id="h1" |a
 +b
 +!1
 +|-
 +! id="h2" |a
 +b
 +!2
 +|-
 +| id="c1" |a
 +b
 +|3
 +|-
 +| id="c2" |a
 +|4
 +|-
 +| id="c3" |a
 +|p||q||r
 +|}
 +!! end
 +
  !! test
  HTML id attribute with Parsoid-like element ids should not be serialized to wikitext
  !! options