Modulo:Prefisso telefonico

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

Modulo che implementa il template {{Prefisso telefonico}}.

Ha una sottopagina di configurazione: Modulo:Prefisso telefonico/Configurazione.



--[[
* Modulo che implementa il template Prefisso telefonico.
]]--

require('strict')

local getArgs = require('Modulo:Arguments').getArgs
local mDelink = require('Modulo:Delink')
local mWikidata = require('Modulo:Wikidata')

-- Configurazione
local cfg = mw.loadData('Modulo:Prefisso telefonico/Configurazione')

local p = {}

local function getWikidataCategory(userval, wdval, from)
	local cat
	-- rimuove eventuali wikilink per il confronto
	userval = userval and mDelink._main({ userval })
	wdval = wdval and mDelink._main({ wdval })
	-- eventuale prefisso nazionale da ignorare nel confronto
	local prefnaz = mWikidata._getProperty({ 'P17', showprop = 'P474', from = from })

	if userval then
		if not wdval then
			cat = 'P473 assente su Wikidata'
		elseif wdval == userval or (prefnaz and userval == string.format('(%s) %s', prefnaz, wdval)) then
			cat = 'P473 uguale su Wikidata'
		else
			cat = 'P473 differente su Wikidata'
		end
	elseif wdval then
		cat = 'P473 letta da Wikidata'
	end
	return string.format('[[Categoria:%s]]', cat)
end

-- Per l'utilizzo da altro modulo
function p._main(args)
	local userval, wdval, cat 

	-- valore utente e wikidata
	userval = args[1]
	wdval = mWikidata._getProperty({ 'P473', from = args.from })

	-- se esiste una voce in itwiki per il valore Wikidata letto, crea il wikilink
	if wdval then
		local iso3166 = mWikidata._getProperty({ 'P17', showprop = 'P298', from = args.from })
		local prefissi = cfg.prefissi[iso3166]
		if prefissi and prefissi[wdval] then
			wdval = prefissi[wdval] == true and 
					string.format('[[%s]]', wdval) or
					string.format('[[%s|%s]]', prefissi[wdval], wdval)
		end
	end

	-- categorie di servizio
	if mw.title.getCurrentTitle().namespace == 0 then
		if not userval and not wdval and args.cat then
			cat = string.format('[[Categoria:%s]]', args.cat)
		elseif userval or wdval then
			cat = getWikidataCategory(userval, wdval, args.from)
		end
	end

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

-- Entry-point per il template {{Prefisso telefonico}}
function p.main(frame)
	return p._main(getArgs(frame, { parentOnly = true }))
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.