Module:UserLinks: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(add the rest of the link types, remove wiki-encoded username as I ended up not using it at all)
(fix bug where the username error wasn't showing up properly, add more comments)
Line 160: Line 160:


local function generateUserDataStrings(args)
local function generateUserDataStrings(args)
-- Username helper strings.
-------------------------------------------------
u.username = args.user or args.User
-- Username helper strings --
-------------------------------------------------
-- 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
return '<span class="error">Error: No username detected by [[Module:UserLinks]].</span>[[Category:UserLinks transclusions without usernames]]'
else
u.username = args.user or args.User
end
u.usernameHtml = mw.uri.encode(u.username) -- Html-encoded username. Spaces are encoded as pluses.
u.usernameHtml = mw.uri.encode(u.username) -- Html-encoded username. Spaces are encoded as pluses.
-- Project helper strings.
u.project = args.Project
-------------------------------------------------
-- Project helper strings --
-------------------------------------------------
u.project = args.Project -- Get the project value.
u.projectColon = (u.project and (':' .. args.Project .. ':')) or '' -- Project value plus colons, for escaping interwiki links.
u.projectColon = (u.project and (':' .. args.Project .. ':')) or '' -- Project value plus colons, for escaping interwiki links.
u.project = u.project or '' -- Control for nil values of args.Project.
u.project = u.project or '' -- Control for nil values of args.Project.
Line 180: Line 170:


local function getLinks(args)
local function getLinks(args)
-- If the username is absent or blank, return an html error and a tracking category.
generateUserDataStrings(args)
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]]'
end
-- Generate the user data strings.
generateUserDataStrings(args)
-- Build the template output.
local result = makeToolbar(args)
local result = makeToolbar(args) -- Get the toolbar contents.
if result then
if result then
if args.sup then
if args.sup then
Line 189: Line 185:
result = '&nbsp;' .. result
result = '&nbsp;' .. result
else
else
result = ''
result = '' -- If there are no links specified, don't return the toolbar at all.
end
end
result = '<span>' .. makeUserLink() .. result .. '</span>'
result = '<span>' .. makeUserLink() .. result .. '</span>'