Modulo:Controllo di autorità/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
+ |
use require('strict') instead of require('Module:No globals') |
||
(5 versioni intermedie di 2 utenti non mostrate) | |||
Riga 5:
]]
require('strict')
local mWikidata = require( local modlingue = require(
local cfg = mw.title.new(
-------------------------------------------------------------------------------
Riga 15 ⟶ 16:
-- Returns the ISNI check digit isni must be a string where the 15 first elements are digits
local function getIsniCheckDigit(
local total = 0
for i = 1, 15 do
local digit = isni:byte(
total = (total + digit) * 2
end
Riga 26 ⟶ 27:
return "X"
end
return tostring(
end
-- Validate ISNI (and ORCID) and retuns it as a 16 characters string or returns false if it's invalid
-- See http://support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier
local function validateIsni(
id = id:gsub(
if not id:match(
return false
end
if getIsniCheckDigit(
return false
end
Riga 42 ⟶ 43:
end
local function splitLccn(
if id:match(
id = id:gsub(
end
if id:match(
return mw.text.split(
end
return false
Riga 65 ⟶ 66:
local f = {}
function f.viafLink(
if not string.match(
return false
end
return string.format(
end
function f.isniLink(
id = validateIsni(
if not id then
return false
end
return string.format(
end
function f.sbnLink(
if not string.match(
return false
end
return string.format(
end
function f.bncfLink(
if not tonumber(
return false
end
return string.format(
end
function f.europeanaLink(
if not string.match(
return false
end
return string.format(
end
function f.lccnLink(
local parts = splitLccn(
if not parts then
return false
end
local lccnType = parts[1] ~= 'sh' and 'names' or 'subjects'
id = parts[1] .. parts[2] .. append(
return string.format(
end
function f.orcidLink(
id = validateIsni(
if not id then
return false
end
id = id:sub(
return string.format(
end
function f.gndLink(
return string.format(
end
function f.bnfLink(
-- Add cb prefix if it has been removed
if not string.match(
id = 'cb' .. id
end
return string.format(
end
function f.bneLink(
return string.format(
end
function f.ulanLink(
return string.format(
end
function f.nlaLink(
return string.format(
end
function f.bavLink(
if not string.match(
return false
end
Riga 151 ⟶ 152:
end
function f.cerlLink(
if not string.match(
return false
end
return string.format(
end
function f.ndlLink(
if not string.match(
return false
end
return string.format(
end
function f.worldcatLink(
return string.format(
end
function f.vcbaLink(id)
if not string.match(id, '^%d%d%d/%d%d?%d?%d?%d?%d?$') then
return false
end
-- id = id:sub(1,3) .. '_' .. id:sub(5)
return string.format('[https://opac.vatlib.it/auth/detail/%s %s]', id:sub(1,3) .. '_' .. id:sub(5), id)
end
-------------------------------------------------------------------------------
-- Funzioni esportate
Riga 174 ⟶ 182:
local p = {}
-- Funzione di utilità per il manuale, restituisce un elenco degli identificativi.
function p.identifiers(frame)
local ret = {}
for _, params in ipairs(mw.text.jsonDecode(cfg)) do
local value, n = params.etichetta:gsub('|%u%u+', '')
if n > 0 then
value = string.format('%s (%s)', value, params.codice)
end
if frame.args.wikidata then
value = string.format('%s, su Wikidata [[d:P:P%s|P%s]]', value, params.P, params.P)
end
table.insert(ret, '* ' .. value)
end
return table.concat(ret, '\n')
end
-- Funzione per il template {{Controllo di autorità}}.
function p.authorityControl(
local elements, categories = {}, {}
local ret = ''
local styles = 'Modulo:Controllo di autorità/styles.css'
for _, params in
local val = mWikidata._getProperty({ 'P' .. params.P, n = 1 })
if val then
local el, cat
local link = f[params.funzione](
if link then
local lingue = params.lingue and (
el = string.format(
cat = string.format(
else
el = string.format(
cat = string.format(
end
table.insert(
table.insert(
end
end
if #elements > 0 then
ret = mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = styles } }
ret = ret .. string.format(
'[[Aiuto:Controllo di autorità|Controllo di autorità]]',
table.concat(
if mWikidata._instanceOf(
table.insert(
else
table.insert(
end
else
table.insert(
end
return ret .. (
end
|