Siirry sisältöön

Moduuli:Wikibase

Tämä moduuli on osittain suojattu muutoksilta.
Wikipediasta


-- Module:Wikibase
require('strict')
local p = {}
 
-- Palauta kyseisen sivun Wikidata-kohteen tunniste (id, "q-koodi").
function p.id(frame)
        if not mw.wikibase then
           return "wikibase module not found"
        end
 
        local entity = mw.wikibase.getEntityObject()
        if entity == nil then
           return "(ei aiheeseen liittyvää Wikidata-kohdetta)"
        end
 
        return entity.id
end

-- Return the item ID of the item linked to the specified page.
function p.idForTitle(frame)
	if not mw.wikibase then
		return "no mw.wikibase"
	end
	local qid
	if not frame.args[1] then
		qid = mw.wikibase.getEntityIdForCurrentPage() -- default the item connected to the current page
	else
		qid = mw.wikibase.getEntityIdForTitle(mw.text.trim(frame.args[1]))
	end
	return qid or "no entity"
end

-- Palauta annetun datakohteen nimi.
function p.label(frame)
		local id;
        if frame.args[1] == nil then
            local entity = mw.wikibase.getEntityObject()
            if not entity then 
            	return nil 
            end
 
            id = entity.id
        else
            id = frame.args[1]
        end
 
        return mw.wikibase.label( id )
end
 
-- Palauta annetun Wikidata-kohteen paikallinen sivu.
function p.page(frame)
		local id;
        if frame.args[1] == nil then
            local entity = mw.wikibase.getEntityObject()
            if not entity then 
            	return nil 
            end
 
            id = entity.id
        else
            id = frame.args[1]
        end
 
        return mw.wikibase.sitelink( id )
end

-- Palauta annetun Wikidata-kohteen kuvailu.
function p.description(frame)
		local id;
        if frame.args[1] == nil then
            local entity = mw.wikibase.getEntityObject()
            if not entity then 
            	return nil 
            end
 
            id = entity.id
        else
            id = frame.args[1]
        end
 
        return mw.wikibase.description( id )
end

-- Return the data type of a property given its entity ID.
function p.datatype(frame)
	local prop = mw.wikibase.getEntity(frame.args[1] and mw.text.trim(frame.args[1]):upper():gsub('PROPERTY:P', 'P')) -- trim and remove any "Property:" prefix
	return prop and prop.datatype
end
 
return p