Módulo:Hatnote/doc

De Familia Sanchez Arjona
< Módulo:Hatnote
Revisión del 15:15 24 abr 2014 de Mr. Stradivarius (Discusión) (link to examples)

Saltar a: navegación, buscar

Esta es la página de documentación de Módulo:Hatnote

This is a meta-module that provides various functions for making hatnotes. It implements the {{hatnote}} template, for use in disambiguation hatnotes at the top of pages, and the {{rellink}} template, for use in making links to related articles directly under section headings. It also implements the {{format hatnote link}} template, which is used to format a wikilink for use in hatnotes.

Use from wikitext

The functions in this module cannot be used directly from #invoke, and must be used through templates instead. Please see Template:Hatnote, Template:Rellink and Template:Format hatnote link for documentation.

Use from other Lua modules

To load this module from another Lua module, use the following code.

<source lang="lua"> local mHatnote = require('Module:Hatnote') </source>

You can then use the functions as documented below.

Hatnote

<source lang="lua"> mHatnote._hatnote(s) </source>

Formats the string s as a hatnote. This encloses s in the tags <div class="dablink">...</div>. The CSS of the dablink class is defined in MediaWiki:Common.css.

Example

<source lang="lua"> mHatnote._hatnote('This is a hatnote.') </source>

Produces: <div class="dablink">This is a hatnote.</div>

Displays as:

This is a hatnote.

Rellink

<source lang="lua"> mHatnote._rellink(s, extraclasses) </source>

Formats the string s as a "related articles" link. This encloses s in the tags <div class="rellink">...</div>. The CSS of the dablink class is defined in MediaWiki:Common.css. Extra classes can be added as the string extraclasses.

Example 1

<source lang="lua"> mHatnote._rellink('This is a related article link.') </source>

Produces: <div class="rellink">This is a related article link.</div>

Displays as: Plantilla:Rellink

Example 2

<source lang="lua"> mHatnote._rellink('This is a related article link.', 'boilerplate seealso') </source>

Produces: <div class="rellink boilerplate seealso">This is a related article link.</div>

Displayed as: Plantilla:Rellink

Format link

<source lang="lua"> mHatnote._formatLink(link, display) </source>

Formats link as a wikilink for display in hatnote templates, with optional display value display. Categories and files are automatically escaped with the colon trick, and links to sections are automatically formatted as page § section, rather than the MediaWiki default of page#section.

Examples
<syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._formatLink('Lion')</syntaxhighlight> → [[Lion]] → Lion
<syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._formatLink('Lion#Etymology')</syntaxhighlight> → [[Lion#Etymology|Lion § Etymology]] → Lion § Etymology
<syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._formatLink('Category:Lions')</syntaxhighlight> → [[:Category:Lions]] → Category:Lions
<syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._formatLink('Lion#Etymology', 'Etymology of lion')</syntaxhighlight> → [[Lion#Etymology|Etymology of lion]] → Etymology of lion

Format pages

<source lang="lua"> mHatnote._formatPages(...) </source>

Formats a list of pages using the _formatLink function, and returns the result as an array. For example, the code <syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._formatPages('Lion', 'Category:Lions', 'Lion#Etymology')</syntaxhighlight> would produce an array like <syntaxhighlight lang="lua" class="" id="" style="" inline="1">{'Lion', 'Category:Lions', 'Lion § Etymology'}</syntaxhighlight>.

Format page tables

<source lang="lua"> mHatnote._formatPageTables(...) </source>

Takes a list of page/display tables, formats them with the _formatLink function, and returns the result as an array. Each item in the list must be a table. The first value in the table is the link, and is required. The second value in the table is the display value, and is optional. For example, the code <syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._formatPages({'Lion', 'the Lion article'}, {'Category:Lions'}, {'Lion#Etymology', 'the etymology of lion'})</syntaxhighlight> would produce an array like <syntaxhighlight lang="lua" class="" id="" style="" inline="1">{'the Lion article', 'Category:Lions', 'the etymology of lion'}</syntaxhighlight>.

Find namespace id

<source lang="lua"> mHatnote._findNamespaceId(link, removeColon) </source>

Finds the namespace id of the string link, which should be a valid page name, with or without the section name. This function will not work if the page name is enclosed with square brackets. When trying to parse the namespace name, colons are removed from the start of the link by default. This is helpful if users have specified colons when they are not strictly necessary. If you do not need to check for initial colons, set removeColon to false.

Examples
<syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._findNamespaceId('Lion')</syntaxhighlight> → 0
<syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._findNamespaceId('Category:Lions')</syntaxhighlight> → 14
<syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._findNamespaceId(':Category:Lions')</syntaxhighlight> → 14
<syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._findNamespaceId(':Category:Lions', false)</syntaxhighlight> → 0 (the namespace is detected as ":Category", rather than "Category")

Make wikitext error

<source lang="lua"> mHatnote._makeWikitextError(msg) </source>

Formats the string msg as a red wikitext error message.

Example:

<syntaxhighlight lang="lua" class="" id="" style="" inline="1">mHatnote._makeWikitextError('an error has occurred')</syntaxhighlight> → Error: an error has occurred.

Examples

For examples of how this module is used in other Lua modules, see: