Módulo:Wikibase

Fonte: Wikivoyage
Esta página ainda não foi traduzida completamente de outro idioma-- confira a fonte na lista na página da Expedição de tradução. Se puder, complete a tradução ou reescreva a página, eliminando o texto em língua estrangeira que for traduzido. Por favor, não use tradutores automáticos.

This module is a package of functions for accessing Wikidata properties which cannot be accessed with #property.

Code Returns
{{#invoke:wikibase|capital}} name of the "capital" property as listed in the Wikidata item associated with the current page, displayed as a link
{{#invoke:wikibase|commonslink}} name of the Wikimedia Commons category, as listed in the Wikidata item associated with the current page
{{#invoke:wikibase|disambig}} true if the Wikidata item corresponds to a Wikipedia disambiguation page
false if it does not
{{#invoke:wikibase|flag}} filename listed under the "flag" property in the Wikidata item associated with the current page
{{#invoke:wikibase|id}} ID number of the Wikidata item associated with the current page
{{#invoke:wikibase|idLink}} ID number of the Wikidata item associated with the current page, in the form of a link to that item
{{#invoke:wikibase|label}} label of the Wikidata item associated with the current page
{{#invoke:wikibase|latitude}} decimal latitude as listed in the Wikidata item associated with the current page
{{#invoke:wikibase|longitude}} decimal longitude as listed in the Wikidata item associated with the current page
{{#invoke:wikibase|page|Qxxxxx}} name of the local page associated with Wikidata item number Qxxxxx
{{#invoke:wikibase|sitelink|enwiki}} name of the English Wikipedia page name, as listed in the Wikidata item associated with the current page
enwiki can be replaced with other language codes to obtain corresponding page names for Wikipedia or Wikivoyage in other languages

-- Module:Wikibase
function getId( id )
    if not mw.wikibase then
           return "módulo wikibase não encontrado"
    end
    
    if id then return id end
    
    entity = mw.wikibase.getEntityObject()
    if not entity then return nil end
    return entity.id
end

local p = {}

-- Restituisce l'ID dell'elemento collegato alla pagina corrente.
function p.id(frame)
    id = getId(frame.args[1])
    if id == nil then
           return "(nenhum elemento encontrado)"
    end
    return id
end


-- Restituisce l'ID dell'elemento collegato alla pagina corrente sotto forma di link a Wikidata.
function p.idLink(frame)
    id = getId(frame.args[1])
    if id == nil then
           return "(nenhum elemento encontrado)"
    end
    return "[[d:" .. id .. "|" .. string.upper(id) .. "]]"
end


-- Restituisce l'etichetta di un elemento.
function p.label(frame)
    id = getId(frame.args[1])
    if id == nil then
           return "(nenhum elemento encontrado)"
    end
    return mw.wikibase.label( id )
end
 
-- Restituisce la pagina locale dell'elemento di Wikidata fornito.
function p.page(frame)
    id = getId(frame.args[1])
    if id == nil then
           return "(nenhum elemento encontrado)"
    end
    return mw.wikibase.sitelink( id )
end

function p.sitelink(frame)
    sl = mw.wikibase.getEntityObject()
    if sl and sl.sitelinks[frame.args.dbname] then
        return sl.sitelinks[frame.args.dbname].title
    end
    return ''
end

-- Restituisce le coordinate geografiche corrispondenti all'elemento.
function p.coords(typ,fallback)
    if fallback~='' and string.match(fallback, '^<%!%-%-[%w%s]%-%->$')==nil then
        return fallback
    end
    local item = mw.wikibase.getEntityObject()
    if item~=nil then
        local coords = item.claims.P625
        if coords~=nil and coords[1]~=nil and coords[2]==nil then
            return coords[1].mainsnak.datavalue.value[typ]
        end
    end
    return ''
end
 
function p.latitude(frame)
    return p.coords('latitude',frame.args[1])
end
 
function p.longitude(frame)
    return p.coords('longitude',frame.args[1])
end

function p.disambig(frame)
	local item = mw.wikibase.getEntityObject()
	if item~=nil and item.descriptions~=nil then
		local desc = item.descriptions.en
		if desc~=nil and desc.value~=nil and desc.value:lower():find('disambiguation page')~=nil then
			return true
					end
	end
	return false
end

function p.instanceof(frame)
	local arg = tonumber(frame.args[1])
	local item = mw.wikibase.getEntityObject()
	if item~=nil and item.claims~=nil and item.claims.P31~=nil then
		local claims=item.claims.P31
		for index,claim in pairs(claims) do
			if claim.mainsnak~=nil and claim.mainsnak.datavalue~=nil then
				local val = claim.mainsnak.datavalue.value
				if val~=nil and val['numeric-id']~=nil and arg==val['numeric-id'] then
					return true
				end
			end
		end
	end
	return false
end

return p