Modulo:Diocesi

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

Modulo a supporto del template {{Edificio religioso}} per generare la riga riguardante le diocesi, leggendo la proprietà Wikidata diocesi (P708) o il parametro "Diocesi".



--[[
* Modulo a supporto del template Edificio religioso per generare
* la riga riguardante le diocesi.
]]--

require('strict')

local getArgs = require('Modulo:Arguments').getArgs
local mWikidata = require('Modulo:Wikidata')
local error_category = '[[Categoria:Errori di compilazione del template Edificio religioso]]'
-- La proprietà P708 verrà letta solo se il suo valore (di tipo elemento) è "istanza di" uno di questi elementi.
-- Il formato di ogni riga è:
-- qID = { 'Nome da visualizzare nel sinottico', 'Eventuale titolo pagina se diverso dal nome' }
local cfg = {
	Q285181   = { 'Eparchia' },
	Q350509   = { 'Ordinariato' },
	Q384003   = { 'Prefettura apostolica' },
	Q427961   = { 'Provincia ecclesiastica' },
	Q565744   = { 'Chiesa regionale', 'Chiesa evangelica in Germania' },
	Q620225   = { 'Vicariato apostolico' },
	Q644930   = { 'Missione sui iuris' },
	Q665487   = { 'Diocesi' },
	Q866196   = { 'Diocesi' },
	Q1184788  = { 'Sede suburbicaria' },
	Q1282276  = { 'Patriarcato', 'Patriarcato (cristianesimo)' },
	Q1385389  = { 'Diocesi extra-provinciale', 'Chiesa anglicana' },
	Q1431554  = { 'Amministrazione apostolica' },
	Q1455927  = { 'Prelatura personale' },
	Q1531518  = { 'Ordinariato militare' },
	Q1778235  = { 'Abbazia territoriale' },
	Q2072238  = { 'Arcidiocesi' },
	Q2288631  = { 'Arcieparchia' },
	Q2445047  = { 'Diocesi' },
	Q2633744  = { 'Prelatura territoriale' },
	Q3146899  = { 'Diocesi' },
	Q3732788  = { 'Esarcato apostolico' },
	Q3732792  = { 'Esarcato arcivescovile' },
	Q3732793  = { 'Esarcato patriarcale' },
	Q15150553 = { 'Ordinariato personale' },
	Q12593969 = { 'Patriarcato', 'Patriarcato (cristianesimo)' },
	Q18917976 = { 'Diocesi' },
	Q20060955 = { 'Diocesi' },
	Q60176300 = { 'Diocesi' },
	Q66818387 = { 'Diocesi' },
    Q104964763 = { 'Arcidiocesi' },
	Q105388829 = { 'Diocesi' },
    Q105389481 = { 'Eparchia' },
	Q105390172 = { 'Arcidiocesi' },
	Q105419665 = { 'Arcidiocesi' },
}

-- Restituisce la categoria Wikidata appropriata in base al valore utente e a quello su Wikidata.
--
-- @param {string} userval
-- @param {string} wdval
-- @return {string}
local function getWikidataCategory(userval, wdval)
	local pattern = '^%[?%[?([^|%]]*).*$'
	local cat
	-- rimuove i wikilink per il confronto
	userval = userval and userval:match(pattern)
	wdval = wdval and wdval:match(pattern)

	if userval then
		if not wdval then
			cat = 'P708 assente su Wikidata'
		elseif wdval == mw.language.getContentLanguage():ucfirst(userval) then
			cat = 'P708 uguale su Wikidata'
		else
			cat = 'P708 differente su Wikidata'
		end
	elseif wdval then
		cat = 'P708 letta da Wikidata'
	end
	return string.format('[[Categoria:%s]]', cat)
end

-- Restituisce l'ID dell'elemento Wikidata dell'"istanza di" del valore in P708.
--
-- @return {string}
local function getIstanzaId(anno_sconsacr)
	local diocesiId, ret
	diocesiId = mWikidata._getProperty({ 'P708', n = 1, formatting = 'raw' })
	-- in futuro il modulo:Wikidata restituirà nil per "nessun valore" e "valore sconosciuto"
	if diocesiId and mw.wikibase.isValidEntityId(diocesiId) then
		local claims = {}
		for _, claim in ipairs(mw.wikibase.getAllStatements(diocesiId, 'P31')) do
			if claim.rank ~= 'deprecated' then
				table.insert(claims, claim)
			end
		end
		ret = claims[1] and mWikidata._formatStatement(claims[1], { formatting = 'raw' })
		-- Sede titolare è sovrascritto se ci sono altre dichiarazioni e se la diocesi è diventata
		-- tale dopo l'anno di sconsacrazione della chiesa, altrimenti genera una categoria di errore
		if ret == 'Q15217609' and claims[2] then
			anno_sconsacr = anno_sconsacr and tonumber(anno_sconsacr:match('%d%d%d%d?'))
			local anno_inizio_st = mWikidata._formatQualifiers(claims[1], 'P580') or ''
			anno_inizio_st = tonumber(anno_inizio_st:match('%d%d%d%d?'))
			if anno_sconsacr and anno_inizio_st and anno_sconsacr <= anno_inizio_st then
				ret = mWikidata._formatStatement(claims[2], { formatting = 'raw' })
			end
		end
	end
	return ret
end

-- Costruisce il wikilink della diocesi a partire da sitelink e label (rimuovendo prefix con preposizioni).
--
-- @param {string} prefix
-- @return {string}
local function getDiocesiWlink(prefix)
	local ret
	local pattern = ' d[ei][il]?l?[ae\']?'
	local diocesiId = mWikidata._getProperty({ 'P708', n = 1, formatting = 'raw' })
	local sitelink = mw.wikibase.getSitelink(diocesiId)
	-- deve esistere il sitelink in itwiki, non genera wikilink rossi
	if sitelink then
		local label = mw.wikibase.getLabel(diocesiId) or sitelink
		label = label:gsub('^' .. prefix .. pattern, '')
		label = label:gsub('^' .. mw.ustring.lower(prefix) .. pattern, '')
		ret = string.format('[[%s|%s]]', sitelink, label)
	end
	return ret
end

-- =============================================================================
--                            Funzioni esportate
-- =============================================================================

local p = {}

-- Funzione per {{#invoke:Diocesi|nome}}.
function p.nome(frame)
	local args = getArgs(frame, { parentOnly = true })
	local ret

	if args.Diocesi then
		ret = '[[Diocesi]]'
	else
		local istanzaId = getIstanzaId(args.AnnoSconsacr)
		if istanzaId and cfg[istanzaId] then
			ret = cfg[istanzaId][2] and
				  string.format('[[%s|%s]]', cfg[istanzaId][2], cfg[istanzaId][1]) or
				  string.format('[[%s]]', cfg[istanzaId][1])
		end
	end

	return ret
end

-- Funzione per {{#invoke:Diocesi|valore}}.
function p.valore(frame)
	local userval, wdval, istanzaId, cat
	local args = getArgs(frame, { parentOnly = true })

	userval = args.Diocesi
	istanzaId = getIstanzaId(args.AnnoSconsacr)
	if istanzaId and cfg[istanzaId] then
		wdval = getDiocesiWlink(cfg[istanzaId][1])
	end

	if mw.title.getCurrentTitle().namespace == 0 then
		if userval or wdval then
			cat = getWikidataCategory(userval, wdval)
		elseif istanzaId == 'Q15217609' then
			cat = error_category
		end
	end

	return (userval or wdval or '') .. (cat or '')
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.