Ir al contenido

Diferencia entre revisiones de «Módulo:Wikidata»

53 bytes añadidos ,  17 may 2023
Devolver cadena vacía en lugar de nil cuando la propiedad no está definida en Wikidata, como se hacía antes. Ver Especial:EnlacePermanente/151214156#Población en la Ficha de localidad de España.
Sin resumen de edición
(Devolver cadena vacía en lugar de nil cuando la propiedad no está definida en Wikidata, como se hacía antes. Ver Especial:EnlacePermanente/151214156#Población en la Ficha de localidad de España.)
Línea 152: Línea 152:
-- == Comprobamos que existe un ítem enlazado a la página en Wikidata ==
-- == Comprobamos que existe un ítem enlazado a la página en Wikidata ==
if not pcall (SelecionEntidadPorId, entityId ) then
if not pcall (SelecionEntidadPorId, entityId ) then
return ''
return false
end
end
local entidad  = SelecionEntidadPorId(entityId)
local entidad  = SelecionEntidadPorId(entityId)
Línea 204: Línea 204:
function p.getPropiedad(opciones, declaracion)
function p.getPropiedad(opciones, declaracion)
local propiedad = {}
local propiedad = {}
local tablaOrdenada = {}


-- Resolver alias de propiedad
-- Resolver alias de propiedad
Línea 222: Línea 221:
return formatoError( 'property-param-not-provided' )
return formatoError( 'property-param-not-provided' )
end
end
 
local tablaOrdenada
if declaracion then
if declaracion then
tablaOrdenada = declaracion
tablaOrdenada = declaracion
elseif not p.getDeclaraciones(opciones.entityId) then
elseif mw.wikibase.isValidEntityId(tostring(opciones.entityId)) and mw.wikibase.isValidEntityId(tostring(propiedad)) then
return formatoError( 'other entity' )
tablaOrdenada = mw.wikibase.getAllStatements( opciones.entityId, mw.ustring.upper(propiedad) )
elseif p.getDeclaraciones(opciones.entityId)[mw.ustring.upper(propiedad)] then
if not tablaOrdenada[1] then return '' end
tablaOrdenada = p.getDeclaraciones(opciones.entityId)[mw.ustring.upper(propiedad)]
else
else
return ''
return ''
Línea 906: Línea 904:
valorWikidata = '';
valorWikidata = '';
else
else
local ent = SelecionEntidadPorId(argumentos.entityId)
if not mw.wikibase.isValidEntityId(tostring(argumentos.entityId)) then
argumentos.entityId = ent and ent.id or nil
argumentos.entityId = mw.wikibase.getEntityIdForCurrentPage() or nil
end
valorWikidata = p.getPropiedad(argumentos, nil);
valorWikidata = p.getPropiedad(argumentos, nil);
end
end
Usuario anónimo