Module:Other uses
![]() | This Lua module is used on approximately 143,000 pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This module produces an "other uses" hatnote for linking to disambiguation pages. It implements the {{other uses}} template.
Usage from wikitext
otheruses()
The otheruses()
function directly implements {{other uses}} and probably shouldn't be used anywhere else.
otherX()
The otherX()
function allows direct implementation of templates that differ from {{other uses}} in only phrasing. For example, where {{other uses}} is phrased with "other uses", {{other places}} is phrased with "other places with the same name" and can be implemented using otherX()
, which takes the custom phrasing as its parameter at the module invocation. {{other places}} in particular could be implemented with this wikitext:
{{#invoke:other uses|otherX|places with the same name}}
Note that the leading "other" is automatically supplied; if a template would not use this phrasing, it should not use otherX()
.
Usage from Lua
To use this module from Lua, first load the module:
local mOtheruses = require('Module:Other uses')
The module functions can then be used through the _otheruses()
function:
mOtheruses._otheruses(args, options)
Parameters of _otheruses()
- 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().prefixedText
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 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 = frame:getParent():getTitle()
return p._otheruses(args, {title=title})
end
--Main generator
--Two parameters, args and options, each tables:
-- * args: can be empty or nil, in which case the defaults kick in.
-- Otherwise assumed to be a table of unbracketed page strings, no table gaps
-- * options: must not be nil; it must have in a "defaultPage" or "title" option,
-- since this function doesn't use a frame object to do the defaulting itself.
-- Summary of options available:
-- * defaultPage: sets full default "other uses" target; overrides title and disambiguator
-- * title: sets title assumed that gets the suffix added
-- * disambiguator: sets default text appearing in parens, defaults to "disambiguation"
-- * otherText: allows setting more "other" options, defaults to "uses"
function p._otheruses(args, options)
checkType('_otheruses', 1, args, 'table', true)
if not args then args = {} end
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
(options.title .. ' (' .. (options.disambiguator or 'disambiguation') .. ')')
}
end
local forOther = 'For other ' .. (options.otherText or 'uses') .. ', '
local see = 'see ' .. mw.text.listToText(mHatnote.formatPages(unpack(args))) .. "."
local text = forOther .. see
return mHatnote._hatnote(text)
end
return p