Module:Common/doc
This is the documentation page for Module:Common
Module:Common
Shared stateless helper functions, which can be loaded in other Lua modules via:
local common = require("Module:Common")
Usage
This module also exposes a few permanent utility entry points.
Replace tildes with another character
Tildes are good delimiters in the wiki context, as the alternatives are commas, which are common in prose, and pipes, which are special wikitext characters.
By default, tildes ~ will be replaced by pipes |:
{{#invoke:Common|replaceTilde|Item 1~Item 2~Item 3}}
Optionally, a character can be specified to be used as the replacement. For example, comma:
{{#invoke:Common|replaceTilde|Item 1~Item 2~Item 3|,}}
Render a tilde-delimited string as a bullet list
Converts a tilde-separated string into a bullet list. The list items are left-aligned (by default), while the list as a whole remains centered.
{{#invoke:Common|bulletList|Item 1~Item 2~Item 3}}
Optionally, set link=true to wrap each item as a wikilink:
{{#invoke:Common|bulletList|Item 1~Item 2~Item 3|link=true}}
Optionally, specify prefix to prepend a certain string to every item's link target:
{{#invoke:Common|bulletList|Item 1~Item 2~Item 3|link=true|prefix=ParentPage/}}
Optionally, set leftAlign=no to omit the left-alignment, allowing invoking elements to control text alignment instead:
{{#invoke:Common|bulletList|Item 1~Item 2~Item 3|leftAlign=no}}
Get URL-safe version of a given string
MessageBundle keys are built from a slugified (URL-safe) version of a string. Use this to generate the exact slug from a given input.
If no value is specified, it defaults to the current page's title:
{{#invoke:Common|toSlug}}
A specific string can also be provided instead:
{{#invoke:Common|toSlug|Terrarium of Muad'Dib}}
Get an auto-localised string from a MessageBundle
Retrieves a string for a given key from a specified MessageBundle. It auto-switches to the language that the viewer's page is currently on, and falls back to the English source if no translation exists for the current language.
{{#invoke:Common|localise|Vehicles|sandbike-name}}
Optionally, set link=true to wrap the result as a link to the page matching the key's English value (translated subpage if one exists for the viewer's language), e.g. [[Wildlife of Arrakis|Fauna von Arrakis]]:
{{#invoke:Common|localise|DLC|wildlife-of-arrakis-name|link=true}}
If the link target differs from the localised string itself (e.g. a label whose page title doesn't match the label text), specify the target page title directly instead of true. This also resolves to a translated subpage where available:
{{#invoke:Common|localise|Labels|vehicle_backup|link=Vehicle Backup Tool}}
Parameters
replaceTilde
- 1
- string
- The string containing tildes
~to replace.
- 2 (optional)
- string
- The character to replace the tildes with.
- Defaults to pipe
|.
bulletList
- 1
- string
- The tilde-separated string of items to convert into a bullet list.
- link (optional)
- boolean
- If specified with a truthy value, each item will be wrapped in double square brackets, rendering it as a wikilink.
- Valid values:
trueyes1
- prefix (optional)
- string
- Only functions when
linkis truthy. - If specified, prepends the string to every item's link target.
- leftAlign (optional)
- boolean
- If set to a falsy value, the inline text-align:left style is omitted from the list wrapper, so the caller's own CSS can control alignment instead.
- Defaults to true.
toSlug
- 1 (optional)
- string
- The string to generate a slug for.
- If omitted, defaults to the current page's title.
localise
- 1
- string
- The name of the MessageBundle to look up (without the "MessageBundle:" prefix).
- 2
- string
- The key to retrieve from the MessageBundle.
- link (optional)
- boolean or string
- If
true, wraps the result as a link to the page matching the key's English value, e.g.[[English|Translation]]. - If set to a page title instead, links to that page rather than the key's English value. Use this when the link target differs from the localised string itself.
- In both cases, the link resolves to a translated subpage of the target (e.g.
Vehicle Backup Tool/de) matching the language of the current page, falling back to English if no translated subpage exists. - Defaults to false.