I tend to do a fair amount of wiki work these days. Whether it’s scripting against the mediawiki api, or just manually editing pages … you tend pick up little tips here and there. One such gem I’ve been using for a while is to get mediawiki templates to expand when used inside preformatted <pre>
tags.
Why bother? Well, when writing test cases, or related pages, I frequently provide command-line samples or output. I like to ensure that the output remains relevant over time. Even more, I dislike having to frequently update a page release after release to ensure the commands or output are still relevant. For some common QA-related <pre>
tag examples, checkout the following links …
- How to update AutoQA repoinfo.conf – provide copy and paste-able configuration files used whenever a Fedora release branches or reaches end-of-life.
- QA:SOP Installation Test – Provides a sample command-line script to count test day participants.
- QA:Testcase Anaconda save traceback to bugzilla – Specify boot arguments for various installer traceback tests
Okay, you get the idea. The fun part is hidden in the first example. What if you want to take advantage of some awesome wiki templates, such as {{FedoraVersion}}
? If you try that … the <pre>
tags will show you just that … pre-formatted text as shown below.
mock -r fedora-{{FedoraVersion||previous}}-x86_64 --init
If you like puzzles, and are hell-bent on having templates expansion inside <pre>
tags, let me save you a tremendous waste of time searching for the correct solution. … To expand mediawiki templates inside <pre>
tags … you can use a miscellaneous parser function. The function is a bit strange, but works as follows …
{{#tag:pre| mock -r fedora-{{FedoraVersion||previous}}-x86_64 --init }}
The above syntax will produce the following wiki output …
mock -r fedora-14-x86_64 --init
All that to emit two characters! I know, but I’m lazy and this solution helps me to never update that particular wiki page ever again. It will always point to the proper release thanks to Template:FedoraVersion. Also, thanks to a post from Das Gurke on the Customizing-MediaWiki mwusers forum for pointing out the right answer.
If you have other creative uses for the #tag:tagname
parser function, please share!