ମଡ୍ୟୁଲ:Other uses
ଦେଖଣା
This Lua module is used on ୪୪,୦୦୦+ pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module produces an "other uses" hatnote for linking to disambiguation pages. It implements the {{other uses}} template.
Usage from wikitext
[ସମ୍ପାଦନା]This module cannot be used directly from wikitext. Please use the {{other uses}} template instead.
Usage from Lua
[ସମ୍ପାଦନା]To use this module from Lua, first load the module:
local mOtheruses = require('Module:Other uses')
The module can then be used with the following syntax:
mOtheruses._otheruses(args, options)
Parameters
[ସମ୍ପାଦନା]- args
- A table containing strings of link text, without brackets. For example,
{"PAGE1", "PAGE2#SECTION", "PAGE3|LABEL"}
. Make sure that there are no gaps or nil values, as that can confuse themw.text.listToText()
function the module uses. If in doubt, usecompressSparseArray()
from Module:TableTools. This may be empty or nil. - options
- A table containing a number of optional named values; you must supply at least one of
options.defaultPage
oroptions.title
; in most cases setting the latter tomw.title.getCurrentTitle().text
is advisable. The following options are supported:defaultPage
: String; completely overrides the linked page when no arguments are suppliedtitle
: String; sets the title used before the "(disambiguation)" suffix.disambiguator
: String; replaces "disambiguation" in the suffixotherText
: String; replaces "uses" in "other uses"
local mHatnote = require('Module:Hatnote')
local mHatlist = require('Module:Hatnote list')
local mArguments --initialize lazily
local mTableTools --initialize lazily
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local p = {}
-- Produces standard {{other uses}} implementation
function p.otheruses(frame)
mArguments = require('Module:Arguments')
mTableTools = require('Module:TableTools')
local args = mTableTools.compressSparseArray(mArguments.getArgs(frame))
local title = mw.title.getCurrentTitle().text
return p._otheruses(args, {title=title})
end
-- Main generator
function p._otheruses(args, options)
--Type-checks and defaults
checkType('_otheruses', 1, args, 'table', true)
args = args or {}
checkType('_otheruses', 2, options, 'table')
if not (options.defaultPage or options.title) then
error('No default title data provided in "_otheruses" options table', 2)
end
if #args == 0 then
args = {
options.defaultPage or
mHatnote.disambiguate(options.title, options.disambiguator)
}
end
--Generate and return hatnote
local text = mHatlist.forSeeTableToString({{
use = options.otherText and "other " .. options.otherText or nil,
pages = args
}})
return mHatnote._hatnote(text)
end
return p