Working With MediaWiki
XML tags, parameters to a tag function can be either a content string, placed between the start and end tag, or attributes placed within the tag. This means that tag functions can have only one unnamed parameter, all the rest must be named.
How are multiple parameters passed in to parser functions? They’re separated using pipes. Here is a call to a real-life parser function, #sub, that displays a substring of a string, starting at a certain location and with a certain length:
{{#sub:This is a string.|0|4}}
In this case, the #sub function takes the first parameter, the sentence, and returns the substring starting at character 0, with length 4. The resulting displayed string would be "This".
The values passed in to #sub, and to all other parser functions, are separated by pipes.
But what about values that actually contain pipes — how can they be passed in without confusing the function? There is a standard solution to this that’s somewhat of a hack: a template called "!" is defined in the wiki, which contains simply the string "|". You could then have a call like:
{{#sub:This is{{!}}a string with a pipe.|0|4}}
When the parameters are evaluated, the "{{!}}" will change to a "|". (The result will simply be “This”, so this is a contrived example, but hopefully you get the idea.)
That brings us to the last difference between parser and tag functions, although it’s a difference that’s becoming less of an issue. For most of the history of MediaWiki, the big weakness of tag functions was that inputs passed in to them were not first parsed.
To take an example, let’s say that there are parser and tag functions named ’spacify’, that put spaces in between all the characters in a string (this is a hypothetical example — there’s probably no reason why anyone would ever want such a thing). The following calls will both display the string "c b a":
{{#spacify:{{#reverse:abc}}}}
{{#spacify:abc}}
The following calls, in most cases, would fail, however:
{{#reverse:abc}}
abc
That’s because the string that would be “spacified” would be the literal string ’{{#reverse:abc}}’ or ’abc’. In other words, tag functions don’t allow their inputs to be parsed -- a weakness that has made them unusable for many situations.
Two features of MediaWiki, though, can help to reduce this difference between tag and parser functions. The first is the#tag function, which is part of core MediaWiki. #tag lets tag functions be called as parser functions, so that their arguments can be parsed. So if only were defined and not #spacify, you could call the following, and it would, in fact, display "c b a":
{{#tag:spacify|abc}}
The second is that, since version 1.16 of MediaWiki, tag functions can in fact be defined so that they parse their own parameters, just as parser functions do. As of this writing, few tag functions have been defined with this behavior, but hopefully this will become more standard in the future.
Besides #tag, there are a variety of other parser functions defined in core MediaWiki. There are also a few tags. And some parser functions are called without the ’#’ character at the beginning — for the most part, this is based on when that parser function was added; older functions do not have it. Here are some of the important parser functions defined in MediaWiki:
localurl
,
fullurl
,
canonicalurl
— variants that produce a URL based on a page name and a query string
lc
,
lcfirst
,
uc
,
ucfirst
— lower-casing and upper-casing functions
There are a variety of other pre-defined parser functions; you can see the full list here:
https://www.mediawiki.org/wiki/Help:Magic_words#Parser_functions
There are also some tag functions, including , and . and (and ) were already covered here . is a very useful tag, that prevents MediaWiki formatting from being applied to text. For instance, to display the following on a wiki page:
The way to do italics is with ''double apostrophes''.
You could use this wikitext:
The way to do
''
italics
''
is with
''
double apostrophes
''
.
5 Content organization
Categories
Categories are MediaWiki’s basic method of organizing information. On wikis that don’t use Semantic MediaWiki, categories are really the only way to tag information about
Weitere Kostenlose Bücher