Modulo:Sandbox/ValterVB: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
.
 
(51 versioni intermedie di 2 utenti non mostrate)
Riga 1:
local getArgs = require('Module:Arguments').getArgs
local p = {}
 
function p.IMDbmain(frame)
local tipot = getArgs(frame.args['tipo'])
local iddato = frame.argst['id'1]
local pagina = mw.title.getCurrentTitle() --nome della pagina
local entity2= mw.wikibase.getEntity( dato )
local wdIMDb = formatStatements({property=p345}) -- recupera il codice IMDb da Wikidata
local count = 0
 
local ris = '[[File:Wikidata-logo.svg|20px]] Su Wikidata: '
local result = '* (\'\'\'EN\'\'\') Scheda su \'\'[http://www.imdb.com/'
if tipo == 'titolo' or tipo == 'film' then
if dato == nil then
tipo = 'title/tt'
ris = ris .. 'n° item mancante'
elseif tipo == 'compagnia' then
else
tipo = 'company/co'
if elseif tipoentity2 == 'nome'nil then
ris = ris..'Non esiste'
tipo = 'name/nm'
else
elseif tipo == 'personaggio' then
ris = ris..'[[:D:' .. dato .. '|' .. dato .. ']] - N° di link: '
tipo = 'character/ch'
if entity2.sitelinks == nil then
end
ris = ris..'nessuno'
else
result = result .. tipo .. id
for _ in pairs(entity2.sitelinks) do
result = result .. '/ '
count=count+1
result = result .. pagina.text
end
result = result .. ']\'\' dell\'\[\[Internet Movie Database\]\]'
ris = ris..count
return wdIMDb
end
end
end
return ris
end
 
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 "Tipo di entità sconosciuta."
end
return prefix .. value['numeric-id']
end
 
function formatStatements( options )
--Get entity
local entity = getEntityFromId( 345 )
if not entity then
return "Entità non trovata."
end
if (entity.claims == nil) or (not entity.claims[options.property]) then
return '' --TODO error?
end
--Format statement and concat them cleanly
local formattedStatements = {}
for i, statement in pairs( entity.claims[options.property] ) 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 datavalue.type == 'wikibase-entityid' then
return formatEntityId( getEntityIdFromValue( datavalue.value ), options )
elseif datavalue.type == 'string' then
return datavalue.value --TODO ids + media
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 then
if label then
return '[[' .. link .. '|' .. label .. ']]'
else
return '[[' .. link .. ']]'
end
else
return label --TODO what if no links and label + fallback language?
end
end
 
 
return p