The string functions in the MediaWiki model?

综合技术 2017-12-31

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.

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.

您可能感兴趣的

webassembly 在 flv 编解码中的实战 pc端直播平台的播放器大部分已FLV 直播流格式为主。FLV 直播流可以嵌套在swf文件当中,可以用flash播放。 前几个月,我们刚刚完成了对直播播放器的重构,引入了现有的bilibili开源的flv.js,接入了flv h5播放器。向下兼容了flash播放器。 h5播放器的原理...
微信小程序wx.request的简单封装 这些天团队里开始做小程序开发了,之前没做过,都是第一次,第一次的感觉大家都懂的。周末看了一下小程序项目的代码,在网络请求上发现了一些小问题,最终没忍住想了点办法把request封装了一下。下面来看看吧。 看项目代码时发现了下面几点问题: 网络请求都写在Page里,每个请求都要重...
Algorithm to get all possible sets This question already has an answer here: JavaScript - Generating combinations from n arrays with m elements 6 answers Input: ,...
JavaScript: Removing a property from an object imm... Say you have a JavaScript object like this: const user = { firstName: 'Bramus', lastName: 'Van Damme', twitter: 'bramus', c...
用js优美的写各种斐波那契数列 fibonacci 在阅读BuckleScript官方文档时,发现一个斐波那契的code让我眼前一亮,实现思路是我从未想到过的。犹记得初学编程时斐波那契数列让我理解的递归的威力,现又让我从新认识了递归。这里我会总结我所有价值的斐波那契数列实现。如后续有新的认知会在文章末尾处...