Page MenuHomePhabricator

Passing template parameters to parser hook extensions
Closed, DuplicatePublic


Author: avarab

There should be some way to pass template parameters to parser hook extensions,
Tim Starling changed some stuff in rev 1.489 of Parser.php to allow for this but
reverted it in rev 1.498 because of some breakage with it.

There are two ways to solve this, one would be to add a flag to
Parser::setHook() that indicates that the extension being hooked returns
wikitext, it could then return stuff like "[[{{{foo}}}]]" and have the Parser
DWIM, the other way would be to bring something like the old hack back, the
former would work for most cases but it would also be nice to access template
parameters in hooks that don't return wikitext.

Relevant diffs:

Adding support

cvs diff -u -r 1.488 -r 1.489 Parser.php

Removing support

cvs diff -u -r 1.497 -r 1.498 Parser.php

Version: 1.6.x
Severity: normal



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:02 PM
bzimport set Reference to bz4529.
bzimport added a subscriber: Unknown Object (MLST).

avarab wrote:

*** Bug 4585 has been marked as a duplicate of this bug. ***

dossy wrote:

I have a minimal change to MediaWiki 1.5.0 that lets me at least access the
template args from my extension (which is all I currently need). It's a
three-line change to includes/Parser.php:


< var $mOptions, $mTitle, $mOutputType,

var $mOptions, $mTitle, $mOutputType, $mTemplateArgs,


$this->mTemplateArgs = array();


  1. Store a copy of template args so extensions

can use them.

$this->mTemplateArgs = $assocArgs;

In my extension, I can now do:

global $wgParser;
$text = $wgParser->replaceVariables($input, $wgParser->mTemplateArgs);

Any reason not to do this?

dossy wrote:

minimal patch to expose template args for use in extension callbacks, etc.

With this patch, I can now do this from an extension:

global $wgParser;
$text = $wgParser->replaceVariables($input, $wgParser->mTemplateArgs);


emmiller wrote:

Fix for 1.7-svn

Same changes as #1423, but for 1.7-svn.


emmiller wrote:

*** This bug has been marked as a duplicate of 2257 ***