Latest revision |
Your text |
Line 1: |
Line 1: |
| --------------------------------------------------------------------------------
| |
| -- Module:Hatnote --
| |
| -- --
| |
| -- This module produces hatnote links and links to related articles. It --
| |
| -- implements the {{hatnote}} and {{format link}} meta-templates and includes --
| |
| -- helper functions for other Lua hatnote modules. --
| |
| --------------------------------------------------------------------------------
| |
|
| |
| local libraryUtil = require('libraryUtil')
| |
| local checkType = libraryUtil.checkType
| |
| local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg
| |
| local mArguments -- lazily initialise [[Module:Arguments]]
| |
| local yesno -- lazily initialise [[Module:Yesno]]
| |
| local formatLink -- lazily initialise [[Module:Format link]] ._formatLink
| |
|
| |
| local p = {}
| |
|
| |
| --------------------------------------------------------------------------------
| |
| -- Helper functions
| |
| --------------------------------------------------------------------------------
| |
|
| |
| local function getArgs(frame)
| |
| -- Fetches the arguments from the parent frame. Whitespace is trimmed and
| |
| -- blanks are removed.
| |
| mArguments = require('Module:Arguments')
| |
| return mArguments.getArgs(frame, {parentOnly = true})
| |
| end
| |
|
| |
| local function removeInitialColon(s)
| |
| -- Removes the initial colon from a string, if present.
| |
| return s:match('^:?(.*)')
| |
| end
| |
|
| |
| function p.defaultClasses(inline)
| |
| -- Provides the default hatnote classes as a space-separated string; useful
| |
| -- for hatnote-manipulation modules like [[Module:Hatnote group]].
| |
| return
| |
| (inline == 1 and 'hatnote-inline' or 'hatnote') .. ' ' ..
| |
| 'navigation-not-searchable'
| |
| end
| |
|
| |
| function p.disambiguate(page, disambiguator)
| |
| -- Formats a page title with a disambiguation parenthetical,
| |
| -- i.e. "Example" → "Example (disambiguation)".
| |
| checkType('disambiguate', 1, page, 'string')
| |
| checkType('disambiguate', 2, disambiguator, 'string', true)
| |
| disambiguator = disambiguator or 'disambiguation'
| |
| return mw.ustring.format('%s (%s)', page, disambiguator)
| |
| end
| |
|
| |
|
| function p.findNamespaceId(link, removeColon) | | function p.findNamespaceId(link, removeColon) |