Mòdul:WikidataBox : Diferéncia entre lei versions

Contengut suprimit Contengut apondut
Boulaur (discussion | contribucions)
mCap resum de modificació
Boulaur (discussion | contribucions)
mCap resum de modificació
Linha 14 :
["novalue"] = "''no value''"
}
 
function getEntityFromId( id )
if id then
return mw.wikibase.getEntity( id )
end
return mw.wikibase.getEntity()
end
function getEntityIdFromValue( value )
local prefix = ''
if value['entity-type'] == 'item' then
prefix = 'Q'
elseif value['entity-type'] == 'property' then
prefix = 'P'
else
return formatError( 'unknown-entity-type' )
end
return prefix .. value['numeric-id']
end
function formatError( key )
return '<span class="error">' .. i18n.errors[key] .. '</span>'
end
function formatStatements( cadena, options )
local s = {} -- Esto es para que el índice 0 pase a ser 1. Necesario para que todo quede en el mismo orden que en ítem
for k, v in pairs(cadena) do
s[k+1] = v
end
local formattedStatements = {}
for i, statement in pairs(s) do
table.insert( formattedStatements, formatStatement( statement, options ) )
end
return mw.text.listToText( formattedStatements, options.separator, options.conjunction )
end
function formatStatement( statement, options )
if not statement.type or statement.type ~= 'statement' then
return formatError( 'unknown-claim-type' )
end
return formatSnak( statement.mainsnak, options )
--TODO reference and qualifiers
end
function formatSnak( snak, options )
if snak.snaktype == 'somevalue' then
return i18n['somevalue']
elseif snak.snaktype == 'novalue' then
return i18n['novalue']
elseif snak.snaktype == 'value' then
return formatDatavalue( snak.datavalue, options )
else
return formatError( 'unknown-snak-type' )
end
end
function formatDatavalue( datavalue, options )
--Use the customize handler if provided
if options['value-module'] or options['value-function'] then
if not options['value-module'] or not options['value-function'] then
return formatError( 'unknown-value-module' )
end
local formatter = require ('Module:' .. options['value-module'])
if formatter == nil then
return formatError( 'value-module-not-found' )
end
local fun = formatter[options['value-function']]
if fun == nil then
return formatError( 'value-function-not-found' )
end
return fun( datavalue.value, options )
end
--Default formatters
if options.property == 'latitud' then --Para las coordenadas
return datavalue.value['latitude']
elseif options.property == 'longitud' then
return datavalue.value['longitude']
elseif options.property == 'precisión' then
return datavalue.value['precision']
elseif datavalue.type == 'wikibase-entityid' then
return formatEntityId( getEntityIdFromValue( datavalue.value ), options )
elseif datavalue.type == 'string' then
return datavalue.value --TODO ids + media
elseif datavalue.value['latitude'] and datavalue.value['longitude'] then
return marco:preprocess('{{coord|' .. datavalue.value['latitude'] .. '|' ..
datavalue.value['longitude'] .. '|type:' .. options.tipo .. '|display=' ..
options.display ..'|format=' .. options.formato..'}}')
else
return formatError( 'unknown-datavalue-type' )
end
end
function formatEntityId( entityId, options )
local label = mw.wikibase.label( entityId )
local link = mw.wikibase.sitelink( entityId )
 
if link and options['link'] == '' then
if label then
return ' [[' .. link .. '|' .. label .. ']]'
else
return ' [[' .. link .. ']]'
end
end
if link and options['link'] == 'ligam' then
if label then
return ' [[' .. link .. '|' .. label .. ']]'
else
return ' [[' .. link .. ']]'
end
end
if link and options['link'] == 'model' then
if label then
return marco:preprocess('{{coord:' .. label .. '}}')
else
return marco:preprocess('{{coord:' .. link .. '}}')
end
end
if link and options['link'] == 'imatge' then
if label then
return ' [[Imatge:' .. link .. '|' .. label .. ']]'
else
return ' [[Imatge:' .. link .. ']]'
end
end
if link and options['link'] == 'categoria' then
if label then
return ' [[Categoria:' .. label .. ']]'
end
end
 
if link and options['link'] == 'non' then
if label then
return label
else
return entityId
end
else
if label then
return ' [[' .. label .. ']] [[d:' .. entityId .. '|(WikiData)]]'
else
return ' [[d:' .. entityId .. '|' .. entityId .. ']]'
end
end
end
 
local p = {}
Linha 28 ⟶ 175:
return '' --TODO error?
end
returna = formatStatements( cadena, frame.args )
return a
-- tab[1]= formatStatements( 'p1', 'link' )
-- tab[2]= formatStatements( 'p2', 'link' )