Diferencia entre revisiones de «Módulo:Wikidata»

1046 bytes añadidos ,  4 marzo
m
1 revisión importada
m (1 revisión importada)
m (1 revisión importada)
 
(No se muestran 8 ediciones intermedias de 3 usuarios)
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 244: Línea 242:
end  
end  
end
end
tablaOrdenada = p.filtroDesconocidos(tablaOrdenada)
-- Aplicar filtro de calificador
-- Aplicar filtro de calificador
Línea 616: Línea 616:
end
end
return f
return f
end
--[[ =========================================================================
Función que filtra los valores de una propiedad y devuelve solo los que
tengan formatos de valor, omitiendo los de formato desconocido o sin valor
========================================================================= `-- ]]
function p.filtroDesconocidos(t)
for k,v in pairs(t) do
if(v["mainsnak"]["snaktype"] ~= "value") then
t[k] = nil
end
local qual = v["qualifiers"]
if(qual ~= nil) then
for qualk,qualv in pairs(qual) do
local prop = qualv
for propk,propv in pairs(prop) do
if(propv["snaktype"] ~= "value") then
prop[propk] = nil
-- same as: qual[prop] = nil
-- same as: t["qualifiers"][prop] = nil
end
end
if #prop == 0 then
prop = nil
qual[qualk] = nil
end
end
if #qual == 0 then
qual = nil
end
end
end
return t
end
end


Línea 904: Línea 937:
local valorWikidata;
local valorWikidata;
if (args.prioridad ~= 'sí' or (args.importar and args.importar == 'no')) and args.valor and args.valor ~= '' then
if (args.prioridad ~= 'sí' or (args.importar and args.importar == 'no')) and args.valor and args.valor ~= '' then
valorWikidata = '';
valorWikidata = nil;
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
Línea 920: Línea 954:
  and string.upper(args.propiedad) ~= 'P109' -- P109: firma de persona
  and string.upper(args.propiedad) ~= 'P109' -- P109: firma de persona
  and string.upper(args.propiedad) ~= 'P154') then -- P154: logotipo
  and string.upper(args.propiedad) ~= 'P154') then -- P154: logotipo
if valorWikidata ~= '' and args.valor and args.valor ~= '' then
if valorWikidata and valorWikidata ~= '' and args.valor and args.valor ~= '' then
categorias = '[[Categoría:Wikipedia:Artículos con datos locales]]'
categorias = '[[Categoría:Wikipedia:Artículos con datos locales]]'
elseif valorWikidata and valorWikidata == '' and args.valor and args.valor ~= '' and
elseif valorWikidata and valorWikidata == '' and args.valor and args.valor ~= '' and
(not args.calificador or args.calificador == '') and
(not args.calificador or args.calificador == '') and
(not args.dato or args.dato == '' or args.dato ~= 'fuente')then
(not args.dato or args.dato == '' or args.dato ~= 'fuente') then
categorias = '[[Categoría:Wikipedia:Artículos con datos por trasladar a Wikidata]]'
categorias = '[[Categoría:Wikipedia:Artículos con datos por trasladar a Wikidata]]'
end
end
end
end


if args.prioridad == 'sí' and valorWikidata ~= '' then -- Si se da el valor sí a prioridad tendrá preferencia el valor de Wikidata
if args.prioridad == 'sí' and valorWikidata and valorWikidata ~= '' then -- Si se da el valor sí a prioridad tendrá preferencia el valor de Wikidata
if args.importar and args.importar == 'no' and args.valor and args.valor ~= '' then
if args.importar and args.importar == 'no' and args.valor and args.valor ~= '' then
return args.valor .. categorias
return args.valor .. categorias
MediaWiki spam blocked by CleanTalk.