Module:Wikibase

Diyila Dagbani Wikipedia
Yiɣi chaŋ yaɣa shɛli Yiɣi chaŋ vihigu ni

Documentation for this module may be created at Module:Wikibase/doc

-- Module:Wikibase
local p = {}
 
-- Return the item ID of the item connected to the current page or connected to a page title via a sitelink.
-- mw.wikibase.getEntityIdForCurrentPage, mw.wikibase.getEntityIdForTitle
function p.id(frame)
	local page_title = frame.args[1] and mw.text.trim(frame.args[1])
	if page_title == nil or page_title == '' then
		return mw.wikibase.getEntityIdForCurrentPage()
	end
	return mw.wikibase.getEntityIdForTitle(page_title)
end
 
-- Return the label of a given data item.
function p.label(frame)
    if frame.args[1] == nil then
        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
 
-- Return the local page about a given data item.
function p.page(frame)
    if frame.args[1] == nil then
        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
 
-- Return the first value of given property of the item linked to the current page.
function p.firstproperty(frame)
    local property = frame.args[1]
    local entity = mw.wikibase.getEntityObject()
    if not entity then return nil end
    if not entity.claims then return nil end
    local hasProp = entity.claims[property]
    if not hasProp then return nil end
    return hasProp[0].mainsnak.datavalue.value
end
 
return p