Mòdul:Other uses

De la Viquipèdia, l'enciclopèdia lliure
Icona de documentació de mòdul Documentació del mòdul [ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]

Mòdul Other uses (codi · ús · discussió · proves · tests · casos prova | subpàgines · enllaços)

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


Aquest mòdul produeix una nota d'"altres usos" per enllaçar a pàgines de desambiguació. Implementa la plantilla {{altres usos}}.

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.otherusesIni(frame)
	mArguments = require('Module:Arguments')
	mTableTools = require('Module:TableTools')
	local args = mTableTools.compressSparseArray(mArguments.getArgs(frame))
	return mw.title.getCurrentTitle().prefixedText, args
end

function p.otheruses(frame) --CATALAN: Original form
	local title, args = p.otherusesIni(frame)
	return p._otheruses(args, {title=title})
end

function p.otheruses0(frame)  --CATALAN: without begin space
	local title, args = p.otherusesIni(frame)
	return p._otheruses0(args, {title=title})
end

function p._otheruses(args, options) --CATALAN: Original function
	local text = p._otherusesX(args, options)
	return mHatnote._hatnote(text)
end	

function p._otheruses0(args, options) --CATALAN: without begin margin
	local text = p._otherusesX(args, options)
	return mHatnote._hatnote0(text)
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._otherusesX(args, options) --CATALAN: New name
	--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 s'ofereixen dades de títol predeterminades a la taula d'opcions "..'"_otheruses"', 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 text
end

return p