Module:Wikibase/sandbox
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Wikibase/sandbox/doc
---------- Module:Wikibase ----------------
local p = {}
-- Return the entity ID of the item linked to the current page.
function p.id(frame)
if not mw.wikibase then
return "no mw.wikibase"
end
eid = mw.wikibase.getEntityIdForCurrentPage()
return eid or "no entity"
end
-- Return the WD entity URL of a given entity ID, or item for current page
-- if no argument is provided to this method.
function p.wdurl(frame)
eid = frame.args[1]
eid = eid and mw.text.trim( eid )
return mw.wikibase.getEntityUrl( eid ) -- defaults to URL of the item connected to the current page
end
-- Return the label of a given entity ID, or item for current page
-- if no argument is provided to this method.
function p.label(frame)
eid = frame.args[1]
eid = eid and mw.text.trim( eid )
return mw.wikibase.getLabel( eid ) -- defaults to label of the item connected to the current page
end
-- Return the description of a given entity ID, or item for current page
-- if no argument is provided to this method.
function p.description(frame)
eid = frame.args[1]
eid = eid and mw.text.trim( eid )
return mw.wikibase.getDescription( eid ) -- defaults to description of the item connected to the current page
end
-- Return the local sitelink of a given entity ID, or item for current page
-- if no argument is provided to this method.
function p.page(frame)
eid = frame.args[1] or mw.wikibase.getEntityIdForCurrentPage()
eid = eid and mw.text.trim( eid )
if eid == '' then
eid = nil
end
return eid and mw.wikibase.getSitelink( eid )
end
-- Return the data type of a property given its entity ID
function p.datatype(frame)
pid = frame.args[1]
pid = pid and mw.text.trim( eid )
pid = pid and string.gsub( string.upper(pid), 'PROPERTY:P', 'P') -- capitalize and remove "Property:" prefix
prop = mw.wikibase.getEntity( pid )
if prop and prop.datatype then
return prop.datatype
end
end
return p