Skip to content

Instantly share code, notes, and snippets.

@danpeig
Created March 10, 2025 22:24
Show Gist options
  • Save danpeig/da460d46c350ee43debed80783314b33 to your computer and use it in GitHub Desktop.
Save danpeig/da460d46c350ee43debed80783314b33 to your computer and use it in GitHub Desktop.
Mediawiki basic to advanced cheatsheet

Mediawiki Markup

Decoration

  • ''italic'': italic
  • '''bold''': bold
  • '''''bold & italic''''' : bold & italic
  • == level 1 == : heading 1 (page title)
  • === level 2 === : heading 2
  • ==== level 3 ==== : heading 3
  • ===== level 4 =====: heading 4
  • ----: horizontal rule
  • <s>Strike-through</s>: strike-through

Blocks

  • <q>This is a quotation</q>: quotes
  • with ''markup'': escape with markup (start with blank space)
  • <nowiki>without ''markup''</nowiki>: escape without markup
  • <!-- comment -->: comment
  • <pre> Text is '''preformatted''' and ''markups'' '''''cannot''''' be done</pre>: preformatted
  • <code>Source code</code>: source code
  • <blockquote>Blockquote</blockquote>: blockquotes

Links and templates

  • [[name of page]]: internal link
  • [[name of page|display text]]: internal link with display text
  • [[:Category:name of category]]: link to category page
  • [[Category:Birds nest]]: definition of a category page (does not print)
  • [http://www.example.com]: external link
  • [http://www.example.com display text]: external link with display text
  • #redirect [[Target page]]: redirect
  • {{header|parameter=apple}}: template passing a named parameter
  • {{:Pagename}}: transclusion (inserts the page as content)
  • [[Media:MediaWiki-2020-logo.svg]]: link to image (does not load the image)

Signature

  • ~~~: signature name
  • ~~~~: signature name and timestamp
  • ~~~~~: timestamp

Lists

  • bullet
* Start each line
* with an [[Wikipedia:asterisk|asterisk]] (*).
** More asterisks give deeper
*** and deeper levels.
* Line breaks <br>don't break levels.
*** But jumping levels creates empty space.
Any other start ends the list.
  • numbered
# Start each line
# with a [[Wikipedia:Number_sign|number sign]] (#).
## More number signs give deeper
### and deeper
### levels.
# Line breaks <br>don't break levels.
### But jumping levels creates empty space.
# Blank lines
  • definition
;item 1
: definition 1
;item 2
: definition 2-1
: definition 2-2
  • indent text
: Single indent
:: Double indent
::::: Multiple indent

Images

  • [[File:Example.jpg|thumb|Caption text]]: thumbnail
  • [[File:image_name.png|150px]]: with size
  • [[File:example.jpg|border|caption]]: with border
  • [[File:example.jpg|frameless|caption]]: without frame
  • [[File:example.jpg|frameless|border|caption]]: without frame with border
  • [[File:example.jpg|right|100px|caption]]: aligned to the right of the text
  • [[File:example.jpg|link=Main Page|caption]]: link
  • [[File:example.jpg|link=http://wikipedia.org/wiki/Test|caption]]: external link
  • [[File:example.jpg|link=|caption]]: disable link to file page

Image gallery

<gallery>
File:Example.jpg|Item 1
File:Example.jpg|a link to [[Help:Contents]]
File:Example.jpg
File:Example.jpg|alt=An example image. It has flowers
File:Example.jpg|''italic caption''
File:Example.jpg|link=https://example.com|This text will not render because an external link came first
File:Example.jpg|Links to external website|link=https://example.com
File:Example.jpg|link=w:Main_Page|Internal link
Example.jpg|on page "{{PAGENAME}}"
File:Using Firefox.pdf|page=72
</gallery>
  • gallery modes: <gallery mode="packed-hover">
    • traditional is the original gallery type used by MediaWiki.
    • nolines is similar to traditional, but with no border lines.
    • packed causes images to have the same height but different widths, with little space between the images. The rows in this responsive mode organize themselves according to the width of the screen.
    • packed-overlay shows the caption overlaid on the image, in a semi-transparent white box.
    • packed-hover is similar to packed-overlay, but with the caption and box only showing up on hover.
    • slideshow creates a slideshow of the images.
  • gallery sizes: <gallery widths=300 heights=200>

Tables

{|
|+ Caption of the table
! Heading 1
! Heading 2
|-
| Cell 1 in row 1
| Cell 2 in row 1
|-
| Cell 1 in row 2
| Cell 2 in row 2
|}

References

First use of the refence <ref name="Ref06">Reference text</ref>
Next uses of the reference <ref name="Ref06"/>

==References==
<references/>

Templates

{{Template:Pagename}} transcludes the page titled Template:Pagename (equivalent to {{Pagename}})
{{Talk:Pagename}} transcludes the page titled Talk:Pagename
{{:Pagename}} transcludes the page titled Pagename (i.e., in the main namespace)
{{subst::Pagename}} substitutes the contents of the page titled Pagename

If the specified namespace doesn’t exist, the full title is assumed to be a template:

{{Foo:Bar}} transcludes Template:Foo:Bar

Regardless of what syntax is used, the name of the template can be relative to the current page For example, if {{/bar}} is called on page foo, it will transclude the page foo/bar.

It can also be generated dynamically. For example, {{ {{foo}} }} calls Template:foo and interprets the result as the name of another template to call.

Named parameters

'''A little thank you...'''
for {{{reason}}}.
hugs, {{{signature}}}

Within the template, we use {{{reason}}} and {{{signature}}} to identify each parameter, instead of a number. To pass these parameters by name, identify each parameter when passing it:

{{Thankyou|signature=Me|reason=being who you are}}

Note that, within the template, each parameter is surrounded by three braces: {{{ }}}. This is different from normal template name usage.

Anonymous parameters

{{Thankyou|all your effort|Me}}

Template {{Thankyou}} receives parameters{{{1}}}=all your effort and {{{2}}}=Mee, producing A little thank you... for all your effort. Hugs, Me

Transclusion control

  • noinclude - The markup <noinclude>...</noinclude> means that the text between the tags is visible exclusively on the source page and cannot be transcluded onto another page. This is useful for template documentation and categories.
  • includeonly - The markup <includeonly>...</includeonly> means that the text between the tags will be hidden on the source page and visible only when transcluded onto a different page. This can be useful, for example, for adding categories to pages transcluding a template, without adding the template itself to these categories.
  • onlyinclude - The markup <onlyinclude>...</onlyinclude> means that the text between the tags will be visible on the source page and visible when transcluded onto a different page. This is the most subtle of the partial transclusion tags because it often overrules the others. If there is at least one pair of “onlyinclude” tags on a page, then whenever this page is transcluded, it is only the material within the “onlyinclude” tags that is transcluded. There can be several such “onlyinclude” sections on a page. This can be useful, for example, to repeat a small part of one page on a second one: just surround the small part by onlyinclude tags, and transclude it onto the second page.

Category in templates

If you add [[Category:Cats]] inside a template (a transcluded page), both the template and pages which transclude this template will be categorised in Cats.

If you want only the template to be categorised, you should ensure to write category marker inside <noinclude> tags.

If you want only the pages which use the template to be categorised, but not the template itself, you should ensure to write category marker inside <includeonly> tags.

Parser functions

if

This function evaluates a test string and determines whether or not it is empty. A test string containing only white space is considered to be empty.

{{#if: test string | value if test string is not empty | value if test string is empty (or only white space)}}
{{#if:{{{1|}}}|You entered text in variable 1|There is no text in variable 1}}

alternative switch:

{{#switch: {{{1}}} | foo = Foo | baz = Baz | Bar }}

Here, if {{{1}}} equals foo, zoo or roo, the function will return Foo. If it equals baz, the function will return Baz. If the parameter is empty or does not exist, the function will return Bar.

ifeq

This parser function compares two input strings, determines whether they are identical, and returns one of two strings based on the result. If more comparisons and output strings are required, consider using #switch.

{{#ifeq: string 1 | string 2 | value if identical | value if different }}

{{#ifeq: {{{1|}}} | short | 20 | 40 }}

switch

This function compares one input value against several test cases, returning an associated string if a match is found.

{{#switch: comparison string
 | case = result
 | case = result
 | ...
 | case = result
 | default result
}}

time

{{#time: Y-m-d }} → 2025-03-05
{{#time: [[Y]] m d }} → 2025 03 05
{{#time: [[Y (year)]] }} → 2025 (25UTCamWed, 05 Mar 2025 06:13:28 +0000)
{{#time: [[Y "(year)"]] }} → 2025 (year)
{{#time: i's" }} → 13'28"
{{#time: r|20 December 2000}}
{{#time: r|now}} → Tue, 04 Mar 2025 14:11:21 +0000
{{#time: r|+2 hours}} → Tue, 04 Mar 2025 16:11:21 +0000
{{#time: r|now + 2 hours}} → Tue, 04 Mar 2025 16:11:21 +0000
{{#time: r|20 December 2000}} → Wed, 20 Dec 2000 00:00:00 +0000
{{#time: r|December 20, 2000}} → Wed, 20 Dec 2000 00:00:00 +0000
{{#time: r|2000-12-20}} → Wed, 20 Dec 2000 00:00:00 +0000
{{#time: d F Y | January 0 2008 }} → 31 December 2007
  • Y 4-digit year
  • y 2-digit year
  • L 1 if it's a leap year, 0 if not
  • n Month index, not zero-padded (3)
  • m Month index, zero-padded (03)
  • M An abbreviation of the month name, in the site language (Mar)
  • F The full month name in the site language (March)
  • j Day of the month, not zero-padded (4)
  • d Day of the month, zero-padded (04)
  • z Day of the year (January 1 = 0)
  • W ISO 8601 week number, zero-padded
  • N ISO 8601 day of the week (Monday = 1, Sunday = 7)
  • w Number of the day of the week (Sunday = 0, Saturday = 6)
  • D An abbreviation for the day of the week. Rarely internationalized (Tue)
  • l The full weekday name. Rarely internationalized. (Tuesday)
  • a "am" during the morning (00:00:00 → 11:59:59), "pm" otherwise (12:00:00 → 23:59:59).
  • A Uppercase version of a above
  • g Hour in 12-hour format, not zero-padded
  • h Hour in 12-hour format, zero-padded.
  • G Hour in 24-hour format, not zero-padded
  • H Hour in 24-hour format, zero-padded
  • i Minutes past the hour, zero-padded
  • s Seconds past the minute, zero-padded
  • U Unix time. Seconds since January 1 1970 00:00:00 GMT
  • e Timezone identifier
  • O Difference to Greenwich time (GMT)
  • P Difference to Greenwich time (GMT), with colon
  • T Timezone abbreviation
  • t Number of days in the current month
  • c ISO 8601 formatted date, equivalent to Y-m-d"T"H:i:s+00:00 (Tue, 04 Mar 2025 14:11:21 +0000)

Magic words

  • __NOTOC__: Hides the table of contents (TOC).
  • __FORCETOC__: Forces the table of contents to appear at its normal position (before the first header
  • __TOC__: Places a table of contents at the word's current position (overriding NOTOC). If this is used multiple times, the table of contents will appear at the first word's position.
  • __INDEX__: Tell search engines to index the page
  • __NOINDEX__: Tell search engines not to index the page (i.e. do not list in search engines' results).
  • __NOEDITSECTION__: Hides the section edit links beside headings.
  • __NEWSECTIONLINK__: Adds a link beside the "Edit" tab for adding a new section on a non-talk page
  • __NONEWSECTIONLINK__: Removes the link beside the "Edit" tab on pages in talk namespaces.
  • __NOGALLERY__: Used on a category page, replaces thumbnails in the category view with normal links.
  • __DISAMBIG__: Disambiguation page

Variables

Server

Content

  • {{CONTENTLANGUAGE}}: en
  • {{PAGELANGUAGE}}: en
  • {{DISPLAYTITLE:title}}: set the title
  • {{DEFAULTSORT:sortkey}}: set sort categories
  • {{FULLPAGENAME}}: namespace + title
  • {{PAGENAME}}: title
  • {{BASEPAGENAME}}: Help:Title/Foo/Bar would return Title/Foo
  • {{ROOTPAGENAME}}: Help:Title/Foo/Bar would return Title
  • {{SUBPAGENAME}}: Help:Title/Foo/Bar would return Bar
  • {{PAGEID}}: 3271
  • {{PROTECTIONLEVEL:action}}: protection level for a given action (e.g. "edit", "move"). Returns an empty string if not protected.
  • {{PROTECTIONEXPIRY:action}}: protection expiry (e.g. "20160418155030", "infinity") for a given action (e.g. "edit", "move")

Date and time

Prefer time parse functions instead

  • {{CURRENTYEAR}}: 2025
  • {{CURRENTMONTH2}}: 03
  • {{CURRENTMONTH1}}: 3
  • {{LOCALTIMESTAMP}}: 20250308160027

Revision

  • {{REVISIONID}}: 2131234123
  • {{REVISIONDAY}}: 2
  • {{REVISIONDAY2}}: 02
  • {{REVISIONMONTH1}}: 3
  • {{REVISIONMONTH1}}: 03
  • {{REVISIONYEAR}}: 2025
  • {{REVISIONTIMESTAMP}}: 20250302012043
  • {{REVISIONUSER}}: user name

Statistics

  • {{NUMBEROFPAGES}}: wiki pages
  • {{NUMBEROFARTICLES}}: wiki articles (content namespace)
  • {{NUMBEROFFILES}}: uploaded files
  • {{NUMBEROFVIEWS}}: page views (does not work with cache)
  • {{NUMBEROFUSERS}}: registred users
  • {{NUMBEROFADMINS}}: admins
  • {{NUMBEROFACTIVEUSERS}}: active users

URL parameters

Example: www.mediawiki.org/w/index.php?title=Project:Sandbox&action=view

  • &action=purge: erase cache
  • &action=edit: edit page
  • &action=view: standard view
  • &action=delete: delete page
  • &action=raw: raw content
  • &useskin=vector : set skin to vector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment