Module:UserLinks: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(output user links) |
(add some different user link functions) |
||
Line 1: | Line 1: | ||
p = {} |
local p = {} |
||
local ToolbarBuilder = require('Module:Toolbar') |
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() |
local function makeUserLink() |
||
return '[[' .. |
return '[[' .. u.projectColon .. 'User:' .. u.username .. '|' .. u.username .. ']]' |
||
end |
end |
||
local function makeTalkLink() |
local function makeTalkLink() |
||
return '[[' .. |
return '[[' .. u.projectColon .. 'User talk:' .. u.username .. '|talk]]' |
||
⚫ | |||
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 |
end |
||
local function getLink(linktype) |
local function getLink(linktype) |
||
local linktypes = { |
local linktypes = { |
||
t = makeTalkLink |
t = makeTalkLink, |
||
c = makeContribsLink, |
|||
ct = makeCountLink, |
|||
m = makeMovesLink, |
|||
l = makeLogsLink, |
|||
} |
} |
||
return linktypes[linktype]() |
return linktypes[linktype]() |
||
Line 38: | Line 75: | ||
end |
end |
||
local function |
local function generateUserDataStrings(args) |
||
------------------------------------------------- |
|||
-- Username helper strings -- |
|||
------------------------------------------------- |
|||
-- Get the username value. If it 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]]' |
||
else |
else |
||
username = args.user or args.User |
u.username = args.user or args.User |
||
⚫ | |||
⚫ | |||
if args.Project then |
|||
project = ':' .. args.Project .. ':' |
|||
else |
|||
project = '' |
|||
end |
end |
||
u.usernameHtml = mw.uri.encode(u.username) -- Html-encoded username |
|||
------------------------------------------------- |
|||
-- Project helper strings -- |
|||
------------------------------------------------- |
|||
⚫ | |||
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) |
local result = makeToolbar(args) |