Bücher online kostenlos Kostenlos Online Lesen
Working With MediaWiki

Working With MediaWiki

Titel: Working With MediaWiki Kostenlos Bücher Online Lesen
Autoren: Yaron Koren
Vom Netzwerk:
with the downloadable version of MediaWiki. But why, given that it’s so popular, isn’t its functionality directly a part of core MediaWiki? That’s because ParserFunctions is a bit of a hack. Functions like #if, for all their helpfulness, can be cumbersome to use, and you only need to look at the code for some of the templates in Wikipedia to see how such functions can quickly turn wikitext into an unreadable mess of curly braces. Here’s a small example, from the English Wikipedia’s “Infobox settlement” template:
{{#ifeq:{{{parts_style|}}} | para | {{{parts|}}} {{#if:{{both | {{{parts|}}} | {{{p1|}}}}} | : |}} {{#if:{{{p1|}}} | {{{p1}}} {{#if:{{{p2|}}} |, {{{p2}}} {{#if:{{{p3|}}} |, {{{p3}}} {{#if:{{{p4|}}} |, {{{p4}}} {{#if:{{{p5|}}} |,
    It goes on like that for a while.
    There has long been a discussion of including within MediaWiki true scripting functionality, including "if-then" statements, "for" loops, and the like, which would be both more powerful and more elegant than the current approach. Thankfully, this is finally happening: in early 2012, the decision was made to use the language Luato be MediaWiki’s scripting language of choice, and there is currently a project underway to allow for the creation of Lua-based “modules”, that would work in the same way as templates, but would be more programmatic. The capability is coming via an extension called Scribunto, which is still in progress:
https://www.mediawiki.org/wiki/Extension:Scribunto
    So this idea may become a reality fairly soon. And if/when Lua-based modules start to get widespread use, the importance of the ParserFunctions extension could diminish considerably.
    Scribunto is intended to be a powerful framework, by the way: though its default scripting language will be Lua, it’s designed to allow other languages as well, such as JavaScript (server-side, not client-side).
    Nevertheless, currently we have ParserFunctions. Below is the listing of the original functions it defines, along with a description of each.
#expr — displays the result of a mathematical or logical expression.
    Example:
{{#expr:2 + 3}}
#if — displays different strings depending on whether some value is blank.
    Example:
    {{#if:{{{height|}}}|The height is {{{height|}}}.|No height entered.}}
#ifeq — displays different strings depending on whether two values are equal.
#iferror — displays different strings depending on whether a call to another such function returned an error.
#ifexpr — displays different strings depending on whether a mathematical expression is correct.
#ifexist — displays different strings depending on whether a given page exists.
#rel2abs — displays a page name, based on a directory-like view of subpages.
#switch — displays different strings depending on some specific value (there can be multiple options).
    Example:
    {{#switch: {{{Season|}}} | Summer = How nice, it’s summer! | Winter = Brr, it’s winter! | It’s some other season! }}
#time — displays a specific time, in a specified format.
#timel — displays the current local time, in a specified format.
#titleparts — displays one or more parts of a page name, based on splitting up the page by slashes.
    Example:
{{#titleparts: A/B/C/D/E | 2 | 3}}
    (returns “C/D” — call returns 2 segments, starting at segment #3)
    And here are the ParserFunctions functions that came from StringFunctions:
#len — shows the length of a given string.
    Example:
    {{#ifexpr: {{len: {{{Zip code|}}} }} = 5 | The zip code is {{{Zip code|}}}. | The zip code ({{{Zip code|}}}) should be 5 characters long.}}
#pos — finds the numerical character position of one string within another.
#rpos — similar, but finds the last occurrence of a string.
#sub — shows the substring of a string, given a start and end number.
#pad — pads out a string to a certain length, using a character or other string as padding.
#replace — shows a string that has had a substring replaced with another string.
#explode — shows a substring, based on splitting up a string by a delimiter.
    Example:
    The third name in your list is {{#explode:{{{List of names|}}}|,|3}}.
urldecode — URL-decodes a string, e.g. turning ’%20’ into ’ ’, etc.
urlencode — URL-encodes a string; sometimes useful for creating links.
    Note the lack of a “#” at the beginning of both urldecode and urlencode.
    You can read more about ParserFunctions, including many additional examples,

Weitere Kostenlose Bücher