Modulo:Sandbox/ValterVB/Link

local getArgs = require('Module:Arguments').getArgs
local p = {}
local wikis = {
    ['w'] = 'wiki',
    ['n'] = 'wikinews',
    ['b'] = 'wikibooks',
    ['q'] = 'wikiquote',
    ['s'] = 'wikisource',
    ['v'] = 'wikiversity',
    ['voy'] = 'wikivoyage',
    ['c'] = 'commonswiki',
    ['d'] = 'wikidatawiki',
    ['species'] = 'specieswiki'
}

function p.Link(frame)
    local t = getArgs(frame)
    local itemId = t[1]
    local progetto = t[2]
    local lingua = t[3] or ""
    local nolink = t.nolink or false
    local piped = t.piped or false
    
    if wikis[progetto] ~= nil then
      globalSiteId = lingua .. wikis[progetto]
    end
    
    if globalSiteId ~= nil then
      local title = mw.wikibase.getSitelink( itemId, globalSiteId )
      
      if nolink and nolink ~= "" then
      	return title
      else
      	if (lingua  == nil or lingua  == '') then
          target = ':' .. progetto .. ':' .. title
        else
          target = ':' .. progetto .. ':' .. lingua .. ':' .. title
        end
        
        if piped and piped ~= "" then
          return '[[' .. target .. '|' .. title .. ']]'
        else
          return '[[' .. target .. ']]'
        end
      end
    end
    
    return nil
end
 
return p