Page MenuHomePhabricator

DOM-Like Preprocessor Automatically Expands First Argument
Closed, DeclinedPublic

Description

Author: david.sledge

Description:
When I create parser functions that accept DOM-style arguments, the first argument is already expanded. Example: If I do a var_dump() of args[0] in the [[meta:Help:ParserFunctions]]' ExtParserFunctions::ifObj() method, it shows that the argument is a string. The other arguments are fine though. They show up as PPNode_DOM objects.


Version: 1.12.x
Severity: enhancement
OS: Windows XP
Platform: PC

Details

Reference
bz12842

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 10:01 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz12842.
bzimport added a subscriber: Unknown Object (MLST).

Right, that's how it is, and that's how it will stay.

david.sledge wrote:

Ah, so it's that way by design. Okay. The work-around is easy enough, I'll just make my parser function not use the first argument.

You should call trim($frame->expand($arg)) on each argument regardless of whether it is a string or a PPNode. You should not be accessing the underlying tree.

david.sledge wrote:

I'm using both PPFrame::expand() and PPNode_DOM::splitArg() for the "param=value" pairs. The issue is that I don't want the first arg to be expanded automatically—in some cases not at all—depending on the other "param=value" arguments.

There's also an issue with timing; when the argument gets expanded. For instance, with [[mw:Extension:Cite/Cite.php]] the following:

<ref>E. Miller, The Sun, (New York: Academic Press, 2005), 23-5.</ref>

<references/>

Gives a very different result than:

<references/>

<ref>E. Miller, The Sun, (New York: Academic Press, 2005), 23-5.</ref>

If my extension is going to interact with other extensions where timing is important, I want to make sure the argument gets expanded when its supposed to, and not prematurely.

But as I said, this is minor since I have a workaround. In fact, since the current behavior is intended, this isn't a bug, but an enhancement request.