Difference between revisions of "Module:Wikibase signature"
Jump to navigation
Jump to search
module>Jeblad |
m (1 revision imported) |
(No difference)
|
Latest revision as of 05:53, 31 July 2020
This module is roughly the same as the documentation at mw:Extension:Wikibase Client/Lua. It is although not strictly the same, which makes it somewhat different from w:en:Module:Wikibase.
--- Get Wikibase items signatures
-- @license (CC-BY-SA-3.0)
-- @copyright John Erling Blad <jeblad@gmail.com>
-- @provenance https://en.wikipedia.org/w/index.php?title=Module:Wikibase&oldid=722062922
-- @var The table holding this modules exported members
local p = {}
--- get the item ID of the item linked to the current page
-- @param table frame from the call
-- @return string id of the item
function p.id(frame)
assert( mw.wikibase, "no mw.wikibase" )
frame = frame or mw.getCurrentFrame()
assert( frame, "no frame" )
if frame:getParent() then
frame = frame:getParent()
end
entity = mw.wikibase.getEntityObject()
assert( entity, "no entity" )
return entity.id
end
--- get the label of a given item, or of the connected page
-- if no argument is provided
-- @param table frame from the call
-- @return string label from the item
function p.label(frame)
assert( mw.wikibase, "no mw.wikibase" )
frame = frame or mw.getCurrentFrame()
assert( frame, "no frame" )
if frame:getParent() then
frame = frame:getParent()
end
if not frame.args[2] then
return mw.wikibase.label( frame.args[1] )
end
entity = mw.wikibase.getEntityObject( frame.args[1] )
assert( entity, "no entity" )
return entity:getLabel( frame.args[2] )
end
--- get the description of a given item, or of the connected page
-- if no argument is provided
-- @param table frame from the call
-- @return string description from the item
function p.description(frame)
assert( mw.wikibase, "no mw.wikibase" )
frame = frame or mw.getCurrentFrame()
assert( frame, "no frame" )
if frame:getParent() then
frame = frame:getParent()
end
if not frame.args[2] then
return mw.wikibase.description( frame.args[1] )
end
entity = mw.wikibase.getEntityObject( frame.args[1] )
assert( entity, "no entity" )
return entity:getDescription( frame.args[2] )
end
--- get the local page for a given item, or of the connected page
-- if no argument is provided
-- @param table frame from the call
-- @return string page title from the item
function p.page(frame)
assert( mw.wikibase, "no mw.wikibase" )
frame = frame or mw.getCurrentFrame()
assert( frame, "no frame" )
if frame:getParent() then
frame = frame:getParent()
end
if frame.args[1] and not frame.args[2] then
return mw.wikibase.sitelink( frame.args[1] )
end
entity = mw.wikibase.getEntityObject( frame.args[1] )
assert( entity, "no entity" )
return entity:getSitelink( frame.args[2] )
end
return p