Modulo:IsInCat

Da Wikivoyage.
Info Istruzioni per l'uso
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:IsInCat/man (modifica · cronologia)
Sandbox: Modulo:IsInCat/sandbox (modifica · cronologia) · Test: Modulo:IsInCat/test (modifica · cronologia · Esegui)

Vedi anche


--[[
	Source script:	https://it.wikivoyage.org/wiki/Modulo:IsInCat
	Maintainer:		Andyrom75

	Lazy loads:
	require( 'Module:IsRedirect' ).IsRedirectVal
]]

local function _isDefined(s)
	return s ~= '' and s
end

local function _IsInCat(frame)
	local args = frame.args
	if _isDefined(args[1]) then
		frame:callParserFunction( '#IsIn', { args[1] } )
		local output = '[[Categoria:' .. args[1] .. (_isDefined(args[2]) and ('|' .. args[2]) or '') .. ']]'
		local pageName = mw.title.getCurrentTitle().text
		local pagesInCategory = mw.site.stats.pagesInCategory( pageName ) > 0
		if mw.title.getCurrentTitle().namespace == 14 then --NS:Categoria
			if require( 'Module:IsRedirect' ).IsRedirectVal(pageName) == 'yes' then
				local testoAvviso = "'''[[" .. pageName .. "]]''' è un redirect, probabilmente divenuto tale a seguito dello spostamento di una pagina"
					.. (pagesInCategory and ". Le sottopagine di questa categoria potrebbero necessitare delle modifiche per essere associate ad una nuova categoria. Controlla il template [[Template:Quickfooter|Quickfooter]] alla fine dell'articolo e le categorie aggiunte di seguito per aggiornarne eventualmente i valori" or '')
				output = output .. frame:expandTemplate{ title='Stile', args = { testoAvviso } }
					.. (pagesInCategory and "[[Categoria:Categorie con articoli dal breadcrumb errato]]" or "[[Categoria:Categorie associate a redirect]]")
			end
			output = output .. frame:callParserFunction( '#ifexist', { "Categoria:" .. args[1], '', "[[Categoria:Categorie incluse in categorie inesistenti]]" } )
				.. (args[1] ~= 'Utenti per lingua' -- per queste categorie NON mostro il successivo blocco DIV
				and ("<div class='noprint' style='margin-top:1em;border:1px solid #aaaaaa;background-color: #F9F9F9;padding:3px;text-align:center;clear: both;'>Lista completa degli articoli e sottocategorie inerenti: '''"
					.. frame:callParserFunction( '#ifexist', { pageName, "[[" .. pageName .. "]]", pageName } ) .. "'''<br />"
					.. frame:callParserFunction( '#ifexist', { args[1], "<small>(Per ampliare la ricerca vedere: '''[[" .. args[1] .. "]]''')</small>" , '' } )
					.. "</div>" ) or '')
		end
		return output
	end
	return ''
end

local p = {}

function p.IsInCatTemplate(frame)
	return _IsInCat(frame:getParent())
end

function p.IsInCatInvoke(frame)
	return _IsInCat(frame)
end

function p.IsInCatModule(frame)
	local Cframe = mw.getCurrentFrame()
	Cframe.args = frame.args
	return _IsInCat(Cframe)
end

function p.IsInCatVal(value)
	local Cframe = mw.getCurrentFrame()
	Cframe.args = {value}
	return _IsInCat(Cframe)
end

return p