Jump to content

Module:Other uses of/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nihiltres (talk | contribs) at 18:42, 5 September 2022 (Prototype to allow multiple uses to disambiguate). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local mArguments --initialize lazily
local mHatList = require('Module:Hatnote list')
local mHatnote = require('Module:Hatnote')
local mOtheruses = require('Module:Other uses')
local p = {}

p.otherusesof = function (frame)
	mArguments = require('Module:Arguments')
	return p._otherusesof(mArguments.getArgs(frame))
end

function p._otherusesof(args)
	local currentTitle = mw.title.getCurrentTitle()
	local prefixedText = currentTitle.prefixedText
	local maxArg = 0
	for k, v in ipairs(args) do maxArg = k end
	local page = args[maxArg]
	local ofWhat = ((maxArg <= 2) and (args[1] or prefixedText))
	if not ofWhat then 
		local pages = {}
		for k, v in ipairs(args) do
			if k < maxArg then pages[#pages + 1] = mHatnote.quote(v) end
		end
		ofWhat = mHatList.orList(pages)
	else
		ofWhat = mHatnote.quote(ofWhat)
	end
	local options = {
		title = ofWhat,
		otherText = string.format('uses of %s', ofWhat)
	}
	local skipCat = currentTitle.isTalkPage or currentTitle.namespace == 2
	local oddCat =
		skipCat and '' or
		"[[Category:Hatnote templates using unusual parameters]]"
	if (mw.ustring.lower(args[1] or "") == mw.ustring.lower(prefixedText)) or
		((not args[1]) and not args[2]) then
			options.otherText = options.otherText .. oddCat
	end
	arg = page and {page} or {}
	return mOtheruses._otheruses(arg, options)
end
return p