Diferencia entre revisiones de «Módulo:EnlaceWikidata»
New module to handle Wikidata links |
Enhanced Wikidata Link Module |
||
| Línea 3: | Línea 3: | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame.args | local args = frame.args | ||
-- Soporte para argumentos posicionales (desde plantilla) o nombrados | |||
local id = args.id or args[1] | local id = args.id or args[1] | ||
local label = args.label or args[2] | |||
if not id or id == '' then | if not id or id == '' then | ||
return '' | return '' | ||
end | end | ||
id = mw.text.trim(id) | id = mw.text.trim(id) | ||
-- | -- Si no se pasa etiqueta, usamos el propio ID | ||
if not label or label == '' then | |||
label = id | |||
end | |||
-- Detectar si es Propiedad (P) o Ítem (Q) | |||
local prefix = string.sub(id, 1, 1):upper() | |||
local url | |||
if prefix == 'P' then | |||
url = 'https://www.wikidata.org/wiki/Property:' .. id | |||
else | |||
-- Asumimos Q o ID numérico directo | |||
url = 'https://www.wikidata.org/wiki/' .. id | |||
end | |||
return string.format('[%s %s]', url, label) | |||
end | end | ||
return p | return p | ||
Revisión actual - 13:02 15 feb 2026
A
local p = {}
function p.main(frame)
local args = frame.args
-- Soporte para argumentos posicionales (desde plantilla) o nombrados
local id = args.id or args[1]
local label = args.label or args[2]
if not id or id == '' then
return ''
end
id = mw.text.trim(id)
-- Si no se pasa etiqueta, usamos el propio ID
if not label or label == '' then
label = id
end
-- Detectar si es Propiedad (P) o Ítem (Q)
local prefix = string.sub(id, 1, 1):upper()
local url
if prefix == 'P' then
url = 'https://www.wikidata.org/wiki/Property:' .. id
else
-- Asumimos Q o ID numérico directo
url = 'https://www.wikidata.org/wiki/' .. id
end
return string.format('[%s %s]', url, label)
end
return p