Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String functions in MediaWiki template?

One of the more interesting "programming languages" I've been stuck with lately is MediaWiki templates. You can do a surprising amount of stuff with the limited syntax they give you, but recently I've run into a problem that stumps me: using string functions on template arguments. What I'd like to do (somewhat simplified) is:

{{myTemp|a=1,2,3,4}}

then write a template that can do some sort of magic like

You told me _a_ starts with {{#split:{{{a}}}, ",", 0}}

At present, I can do this with embedded javascript, capturing regexp matching, and document.write, but a) it's huge, b) it's hacky, and c) it will break horribly if anybody turns off javascript. (Note that "split" is merely an example; concatenate, capturing-regexp matching, etc., would be even better)

I realize the right solution is to have the caller invoke the template with separate arguments, but for various reasons that would be hard in my particular case. If it's simply not possible, I guess that's the answer, but if there is some way to have templates do string-manipulation on the back end, that'd be great.

like image 775
Coderer Avatar asked Aug 12 '10 19:08

Coderer


1 Answers

Concatenate is easy. To assign x = y concat z

{{#vardefine:x|{{{y}}}{{{z}}}}}

And, to add to Mark's answer, there are also RegexParserFunctions

Ceterum censeo: MediaWiki will never be not hacky.

like image 98
relet Avatar answered Sep 18 '22 00:09

relet