Page MenuHomePhabricator

VisualEditor: Transclusions editor should support parser functions and variables
Open, LowPublic

Description

Parser function syntax is generally {{#function_name : expr1 | expr2 | expr3 | ...}}

Currently VE sees this as a template with name "#function_name : expr1" and arguments "1 = expr2", "2 = expr3", etc. This makes it impossible to edit expr1 in VE.

Same for parserfunctions like urlencode and template messages. The transclusions editor should be able to handle them, preferably by invisibly detecting them and failing that with a special, user-selected mode. Until we can, we should show an explanatory message when the user attempts to add one.

See also:
T54607: TemplateData: Implement hook for extensions to document magic words and parser functions

Details

Reference
bz50855

Event Timeline

• bzimport raised the priority of this task from to High.Nov 22 2014, 1:51 AM
• bzimport set Reference to bz50855.

Yes, we need a special form of editing transclusions which aren't templates; I can't recall whether Parsoid gives us sufficient information to recognise these as different except for introspection.

Many of the parser functions are rarely used in the main namespace (#if, ...), but some of them are really important even in the main namespace. For example {{formatnum:...}} is probably used a lot there.

Jdforrester-WMF lowered the priority of this task from High to Medium.Jan 9 2015, 10:55 PM

If Parsoid doesn't automatically tell VE whether something is a template or not, could it not be done by looking at the format of the string (e.g. {{# is never a template) or comparing it to a list of parser functions?

nshahquinn-wmf renamed this task from VisualEditor: Transclusions editor should have a special mode for Parser Function and Magic Word calls to VisualEditor: Transclusions editor should support parser functions and variables.Jul 23 2015, 11:00 PM
nshahquinn-wmf lowered the priority of this task from Medium to Low.
nshahquinn-wmf updated the task description. (Show Details)
nshahquinn-wmf added a project: Epic.
nshahquinn-wmf set Security to None.

So yeah. Matma Rex has merged T249860 with this task. Also, I will add details about this task on Wikipedia:VisualEditor.

I can't recall whether Parsoid gives us sufficient information to recognise these as different except for introspection.

Trying the wikitext {{#isbn:963-12-3456-9|foo|bar=baz}} in VisualEditor (not Parsoid read view). The second and third parameters are discarded by the parser function, but they help understanding the data flow between wikitext and Parsoid HTML.

The legacy parser (wikitext editor preview) emits

<a href="/wiki/Special:BookSources/9631234569" class="internal mw-magiclink-isbn">ISBN 963-12-3456-9</a>

while the VisualEditor DOM contains

<a href="https://en.wikipedia.org/wiki/Special:BookSources/9631234569" class="internal mw-magiclink-isbn ve-ce-leafNode ve-ce-focusableNode ve-ce-mwTransclusionNode" typeof="mw:Transclusion" about="#mwt5" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;#isbn:963-12-3456-9&quot;,&quot;function&quot;:&quot;isbn&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo&quot;},&quot;2&quot;:{&quot;wt&quot;:&quot;bar=baz&quot;}},&quot;i&quot;:0}}]}" id="mwGQ" contenteditable="false">ISBN 963-12-3456-9</a>

The data-mw attribute HTML-decoded:

{"parts":[{"template":{"target":{"wt":"#isbn:963-12-3456-9","function":"isbn"},"params":{"1":{"wt":"foo"},"2":{"wt":"bar=baz"}},"i":0}}]}

I guess "function":"isbn" means that Parsoid recognizes this as a parser function; however, it doesn’t handle the parser function parameters correctly, with the second parameter showing up as "1" in the params object and the first parameter being discarded from there. On the other hand, it correctly recognizes that bar=baz is not a named parameter, since parser functions don’t have named parameters (even if #tag and #switch emulate something similar). So there is Parsoid work to be done here – should this task be tagged Parsoid, or should a subtask be created?