Page MenuHomePhabricator

Template parsing is incomplete and inconsistent
Closed, ResolvedPublic

Assigned To
None
Authored By
bzimport
Sep 21 2005, 12:15 PM
Referenced Files
F2356: nested-templates.patch
Nov 21 2014, 8:51 PM
F2357: Parser.php.diff
Nov 21 2014, 8:51 PM
F2355: testcase.txt
Nov 21 2014, 8:51 PM

Description

Author: alarm

Description:
Currently template and template argument parsing is incomplete and inconsistent - based on regular expresions and
workarounds (for example, workaround not to treat '|' in links as parameter separator). This may cause problems, some known
problems are:

  • template cannot be included as parameter for another template ( {{a|{{b}}|c}} )
  • if any argument value is ommioted, prepared template is ugly if it uses another template passing some arguments to that

template (having template A which uses template B - {{B|a={{{a}}}|b={{{b}}}|c=c}} and not passing value for 'a' will be treat {{B|a=
{{{a}} as call to another template and '}|b={{{b}}}|c=c}}' will be left unnparsed)


Version: unspecified
Severity: normal

Details

Reference
bz3526

Event Timeline

bzimport raised the priority of this task from to High.Nov 21 2014, 8:51 PM
bzimport set Reference to bz3526.
bzimport added a subscriber: Unknown Object (MLST).

alarm wrote:

some testcases (using parserTest format)

These tests extends template automated tests, few tests are failing due to bug

Attached:

alarm wrote:

A generic solution

This patch replaces template parsing with generic function which parses all
parentheses pairs in same way and that is done by correctly parsing levels
(first inner parentheses are parsed). So any parentheses combination (for
example, {{a|a|{{b|b|[[c|{{{c}}}]]}}}} )is parsed consistently. Patch also
includes default values for arguments (as having generic parsing makes it very
simple and consistent), but if that may cause any doubts, this can be made
optional or completely removed (it is not a main part of a patch - just a line
or two).

After applying a patch all old and newly proposed tests run successfully.

attachment Parser.php.diff ignored as obsolete

robchur wrote:

You're going to put a whopping strain on the servers of a large wiki if that's
used on a lot of pages.

alarm wrote:

I cannot tell for sure, but I don't think this should be any slower than 3 or 4 regex replace calls + array manipulation (to
workaround link '|' problem). Also, isn't parsing output cached? Anyway, I may be wrong.

robchur wrote:

I meant the calling of templates as parameters of other templates; one could end
up with a series of circular references. In addition, I belive certain template
outputs are not cached. I'm talking about the load on the mySQL servers here...

alarm wrote:

Circular references can already be created using templates without any parameters and as I know there is a solution for
that, so I don't think this patch will introduce any new problems. Still, I can be wrong on ghis.

pierstitus wrote:

Patch (on1.5rc4) to make templates with templates as arguments work

A simple solution that solves the templates as arguments bug, eg.
{{note|{{3x|blah}}}}

attachment nested-templates.patch ignored as obsolete

pierstitus wrote:

Patch (on1.5rc4) to make templates with templates as arguments work, tweaked a bit

A simple solution that solves the templates as arguments bug, eg.
{{note|{{3x|blah}}}}

Attached:

alarm wrote:

Optimized generic solution

Attached:

mediazilla wrote:

Would this bug be the reason I get the following parsing glitch in my template?

http://wqoq.com/wiki/Template:Bad_parse

I get this glitch in 1.5.0 and 1.5.2.

mediazilla wrote:

Nevermind, I'm just going to go with a cvs revision. That obviously has the fix in it.

alarm wrote:

More examples of template usage after the fix was applied - http://meta.wikimedia.org/wiki/Extended_template_syntax