Modulo:Controllo Wikidata
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Controllo Wikidata/man (modifica · cronologia)
Sandbox: Modulo:Controllo Wikidata/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Controllo Wikidata/test (modifica · cronologia · esegui)
Modulo che implementa il template {{Controllo Wikidata}}.
--[[
* Modulo che implementa il template Controllo Wikidata.
]]--
require('strict')
local getArgs = require('Modulo:Arguments').getArgs
local mWikidata = require('Modulo:Wikidata')
local p = {}
-- Confronta due file multimediali su Commons senza tenere conto di eventuali underscore
local function compareCommonsMediaFile(name, name2)
return name:gsub('_', ' ') == name2:gsub('_', ' ')
end
-- Confronta due URL senza tenere conto di un eventuale slash finale (solo se uno) e del protocollo http/https
local function compareURL(url1, url2)
local ret = false
url1, url2 = url1:match('^https?://(.*)$'), url2:match('^https?://(.*)$')
if url1 and url2 then
local n, n2 = select(2, url1:gsub('/', '')), select(2, url2:gsub('/', ''))
if n <= 1 and n2 <= 1 then
ret = url1:gsub('/$', '') == url2:gsub('/$', '')
else
ret = url1 == url2
end
end
return ret
end
local function getCategory(wdval, userval, args)
local comparefunc = function(v1, v2) return v1 == v2 end
local cat
-- consente di definire funzioni di confronto per proprietà specifiche
-- (oppure tramite eventuali parametri)
if mWikidata._getDatatype({ args[1] }) == 'file multimediale su Commons' then
comparefunc = compareCommonsMediaFile
elseif args[1] == 'P856' then
comparefunc = compareURL
end
if userval then
if not wdval then
cat = string.format('%s assente su Wikidata', args[1])
elseif args.uguale ~= 'no' and comparefunc(wdval, userval) then
cat = string.format('%s uguale su Wikidata', args[1])
elseif args.diff ~= 'no' then
cat = string.format('%s differente su Wikidata', args[1])
end
elseif wdval then
cat = string.format('%s letta da Wikidata', args[1])
end
return cat and string.format('[[%sCategoria:%s]]', args.debug and ':' or '', cat)
end
-- Per l'utilizzo da altro modulo
function p._main(args)
local wdprop, userval = args[1], args[2]
-- namespace 0 e proprietà Wikidata obbligatori
if mw.title.getCurrentTitle().namespace ~= (tonumber(args.ns) or 0) or not wdprop then
return nil
end
local wdval = mWikidata._getProperty({
wdprop,
unit = args.unit,
showunit = args.showunit,
formatting = args.formatting,
from = args.debug and args.from
})
return getCategory(wdval, userval, args)
end
-- Funzione per il template {{Controllo Wikidata}}
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.
- 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:
- 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.
- 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.
- 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.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.