My motivation is to automate page creation and semantic annotation by using html-forms. One use case would be to automatically annotate creation relationships between pages. To do so I implemented a tag hook which creates the forms.
My problem: I want to use this extension tag inside templates and also use template parameters.
Contents inside an extension tag are not parsed but treated separately.
<tag>...contents...</tag>
Therefore template variables inside a tag like the following are not replaced.
<tag>...{{parameter}}...</tag>
I already figured out that extension tag hooks are treated within the function split() in Parser.php.
But how can I get the parser to parse the contents of the tag before calling the according extension callback function?
Function recursiveTagParse() seems to be an option but I can't get it to work.
Or is it necessary to work with an extension function hook instead of a tag hook?
Any suggestions? Or indications where I could find help? Thanks in advance. _______________________________________________________________ SMS schreiben mit WEB.DE FreeMail - einfach, schnell und kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
Hi Nils,
Two things:
1) You're correct that extension tags don't expand template parameters. What you'd want is what's called a parser function [1] [2].
2) You may want to have a look at Semantic Forms - there's a chance it may already do what you want (or perhaps at least a portion thereof) [3].
[1] Explanation of Parser Functions: http://meta.wikimedia.org/wiki/Help:Parser_function [2] Some examples: http://www.mediawiki.org/wiki/Category:Parser_function_extensions [3] Semantic Forms extension: http://www.mediawiki.org/wiki/Extension:Semantic_Forms
-- Jim R. Wilson (jimbojw)
On 6/6/07, Nils Oppermann nilito@web.de wrote:
My motivation is to automate page creation and semantic annotation by using html-forms. One use case would be to automatically annotate creation relationships between pages. To do so I implemented a tag hook which creates the forms.
My problem: I want to use this extension tag inside templates and also use template parameters.
Contents inside an extension tag are not parsed but treated separately.
<tag>...contents...</tag>
Therefore template variables inside a tag like the following are not replaced.
<tag>...{{parameter}}...</tag>
I already figured out that extension tag hooks are treated within the function split() in Parser.php.
But how can I get the parser to parse the contents of the tag before calling the according extension callback function?
Function recursiveTagParse() seems to be an option but I can't get it to work.
Or is it necessary to work with an extension function hook instead of a tag hook?
Any suggestions? Or indications where I could find help? Thanks in advance. _______________________________________________________________ SMS schreiben mit WEB.DE FreeMail - einfach, schnell und kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Jim Wilson wrote:
Hi Nils,
Two things:
- You're correct that extension tags don't expand template parameters.
What you'd want is what's called a parser function [1] [2].
- You may want to have a look at Semantic Forms - there's a chance it may
already do what you want (or perhaps at least a portion thereof) [3].
Or you could parse the content before doing anything with the <tag> content. One of the hook parameters is the parser you should use to replace templates. See mediawiki-l archives.
Or you could parse the content before doing anything with the <tag> content. One of the hook parameters is the parser you should use to replace templates.
I think he's talking about params like {{{1}}}, not processing a transclusion request {{like this}}. But even so, a parser function is a more elegant solution to either of these as it happens "in line" with all the benefits of being integrated into the parser during that earlier pass.
Extension tags happen "outside" template processing, so mixing the two is kind of a strange thing in practice.
-- Jim
On 6/6/07, Platonides Platonides@gmail.com wrote:
Jim Wilson wrote:
Hi Nils,
Two things:
- You're correct that extension tags don't expand template parameters.
What you'd want is what's called a parser function [1] [2].
- You may want to have a look at Semantic Forms - there's a chance it
may
already do what you want (or perhaps at least a portion thereof) [3].
Or you could parse the content before doing anything with the <tag> content. One of the hook parameters is the parser you should use to replace templates. See mediawiki-l archives.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Wed, 06 Jun 2007 14:36:19 -0500, Jim Wilson wrote:
Or you could parse the content before doing anything with the <tag> content. One of the hook parameters is the parser you should use to replace templates.
I think he's talking about params like {{{1}}}, not processing a transclusion request {{like this}}. But even so, a parser function is a more elegant solution to either of these as it happens "in line" with all the benefits of being integrated into the parser during that earlier pass.
Extension tags happen "outside" template processing, so mixing the two is kind of a strange thing in practice.
Extension tags are supposed to return HTML, and don't necessarily have wiki input. If they have wiki text, they can use $parser->recursiveTagParse() to parse it.
If you just want to substitute parameters in a tag function, you'd need to pass arguments to the tag, then replace them in the text i.e.
<tag param=val> text {{{param}}} </tag>
function MyTag ($in, $params, $parser) { $text = $parser->replaceVariables($in,$params); ...
Which wouldn't parse, just replace the args with a (techincally private) parser method.
To parse arguments from a parser function, you'd only need to return an array of arguments and the right combination of flags to parse them.
-- Jim
On 6/6/07, Platonides Platonides@gmail.com wrote:
Parser functions don't substitute template arguments either. To do that
you'd have to get the argument array from the call, call $parser->createAssocArgs($args) to parse it, and return the result
Jim Wilson wrote:
Hi Nils,
Two things:
- You're correct that extension tags don't expand template parameters.
What you'd want is what's called a parser function [1] [2].
- You may want to have a look at Semantic Forms - there's a chance it
may
already do what you want (or perhaps at least a portion thereof) [3].
Or you could parse the content before doing anything with the <tag> content. One of the hook parameters is the parser you should use to replace templates. See mediawiki-l archives.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Hi Steve,
I think I see what you're getting at, however I'm not sure that it addresses the original request:
But how can I get the parser to parse the contents of the tag before calling the according extension callback function?
It would seem to me that what he's looking for is <tag>{{{param}}}</tag> to execute in such a way that {{{param}}} is translated _before_ it even gets to the tag's implementation method.
For example, say you have Template:Whatever, which contains:
<tag>{{{1}}}</tag>
And you call it like so:
{{Whatever|something}}
The internals of <tag> will always receive "{{{1}}}", not "something" - which I believe is Nils original complaint.
So although you're correct that it's possible to grab the Parser reference and force it to parse the internal text as was provided to the tag, this doesn't account for (what I believe to be) the original question.
Also, (not sure who said the following):
Parser functions don't substitute template arguments either. To do that you'd have to get the argument array from the call, call $parser->createAssocArgs($args) to parse it, and return the result
Well, ok. Technically speaking, the parser function itself is not "parsing" the {{{params}}}. However, the Parser class does translate these params to the appropriate string values prior to executing a parser function - which achieves what Nils was originally aiming to do.
-- Jim
On 6/7/07, Steve Sanbeg ssanbeg@ask.com wrote:
On Wed, 06 Jun 2007 14:36:19 -0500, Jim Wilson wrote:
Or you could parse the content before doing anything with the <tag> content. One of the hook parameters is the parser you should use to replace templates.
I think he's talking about params like {{{1}}}, not processing a transclusion request {{like this}}. But even so, a parser function is a more elegant solution to either of these as it happens "in line" with
all
the benefits of being integrated into the parser during that earlier
pass.
Extension tags happen "outside" template processing, so mixing the two
is
kind of a strange thing in practice.
Extension tags are supposed to return HTML, and don't necessarily have wiki input. If they have wiki text, they can use $parser->recursiveTagParse() to parse it.
If you just want to substitute parameters in a tag function, you'd need to pass arguments to the tag, then replace them in the text i.e.
<tag param=val> text {{{param}}} </tag>
function MyTag ($in, $params, $parser) { $text = $parser->replaceVariables($in,$params); ...
Which wouldn't parse, just replace the args with a (techincally private) parser method.
To parse arguments from a parser function, you'd only need to return an array of arguments and the right combination of flags to parse them.
-- Jim
On 6/6/07, Platonides Platonides@gmail.com wrote:
Parser functions don't substitute template arguments either. To do that
you'd have to get the argument array from the call, call $parser->createAssocArgs($args) to parse it, and return the result
Jim Wilson wrote:
Hi Nils,
Two things:
- You're correct that extension tags don't expand template
parameters.
What you'd want is what's called a parser function [1] [2].
- You may want to have a look at Semantic Forms - there's a chance
it
may
already do what you want (or perhaps at least a portion thereof) [3].
Or you could parse the content before doing anything with the <tag> content. One of the hook parameters is the parser you should use to replace templates. See mediawiki-l archives.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Thu, 07 Jun 2007 11:21:52 -0500, Jim Wilson wrote:
Hi Steve,
I think I see what you're getting at, however I'm not sure that it addresses the original request:
I think my example is closer to what he's trying to do, to get the extension to do recursive parsing. But on rereading it, yours is probably closer to what he really wants; if it's just a matter of inheriting parameters from the template, they can just be passed into a parser function.
wikitech-l@lists.wikimedia.org