Hello,
I'm attempting to set up an instance of MediaWiki (version 1.4.x) for a community site, and I was trying to implement some custom formatting. I will describe a little more of what I tried further down the mail, but I have one particular question, so I'll get that out of the way first:
I want to use an Extension within a template (details of why below...), and, in particular, to pass in template parameters to the extension. So the template call is
{{myTemplate|argument1}}
with the code within the template looking something like
<myFirstExt>{{{1}}}</myFirstExt>
but the problem is that I get the string '{{{1}}}' passed in to the extension, rather that the value entered in the template call, 'argument1' in the exampel.
Sooo, my question is as follows: is there any way to get the value of the argument into the extension?
To give a little bit of background, basically I want to define a few extensions, but, to get the formatting that I want, each extension needs to be aware of what extensions have already been used. I had kinda assumed that each extension would be invoked in the order in which they were used in the body of the entry, but it appears that all instances of each type of extension is processed in turn (I assume because it uses preg_replace_callback, but I haven't checked that). So for example, in the following code
== My first heading == Introductory text Introductory text Introductory text Introductory text
<myFirstExt>first lot of stuff</myFirstExt>
<mySecondExt>more stuff</mySecondExt>
=== sub-heading ===
<myFirstExt>some sub-stuff</myFirstExt>
the code processing the second <myFirstExt> block is invoked before the code processing the <mySecondExt> block. So an alternative question could be, is there any way of getting extensions within a document processed in order? But I guessed that that was harder.
To get around this, I wanted to try putting Template aliases in the actual document, with the custom extension code invoked in the Template definitions. This seemed to get round the ordering, but then I couldn't do anything with the input parameters, which led to my first question.
If it's not straight-forward to pass in template parameters to the extension, would anyone be able to give me some pointers on where I could try modifying the underlying code to get it to do so? It seems to me that this could be a useful thing for people to be able to do, but that may just be because of my relative inexperience in this stuff, so all feedback would be appreciated.
As a matter of interest, and from a novice's point of view, I found both of these behaviours counter-intuitive, but I don't know whether that's just inexperience with PHP and MediaWiki.
Thanks very much in advance for your help. Yours,
Stephen.
Stephen Betts wrote:
<myFirstExt>{{{1}}}</myFirstExt>
but the problem is that I get the string '{{{1}}}' passed in to the extension, rather that the value entered in the template call, 'argument1' in the exampel.
Sooo, my question is as follows: is there any way to get the value of the argument into the extension?
You might be able to call back into the parser to get it, but I'm not really sure. Extensions are taken out as one of the first stages of wiki processing, then their HTML output is inserted as one of the later stages.
To give a little bit of background, basically I want to define a few extensions, but, to get the formatting that I want, each extension needs to be aware of what extensions have already been used.
Parser hook extensions are assumed to follow these rules:
1) An extension should always return the same output for the same input.
2) The input consists entirely of the text inside the tag, and the attribute parameters on the tag.
Thus it should not matter: * which page the extension is used in * what other content is on that page * which order hooks are run in * how output is cached etc
If you stray outside that design you're heading into uncharted territory and surprises should not be... surprising. ;)
Some limited exceptions to using outside info (user preferences, state of other pages' category memberships) may be made if you're careful about cache management. You should never, however, make assumptions about order of execution or other content on the page. No guarantees are made there and changes to the parser probably will change that in the future.
-- brion vibber (brion @ pobox.com)
On 7/11/05, Brion Vibber brion@pobox.com wrote:
Stephen Betts wrote:
<myFirstExt>{{{1}}}</myFirstExt>
but the problem is that I get the string '{{{1}}}' passed in to the extension, rather that the value entered in the template call, 'argument1' in the exampel.
Sooo, my question is as follows: is there any way to get the value of the argument into the extension?
You might be able to call back into the parser to get it, but I'm not really sure. Extensions are taken out as one of the first stages of wiki processing, then their HTML output is inserted as one of the later stages.
Ah, okay. I may try digging around a little there.
To give a little bit of background, basically I want to define a few extensions, but, to get the formatting that I want, each extension needs to be aware of what extensions have already been used.
Parser hook extensions are assumed to follow these rules:
An extension should always return the same output for the same input.
The input consists entirely of the text inside the tag, and the
attribute parameters on the tag.
Thus it should not matter:
- which page the extension is used in
- what other content is on that page
- which order hooks are run in
- how output is cached
etc
If you stray outside that design you're heading into uncharted territory and surprises should not be... surprising. ;)
I consider myself warned 8-)
To be honest, I think I will keep pursuing this line for the minute as it seems the most expedient way of getting what I want (essentially nested custom elements, but without nesting tags - quite similar to how the different levels of headings, ==, ===, etc., work now), but will try to be very rigorous in my testing before upgrading.
Thanks very much for the clear and prompt response, Brion. Yours,
Stephen.
wikitech-l@lists.wikimedia.org