Jump to content

Module:Other uses

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nihiltres (talk | contribs) at 16:42, 5 May 2016 (Removed long comment block redundant to docs, simplified a default's form, and restructured a string concatenation as a better string.format). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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 = 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
			(options.title .. '  (' .. (options.disambiguator or 'disambiguation') .. ')')
		}
	end
	--should switch to using _forSee from [[Module:Hatnote list]] once that's out of alpha
	local text = string.format(
		'For other %s, see %s.',
		(options.otherText or 'uses'),
		--should switch to using andList from [[Module:Hatnote list]] once that's out of alpha
		mw.text.listToText(mHatnote.formatPages(unpack(args)))
	)
	return mHatnote._hatnote(text)
end

return p