Module:Other uses
This template is currently being deleted. This template is being removed from the pages on which it is currently used, according to the specific instructions at Starfleet:Templates for discussion/Holding cell, after which it will be deleted. Please do not use it on any additional pages, but do not remove it from pages if it is under deletion review. The decision to delete this template was made following this discussion initiated on 15 May 2019 at Templates for discussion. Administrators: Please review this template's instructions at Starfleet:Templates for discussion/Holding cell before proceeding with any action. |
This Lua module is used on 111,000+ pages. To avoid large-scale disruption and unnecessary server load, any changes to it should first be tested in the module's /sandbox or /testcases subpages. The tested changes can then be added to this page in a single edit. Please consider discussing changes on the talk page before implementing them. |
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[edit source]
otheruses()[edit source]
The otheruses()
function directly implements {{other uses}} and probably shouldn't be used anywhere else.
otherX()[edit source]
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[edit source]
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()
[edit source]
- 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"
External links[edit source]
- Module:Other uses at Wikipedia, the free Terran-based encyclopedia that anyone can edit.
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().prefixedText
return p._otheruses(args, {title=title})
end
-- Produces standard {{other uses2}} implementation
function p.otheruses2(frame)
return p._otheruses({}, {title = (frame:getParent().args[1] or mw.title.getCurrentTitle().prefixedText)})
end
--Implements "other [x]" templates with otherText supplied at invocation
function p.otherX(frame)
mArguments = require('Module:Arguments')
mTableTools = require('Module:TableTools')
local x = frame.args[1]
local args = mTableTools.compressSparseArray(
mArguments.getArgs(frame, {parentOnly = true})
)
local options = {
title = mw.title.getCurrentTitle().prefixedText,
otherText = x
}
return p._otheruses(args, options)
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
local emptyArgs = true
for k, v in pairs(args) do
if type(k) == 'number' then emptyArgs = false break end
end
if emptyArgs 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