Diferencia entre revisiones de «Módulo:Wikidata»
m Deshecha la edición 150888530 de Leoncastro (disc.) |
m 485 revisiones importadas |
||
| (No se muestran 6 ediciones intermedias de 4 usuarios) | |||
| Línea 207: | Línea 207: | ||
-- Resolver alias de propiedad | -- Resolver alias de propiedad | ||
if opciones.propiedad == 'precisión' or opciones.propiedad == 'latitud' or opciones.propiedad == 'longitud' then --latitud, longitud o precisión | if opciones.propiedad == 'precisión' or opciones.propiedad == 'latitud' or opciones.propiedad == 'longitud' then --latitud, longitud o precisión | ||
propiedad = 'P625' | |||
propiedad = 'P625' | |||
else | else | ||
propiedad = opciones.propiedad -- En el resto de casos se lee lo dado | propiedad = opciones.propiedad -- En el resto de casos se lee lo dado | ||
| Línea 226: | Línea 220: | ||
elseif mw.wikibase.isValidEntityId(tostring(opciones.entityId)) and mw.wikibase.isValidEntityId(tostring(propiedad)) then | elseif mw.wikibase.isValidEntityId(tostring(opciones.entityId)) and mw.wikibase.isValidEntityId(tostring(propiedad)) then | ||
tablaOrdenada = mw.wikibase.getAllStatements( opciones.entityId, mw.ustring.upper(propiedad) ) | tablaOrdenada = mw.wikibase.getAllStatements( opciones.entityId, mw.ustring.upper(propiedad) ) | ||
if not tablaOrdenada[1] then return '' end | |||
else | else | ||
return '' | return '' | ||
| Línea 241: | Línea 236: | ||
end | end | ||
end | end | ||
tablaOrdenada = p.filtroDesconocidos(tablaOrdenada) | |||
-- Aplicar filtro de calificador | -- Aplicar filtro de calificador | ||
| Línea 476: | Línea 473: | ||
valor = elementoTabla(v,'mainsnak', 'datavalue', 'value') | valor = elementoTabla(v,'mainsnak', 'datavalue', 'value') | ||
if valor.language == 'es' then | if valor and valor.language == 'es' then | ||
return valor.text | return valor.text | ||
end | end | ||
| Línea 613: | Línea 610: | ||
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 901: | Línea 931: | ||
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 | ||
if not mw.wikibase.isValidEntityId(tostring(argumentos.entityId)) then | if not mw.wikibase.isValidEntityId(tostring(argumentos.entityId)) then | ||
| Línea 918: | Línea 948: | ||
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 | 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 | ||