Module:UserLinks: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(save initial version - user talk links only for the moment)
 
(output user links)
Line 1: Line 1:
p = {}
p = {}


local toolbar = require('Module:Toolbar')
local ToolbarBuilder = require('Module:Toolbar')
local project, username
local project, username

local function makeUserLink()
return '[[' .. project .. 'User:' .. username .. '|' .. username .. ']]'
end


local function makeTalkLink()
local function makeTalkLink()
local plink = (project and (':' .. project .. ':')) or ''
return '[[' .. project .. 'User talk:' .. username .. '|talk]]'
return '[[' .. plink .. 'User talk:' .. username .. '|talk]]'
end
end


Line 18: Line 21:
local function makeToolbar(args)
local function makeToolbar(args)
local targs = {}
local targs = {}
local numArgsExist = false
for k, v in pairs(args) do
for k, v in pairs(args) do
if type(k) == 'number' then
if type(k) == 'number' then
numArgsExist = true
targs[k] = getLink(v)
targs[k] = getLink(v)
end
end
Line 25: Line 30:
targs.style = args.small and 'font-size: 90%;'
targs.style = args.small and 'font-size: 90%;'
targs.separator = args.separator or 'dot'
targs.separator = args.separator or 'dot'
return toolbar.main(targs)
if numArgsExist == false then
return -- Don't return a toolbar if no numeric arguments exist.
else
return ToolbarBuilder.main(targs)
end
end
end


local function getLinks(args)
local function getLinks(args)
-- If the username is absent or blank, return an html error and a tracking category.
-- Get the username value. If it is absent or blank, return an html error and a tracking category.
if args.user == '' or (not args.user and (not args.User or args.User == '')) then
if args.user == '' or (not args.user and (not args.User or args.User == '')) then
return '<span class="error">Error: No username detected by [[Module:UserLinks]].</span>[[Category:UserLinks transclusions without usernames]]'
return '<span class="error">Error: No username detected by [[Module:UserLinks]].</span>[[Category:UserLinks transclusions without usernames]]'
Line 35: Line 45:
username = args.user or args.User
username = args.user or args.User
end
end
-- Get the values of the other module-wide variables.
-- Get the project value.
project = args.Project
if args.Project then
small = args.small
project = ':' .. args.Project .. ':'
else
separator = args.separator
project = ''
end
return makeToolbar(args)
local result = makeToolbar(args)
if result then
if args.sup then
result = '<sup>' .. result .. '</sup>'
end
result = '&nbsp;' .. result
else
result = ''
end
result = '<span>' .. makeUserLink() .. result .. '</span>'
return result
end
end