Module:UserLinks: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
m (use nbsp for the edit summaries link) |
(add a function to generate all the links as a table, update comments) |
||
Line 18: | Line 18: | ||
---------------------------------------------------------------------------------------------- |
---------------------------------------------------------------------------------------------- |
||
-- |
-- To add more link types, write a function that produces an individual link, and put -- |
||
-- it at the bottom of the list below. Then, add a link code for your function to the -- |
|||
-- "linktypes" table. Try and make the code three letters or less. There are a number -- |
|||
-- of helper strings available for writing the functions: -- |
|||
-- -- |
-- -- |
||
-- u.username The plain username. If the username is not present then the -- |
-- u.username The plain username. If the username is not present then the -- |
||
Line 35: | Line 38: | ||
-- default is "en". -- |
-- default is "en". -- |
||
-- -- |
-- -- |
||
-- If you want more strings, you can define them in the generateUserDataStrings |
-- If you want more helper strings, you can define them in the generateUserDataStrings -- |
||
-- function below. -- |
-- function below. -- |
||
---------------------------------------------------------------------------------------------- |
|||
---------------------------------------------------------------------------------------------- |
|||
-- LINK FUNCTIONS START -- |
|||
---------------------------------------------------------------------------------------------- |
---------------------------------------------------------------------------------------------- |
||
Line 139: | Line 146: | ||
return '[[Special:PrefixIndex/Wikipedia:Requests for adminship/' .. u.username .. '|RfA]]' |
return '[[Special:PrefixIndex/Wikipedia:Requests for adminship/' .. u.username .. '|RfA]]' |
||
end |
end |
||
---------------------------------------------------------------------------------------------- |
|||
-- LINK FUNCTIONS END -- |
|||
-- To enable new link functions, add the code to the "linktypes" table directly below. -- |
|||
---------------------------------------------------------------------------------------------- |
|||
local linktypes = { |
|||
{'t' , makeTalkLink}, |
|||
{'c' , makeContribsLink}, |
|||
{'ct' , makeCountLink}, |
|||
{'m' , makeMovesLink}, |
|||
{'l' , makeLogsLink}, |
|||
{'bl' , makeBlockLogLink}, |
|||
{'bls' , makeBlocksLink}, |
|||
{'bu' , makeBlockUserLink}, |
|||
{'ca' , makeCentralAuthLink}, |
|||
{'dc' , makeDeletedContribsLink}, |
|||
{'e' , makeEmailLink}, |
|||
{'es' , makeEditSummariesLink}, |
|||
{'del' , makeDeletionsLink}, |
|||
{'lu' , makeListUserLink}, |
|||
{'sul' , makeSulLink}, |
|||
{'tl' , makeTargetLogsLink}, |
|||
{'efl' , makeEditFilterLogLink}, |
|||
{'pr' , makeProtectionsLink}, |
|||
{'rl' , makeRightsLink}, |
|||
{'ren' , makeRenamesLink}, |
|||
{'rfa' , makeRfaLink} |
|||
} |
|||
local function getLink(linktype) |
local function getLink(linktype) |
||
local |
local linkNumber |
||
for i, value in ipairs(linktypes) do |
|||
t = makeTalkLink, |
|||
if value[1] == linktype then |
|||
linkNumber = i |
|||
break |
|||
end |
|||
end |
|||
bl = makeBlockLogLink, |
|||
if not linkNumber then |
|||
bls = makeBlocksLink, |
|||
bu = makeBlockUserLink, |
|||
ca = makeCentralAuthLink, |
|||
dc = makeDeletedContribsLink, |
|||
e = makeEmailLink, |
|||
es = makeEditSummariesLink, |
|||
del = makeDeletionsLink, |
|||
lu = makeListUserLink, |
|||
sul = makeSulLink, |
|||
tl = makeTargetLogsLink, |
|||
efl = makeEditFilterLogLink, |
|||
pr = makeProtectionsLink, |
|||
rl = makeRightsLink, |
|||
ren = makeRenamesLink, |
|||
rfa = makeRfaLink |
|||
} |
|||
if not linktypes[linktype] then |
|||
return err('"' .. linktype .. '" is not a valid link code') |
return err('"' .. linktype .. '" is not a valid link code') |
||
end |
end |
||
local result = linktypes[linkNumber][2]() |
|||
if type(result) ~= 'string' then |
|||
return err('the function for code "' .. linktype .. '" did not return a string value') |
|||
end |
|||
return result |
|||
end |
end |
||
Line 299: | Line 323: | ||
return table.concat(trackingCategories) |
return table.concat(trackingCategories) |
||
end |
end |
||
end |
|||
-- This function generates a table of all available link types, with their previews. |
|||
-- It is used in the module documentation. |
|||
local function getLinkTable(args) |
|||
demo = args.demo -- Set the demo variable. |
|||
-- Override any user or interwiki arguments specified. |
|||
args.user = 'Example' |
|||
args.User = nil |
|||
args.Project = nil |
|||
args.project = nil |
|||
args.lang = nil |
|||
args.Lang = nil |
|||
-- Generate the user data strings and return any errors. |
|||
local dataStringError = generateUserDataStrings(args) |
|||
if dataStringError then |
|||
return dataStringError |
|||
end |
|||
-- Build a table of all of the links. |
|||
local result = '<table class="wikitable plainlinks sortable">' |
|||
.. '\n<tr><th>Code</th><th>Preview</th></tr>' |
|||
for i, value in ipairs(linktypes) do |
|||
local code = value[1] |
|||
result = result .. "\n<tr><td>'''" .. code .. "'''</td><td>" .. getLink(code) .. '</td></tr>' |
|||
end |
|||
result = result .. '\n</table>' |
|||
return result |
|||
end |
end |
||
local function getSingleLink(args) |
local function getSingleLink(args) |
||
demo = args.demo -- Set the demo variable. |
|||
-- Generate the user data strings and return any errors. |
|||
local dataStringError = generateUserDataStrings(args) |
|||
if dataStringError then |
|||
return dataStringError |
|||
end |
|||
local linktype = args[1] |
local linktype = args[1] |
||
if not linktype then |
if not linktype then |
||
Line 312: | Line 374: | ||
local function getLinks(args) |
local function getLinks(args) |
||
demo = args.demo -- Set the demo variable. |
|||
-- Generate the user data strings and return any errors. |
|||
local dataStringError = generateUserDataStrings(args) |
|||
if dataStringError then |
|||
return dataStringError |
|||
end |
|||
-- Build the template output. |
-- Build the template output. |
||
local result = makeToolbar(args) -- Get the toolbar contents. |
local result = makeToolbar(args) -- Get the toolbar contents. |
||
Line 354: | Line 423: | ||
end |
end |
||
demo = args.demo -- Set the demo variable. |
|||
-- Generate the user data strings and return any errors. |
|||
local dataStringError = generateUserDataStrings(args) |
|||
if dataStringError then |
|||
return dataStringError |
|||
end |
|||
return func(args) |
return func(args) |
||
end |
end |
||
Line 367: | Line 429: | ||
return { |
return { |
||
main = makeWrapper(getLinks), |
main = makeWrapper(getLinks), |
||
single = makeWrapper(getSingleLink) |
single = makeWrapper(getSingleLink), |
||
linktable = makeWrapper(getLinkTable) |
|||
} |
} |