Skip to content

Latest commit

 

History

History
163 lines (101 loc) · 5.67 KB

mediawiki.md

File metadata and controls

163 lines (101 loc) · 5.67 KB

MediaWiki

Evaluate math expression: {{#expr: expression }}

Comments: <!-- Comment -->

Transclude another page: {{ Page name | optional parameter }}

MediaWiki supports a number of magic words, including:

  • {{PAGENAME}}
  • {{FULLPAGENAME}} (includes the namespace)
  • {{PAGENAMEE}} (URL-encoded page name)
  • {{__NOTOC__}} (hides the Table of Contents)
  • {{!}} (escaped pipe character)
  • various date/time functions

Escape wiki markup: <nowiki> **this** _formatting_ [[won't be processed]]</nowiki> (further formatting help)

Variables

#vardefine

Define a variable

{{#vardefine: variable-name | variable-value }}

#var

Use a variable

{{#var: variable-name }}

Use a variable, providing a default

{{#var: variable-name | default }}

Looping over arrays

{{#arraymap: input | delimiter | variable name | code | output delimiter | ending conjunction }}

To remove commas between items, use \s (space) as a delimiter.

You can process items via template using {{#arraymaptemplate: input | template | delimiter | output delimiter }}.

String manipulation

Reference guide

Whitespace, including newlines, tabs, and spaces, is stripped from the beginning and end of all the parameters of these parser functions. Workarounds available.

For most of these, negative parameter values count from the right end.

Other available functions: len, pos, rpos, sub

#replace

Replace within a string

{{#replace: input | search | replace}}

#explode

Split a string into pieces and return one or more of them.

{{#explode:string|delimiter|starting index|quantity of pieces}}
  • {{#explode:And if you tolerate this| |2}} returns you
  • {{#explode:String/Functions/Code|/|-1}} returns Code
  • {{#explode:Split%By%Percentage%Signs|%|2}} returns Percentage
  • {{#explode:And if you tolerate this| |2|3}} returns you tolerate this

#titleparts

Get pieces of a page title

{{#titleparts: pagename | number of segments to return | index of first segment to return }}

{{#titleparts: Psalm 1/1/Arguments | 2 | 0 }} -> Psalm 1/1

Conditional rendering

#if

Tests whether string is empty. Reference

{{#if: test string | return if not empty | return if empty }}

#ifexpr

Tests whether an expression is truthy or falsy. Reference

{{#ifexpr: expression | return if truthy | return if falsy }}

Also available: #ifeq (if strings are equal), #iferror, #ifexist (if page exists), #switch

Types of braces

{{{Triple curly braces}}} are template parameters or form definition tags.

{{Double curly braces}} are a magic word, a parser function, or a template.

[[Double square brackets]] are a link to an internal page. To change the link text, write [[page name|link text]].

[Single square brackets] are a link to an external page. To change the link text, write [URL link text].

Tables

Detailed reference, with examples

{| Table start

|+ Table caption (optional, only before first row)

|- Row (the first one is optional)

! Header cell. Optional. Consecutive table header cells may be added on same line separated by double marks (!!) or start on new lines, each with its own single mark (!).

| Cell. Consecutive table data cells may be added on same line separated by double marks (||) or start on new lines, each with its own single mark (|).

|} Table end

Semantic MediaWiki queries

Ask queries the wiki database and returns a table:

{{#ask:
 [[Category:City]]
 [[Located in::Germany]] 
 |?Population 
 |?Area#km² = Size in km²
 |limit=10
}}

Show gets a single property value from a single page:

{{#show: Demo:Berlin |?Population |default=0}}

Other available parameters: format, limit, offset, sort, order, headers, mainlabel, index, link, default, intro, outro, searchlabel, format-specific parameters

Debugging

Replace {{#vardefine}} with {{#vardefineecho}}, which prints the value in the place it's defined