Diferencia entre revisiones de «Módulo:Wikidata»
m Permitir ocultar vía CSS personal sólo el lápiz (sin quitar el enlace a Wikidata del pie de la tabla) |
m 485 revisiones importadas |
||
| (No se muestran 18 ediciones intermedias de 7 usuarios) | |||
| Línea 19: | Línea 19: | ||
========================================================================= `-- ]] | ========================================================================= `-- ]] | ||
local avisos = | local avisos = mw.loadData('Módulo:Wikidata/mensajes') | ||
-- Módulos y funciones utilizadas | -- Módulos y funciones utilizadas | ||
| Línea 42: | Línea 27: | ||
-- diferentes de Wikidata/Formatos | -- diferentes de Wikidata/Formatos | ||
-- | -- | ||
local modulosTipos = | local modulosTipos = mw.loadData('Módulo:Wikidata/modulosTipos') | ||
local modulosTiposComplejos = { | local modulosTiposComplejos = { | ||
| Línea 231: | Línea 204: | ||
function p.getPropiedad(opciones, declaracion) | function p.getPropiedad(opciones, declaracion) | ||
local propiedad = {} | local propiedad = {} | ||
if opciones.propiedad == 'precisión' or opciones.propiedad == 'latitud' or opciones.propiedad == 'longitud' then | -- Resolver alias de propiedad | ||
if opciones.propiedad == 'precisión' or opciones.propiedad == 'latitud' or opciones.propiedad == 'longitud' then --latitud, longitud o precisión | |||
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 249: | Línea 215: | ||
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 | elseif mw.wikibase.isValidEntityId(tostring(opciones.entityId)) and mw.wikibase.isValidEntityId(tostring(propiedad)) then | ||
tablaOrdenada = mw.wikibase.getAllStatements( opciones.entityId, mw.ustring.upper(propiedad) ) | |||
if not tablaOrdenada[1] then return '' end | |||
else | else | ||
return '' | return '' | ||
end | end | ||
-- Función que separa la cadena de texto 'inputstr' utilizando un separador 'sep' | |||
function split(inputstr, sep) | function split(inputstr, sep) | ||
sep=sep or '%s' | sep=sep or '%s' | ||
| Línea 271: | Línea 237: | ||
end | end | ||
tablaOrdenada = p.filtroDesconocidos(tablaOrdenada) | |||
-- Aplicar filtro de calificador | |||
if (opciones.filtroCalificador ~= nil and opciones.filtroCalificador ~= '') then | if (opciones.filtroCalificador ~= nil and opciones.filtroCalificador ~= '') then | ||
local opts = split(opciones.filtroCalificador, ';') | local opts = split(opciones.filtroCalificador, ';') | ||
local negative = false | |||
tablaOrdenada = p.filtroCalificadores(tablaOrdenada, opts[1], split(opts[2], ',')) | if (#opts > 2) then | ||
if (opts[3]=='n') then | |||
negative = true | |||
elseif (opts[3]=='p') then | |||
negative = false | |||
end | |||
end | |||
tablaOrdenada = p.filtroCalificadores(tablaOrdenada, opts[1], split(opts[2], ','), negative) | |||
end | end | ||
-- Aplicar filtro de valor | |||
if (opciones.filtroValor ~= nil and opciones.filtroValor ~= '') then | if (opciones.filtroValor ~= nil and opciones.filtroValor ~= '') then | ||
tablaOrdenada = p.filtroValores(tablaOrdenada, split( | local opts = split(opciones.filtroValor, ';') | ||
local negative = false | |||
if (#opts > 1) then | |||
if (opts[2]=='n') then | |||
negative = true | |||
elseif (opts[2]=='p') then | |||
negative = false | |||
end | |||
end | |||
tablaOrdenada = p.filtroValores(tablaOrdenada, split(opts[1], ','), negative) | |||
end | end | ||
-- Aplicar función de formato | |||
local modulo, funcion | local modulo, funcion | ||
funcion = opciones['valor-función'] or opciones['value-function'] or opciones['funcion'] | funcion = opciones['valor-función'] or opciones['value-function'] or opciones['funcion'] | ||
if funcion then | if funcion then | ||
modulo = modulosTiposComplejos[funcion] | modulo = modulosTiposComplejos[funcion] | ||
| Línea 298: | Línea 285: | ||
end | end | ||
-- | -- Aplicar filtro de mayor rango | ||
if (opciones.rangoMayor == 'sí') then | if (opciones.rangoMayor == 'sí') then | ||
tablaOrdenada = p.filtrarDeclaracionPorRango(tablaOrdenada) | tablaOrdenada = p.filtrarDeclaracionPorRango(tablaOrdenada) | ||
end | end | ||
-- | -- Ordenarsegún el calificador "orden dentro de la serie" | ||
if opciones.ordenar == 'sí' then | if opciones.ordenar == 'sí' then | ||
require('Módulo:Tablas').ordenar(tablaOrdenada, | require('Módulo:Tablas').ordenar(tablaOrdenada, | ||
| Línea 315: | Línea 302: | ||
end | end | ||
--Ordenar | --Ordenar según la fecha. [Véase la función chronosort de :fr:Module:Wikidata/Récup] | ||
if opciones.ordenar == 'por fecha' then | if opciones.ordenar == 'por fecha' then | ||
require('Módulo:Tablas').ordenar(tablaOrdenada, | require('Módulo:Tablas').ordenar(tablaOrdenada, | ||
| Línea 327: | Línea 314: | ||
end | end | ||
-- Si después de todo no queda nada en la tabla retornar | |||
if not tablaOrdenada[1] then | if not tablaOrdenada[1] then | ||
return | return | ||
| Línea 485: | 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 576: | Línea 564: | ||
========================================================================= `-- ]] | ========================================================================= `-- ]] | ||
function p.filtroCalificadores(t, qualifier, values) | function p.filtroCalificadores(t, qualifier, values, negativo) | ||
local f = {} -- Tabla que se devolverá con el resultado del filtrado | local f = {} -- Tabla que se devolverá con el resultado del filtrado | ||
for k,v in pairs(t) do | for k,v in pairs(t) do | ||
| Línea 590: | Línea 578: | ||
end | end | ||
end | end | ||
if counts then -- Si uno de los valores del cualificador dio true se inserta el elemento | if counts and not negativo then -- Si uno de los valores del cualificador dio true se inserta el elemento | ||
table.insert(f, v) | |||
elseif not counts and negativo then -- Si ninguno de los valores del cualificador dio true se inserta el elemento | |||
table.insert(f, v) | table.insert(f, v) | ||
end | end | ||
| Línea 602: | Línea 592: | ||
========================================================================= `-- ]] | ========================================================================= `-- ]] | ||
function p.filtroValores(t, values) | function p.filtroValores(t, values, negativo) | ||
local f = {} -- Tabla que se devolverá con el resultado del filtrado | local f = {} -- Tabla que se devolverá con el resultado del filtrado | ||
for k,v in pairs(t) do | for k,v in pairs(t) do | ||
| Línea 613: | Línea 603: | ||
end | end | ||
end | end | ||
if counts then -- Si uno de los valores dio true se inserta el elemento | if counts and not negativo then -- Si uno de los valores del cualificador dio true se inserta el elemento | ||
table.insert(f, v) | |||
elseif not counts and negativo then -- Si ninguno de los valores del cualificador dio true se inserta el elemento | |||
table.insert(f, v) | table.insert(f, v) | ||
end | end | ||
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 690: | Línea 715: | ||
if wValorCalificativoFormateado then | if wValorCalificativoFormateado then | ||
datoFormateado = p.formatoDato(declaracion.mainsnak, opciones) | datoFormateado = p.formatoDato(declaracion.mainsnak, opciones) | ||
-- Si el parámetro especificado era "|calificador="" no devolver propiedad y paréntesis | |||
if(opciones.calificador ~= nil and opciones.calificador ~= '') then | |||
return wValorCalificativoFormateado | |||
end | |||
-- Si el parámetro especificado era "|calificativo="" devolver propiedad y calificativo entre paréntesis | |||
return (datoFormateado and datoFormateado .. ' <small>(' .. wValorCalificativoFormateado .. ')</small>') or nil | return (datoFormateado and datoFormateado .. ' <small>(' .. wValorCalificativoFormateado .. ')</small>') or nil | ||
end | end | ||
| Línea 900: | 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 | |||
argumentos.entityId = mw.wikibase.getEntityIdForCurrentPage() or nil | |||
end | |||
valorWikidata = p.getPropiedad(argumentos, nil); | valorWikidata = p.getPropiedad(argumentos, nil); | ||
end | end | ||
| Línea 916: | 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 | ||