Módulo:Wikibase: diferenças entre revisões

Conteúdo apagado Conteúdo adicionado
Giro720 (discussão | contribs)
update
m adotando código do en.wikisource
Linha 1:
---------- Module:Wikibase ----------------
require('Module:No globals')
local p = {}
 
-- Return the itementity ID of the item linked to the current page.
function p.id(frame)
if not mw.wikibase then
return "no mw.wikibase"
end
entity =return mw.wikibase.getEntityObjectgetEntityIdForCurrentPage() or "no entity"
 
if entity == nil then
return "no entity"
end
return entity.id
end
 
-- Return the WD entity URL of aan entity given dataits item, or of connectedentity pageID
-- or the item linked to the current page if no argument is provided to this method.
function p.wdurl(frame)
return mw.wikibase.getEntityUrl(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to entity URL of the item linked to the current page
if frame.args[1] == nil then
entity = mw.wikibase.getEntityObject()
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.getEntityUrl( id )
end
 
-- Return the label of aan entity given data item, or ofits connectedentity pageID
-- or the item linked to the current page if no argument is provided to this method.
function p.label(frame)
return mw.wikibase.getLabel(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to label of the item linked to the current page
if frame.args[1] == nil then
entity = mw.wikibase.getEntityObject()
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.label( id )
end
 
-- Return the description of aan entity given data item, or ofits connectedentity pageID
-- or the item linked to the current page if no argument is provided to this method.
function p.description(frame)
return mw.wikibase.getDescription(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to description of the item linked to the current page
if frame.args[1] == nil then
entity = mw.wikibase.getEntityObject()
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.description( id )
end
 
-- Return the local pagetitle aboutof a given dataan item, orgiven ofits connectedentity pageID
-- or the item linked to the current page if no argument is provided.
-- if id is not specified.
function p.page(frame)
iflocal qid = frame.args[1] ==and nil thenmw.text.trim(frame.args[1])
if entitynot qid or qid == nil'' then
entity = mw.wikibase.getEntityObject()
qid = mw.wikibase.getEntityIdForCurrentPage() -- default the item connected to the current page
if not entity then return nil end
id = entity.id
else
id = mw.text.trim(frame.args[1])
end
return mw.wikibase.sitelinkgetSitelink(qid idor '') -- requires one string arg
end
 
-- Return the data type of a property given its entity ID.
function p.datatype(frame)
iflocal prop = mw.wikibase.getEntity(frame.args[1] and stringmw.findtext.trim(frame.args[1]):upper():gsub('PROPERTY:P', 'P')) -- trim and remove any "Property:P") thenprefix
return prop and prop.datatype
if mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P")) then
return mw.wikibase.getEntityObject(string.gsub(frame.args[1], "Property:P", "P") ).datatype
end
elseif frame.args[1] and string.find(frame.args[1], "P") then
if mw.wikibase.getEntityObject(frame.args[1]) then
return mw.wikibase.getEntityObject(frame.args[1]).datatype
end
end
end