Module:UserLinks: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
add some different user link functions
(output user links)
(add some different user link functions)
Line 1:
local p = {}
 
local ToolbarBuilder = require('Module:Toolbar')
local u = {} -- Table for user-data helper strings.
local project, username
 
--------------------------------------------------------------------------------------------------
-- Below are the helper strings available for writing user link functions. --
-- If the project name has not been specified, all the project strings will be --
-- the blank string, ''. If the username is not specified, the module outputs an error. --
-- Either way, there is no need to worry about escaping nil values when using the --
-- helper strings. --
-- --
-- u.username The plain username --
-- u.usernameHtml The username html-encoded. Spaces are encoded with plus signs. --
-- --
-- u.project The plain project name. --
-- u.projectColon The project name with two colons surrounding it, i.e. ":project:" --
-- --
-- If you want more strings, you can define them in the generateUserDataStrings --
-- function below. --
--------------------------------------------------------------------------------------------------
 
local function makeUserLink()
return '[[' .. projectu.projectColon .. 'User:' .. u.username .. '|' .. u.username .. ']]'
end
 
local function makeTalkLink()
return '[[' .. projectu.projectColon .. 'User talk:' .. u.username .. '|talk]]'
end
 
local function makeContribsLink()
return '[[' .. u.projectColon .. 'Special:Contributions/' .. u.username .. '|contribs]]'
end
 
local function makeCountLink()
return '[http://tools.wmflabs.org/xtools/pcount/index.php?name=' .. u.usernameHtml .. '&lang=en&wiki=wikipedia count]'
end
 
local function makeMovesLink()
return '[[' .. u.projectColon .. 'Special:Log/move/' .. u.username .. '|page moves]]'
end
 
local function makeLogsLink()
return '[[' .. u.projectColon .. 'Special:Log/' .. u.username .. '|logs]]'
end
 
local function getLink(linktype)
local linktypes = {
t = makeTalkLink,
c = makeContribsLink,
ct = makeCountLink,
m = makeMovesLink,
l = makeLogsLink,
}
return linktypes[linktype]()
Line 38 ⟶ 75:
end
 
local function getLinksgenerateUserDataStrings(args)
-------------------------------------------------
-- 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
-- Get the project value.
if args.Project then
project = ':' .. args.Project .. ':'
else
project = ''
end
u.usernameHtml = mw.uri.encode(u.username) -- Html-encoded username
-------------------------------------------------
-- 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.
end
 
local function getLinks(args)
generateUserDataStrings(args)
local result = makeToolbar(args)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu