Protect language converter markup in the preprocessor (take 2).
authorC. Scott Ananian <cscott@cscott.net>
Thu, 19 Jan 2017 19:58:05 +0000 (14:58 -0500)
committerReedy <reedy@wikimedia.org>
Tue, 23 May 2017 14:43:49 +0000 (15:43 +0100)
commit186a182a150f20475f0887cbc261d9be01dbfd98
treeaf33749287184af6a8b6d203cf6da804c84b8aaf
parent1928a85867dcbdb035d2cb2432efb91353826fba
Protect language converter markup in the preprocessor (take 2).

This revises 28774022769d2273be16c6c6e1cca710a1fd97ef, which was
reverted in master due to unexpected issues with `-{{...}} ` markup
on translatewiki and enwiki.  Test cases are added to ensure that this
is parsed as a template, not as language converter markup.

https://www.mediawiki.org/wiki/Preprocessor_ABNF is the canonical
documentation for the preprocessor; this will be updated after this
patch is merged.  The basic principles described in that page are
maintained in this patch:

* Rightmost opening structure has precedence: `-{{` is parsed as a
dash followed by template opening.

* `{{{` has precedence over `{{` and `-{`: `-{{{{` is parsed as
`-{` `{{{` since we first grab the rightmost `{{{`.

A bunch of test cases were added to verify the "ideal precedence"
order described on that wiki page.

This patch introduced some minor incompatibilities in existing
markup, in particular with chemical formulae in templates.
Fixes for these are being tracked at
https://www.mediawiki.org/wiki/Parsoid/Language_conversion/Preprocessor_fixups

Bug: T146304
Bug: T153761
Change-Id: I2f0c186c75e392c95e1a3d89266cae2586349150
RELEASE-NOTES-1.30
includes/parser/Preprocessor.php
includes/parser/Preprocessor_DOM.php
includes/parser/Preprocessor_Hash.php
tests/parser/parserTests.txt