Module:Sandbox/Was a bee/getLinkedName
Yi palo
Documentation for this module may be created at Module:Sandbox/Was a bee/getLinkedName/doc
local p = {}
function p.rmvDisambigBracket ( text )
text = string.gsub( text, '%s%(.+%)$', '' )
return text
end
function p.getLinkedName( frame )
local id = frame.args[1]
local alias = frame.args['alias']
if id == nil or id == '' then
--If QID is not defined, using the QID of the item which is connected to the current page.
id = mw.wikibase.getEntityIdForCurrentPage()
if not id then
return 'No item passed as parameter' --If there is no connected wikidata page, abort.
end
end
if tonumber(id) then --legacy format
id = 'Q'.. tostring(id)
end
local lang = mw.language.getContentLanguage().code
local globalSiteId = lang .. 'wiki'
local entity = mw.wikibase.getEntity( id )
local content
local currentText = nil
local currentText_NoBracket = nil
currentText = entity:getSitelink( globalSiteId )
if currentText ~= nil then
if alias ~= nil and alias ~= '' then
currentText_NoBracket = alias
else
currentText_NoBracket = p.rmvDisambigBracket(currentText)
end
content = '[[:' .. lang .. ':' .. currentText .. '|' .. currentText_NoBracket .. ']]'
return content ---- 1. [[:en:Sitelink|Sitelink]] style
else
currentText = entity:getLabelWithLang(lang)
if currentText ~= nil then
content = '[[:' .. lang .. ':' .. currentText .. '|' .. currentText .. ']]'
return content ---- 2. [[:en:Label|Label]] style
else
content = id .. ' ' .. '[[File:Blue pencil.svg|frameless|text-top|10px|link=https://www.wikidata.org/wiki/' .. id .. ']]'
return content ---- 3. Q123456 style
end
end
end
return p