Modulo:Wikidata/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
+controllo getLabel
aggiunta funzione getDatatype
Riga 580:
return entityId:sub(1, 1) == 'Q' and formatEntityId(entityId) or nil
end
 
-- Ritorna il datatype di una proprietà Wikidata.
function p._getDatatype(args)
local ret, property, entity, datatype
 
-- parametri posizionali
property = args[1] and string.upper(args[1]) or nil
if not property then
error(i18n.errors['property-param-not-provided'], 2)
end
 
entity = mw.wikibase.getEntityObject(property)
if not entity then
error(i18n.errors['entity-not-found'], 2)
end
 
datatype = entity.datatype
if datatype == 'commonsMedia' then
ret = 'file multimediale su Commons'
elseif datatype == 'globe-coordinate' then
ret = 'coordinate geografiche'
elseif datatype == 'monolingualtext' then
ret = 'testo monolingua'
elseif datatype == 'quantity' then
ret = 'quantità'
elseif datatype == 'string' then
ret = 'stringa'
elseif datatype == 'time' then
ret = 'data e ora'
elseif datatype == 'url' then
ret = 'URL'
elseif datatype == 'wikibase-item' then
ret = 'elemento'
else
error(i18n.errors['unknown-datavalue-type'], 2)
end
 
return ret
end
 
Riga 628 ⟶ 667:
return select(2, xpcall(function()
return p._instanceOf(getArgs(frame, {parentOnly = true})) and 1 or 0
end, errhandler))
end
 
-- Entry-point per {{WikidataTipo}}
function p.getDatatype(frame)
return select(2, xpcall(function()
return p._getDatatype(getArgs(frame, {parentOnly = true}))
end, errhandler))
end