Module:UserLinks: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
add a function to generate all the links as a table, update comments
m (use nbsp for the edit summaries link)
(add a function to generate all the links as a table, update comments)
Line 18:
 
----------------------------------------------------------------------------------------------
-- BelowTo areadd the helper strings available for writing usermore link functions. 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 --
Line 35 ⟶ 38:
-- default is "en". --
-- --
-- If you want more helper strings, you can define them in the generateUserDataStrings --
-- function below. --
----------------------------------------------------------------------------------------------
 
----------------------------------------------------------------------------------------------
-- LINK FUNCTIONS START --
----------------------------------------------------------------------------------------------
 
Line 139 ⟶ 146:
return '[[Special:PrefixIndex/Wikipedia:Requests for adminship/' .. u.username .. '|RfA]]'
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 linktypes = {linkNumber
for i, value in ipairs(linktypes) do
t = makeTalkLink,
c if value[1] == linktype makeContribsLink,then
ct linkNumber = makeCountLink,i
m = makeMovesLink,break
l = makeLogsLink,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')
end
returnlocal result = linktypes[linktypelinkNumber][2]()
if type(result) ~= 'string' then
return err('the function for code "' .. linktype .. '" did not return a string value')
end
return result
end
 
Line 299 ⟶ 323:
return table.concat(trackingCategories)
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
 
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]
if not linktype then
Line 312 ⟶ 374:
 
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.
local result = makeToolbar(args) -- Get the toolbar contents.
Line 354 ⟶ 423:
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)
end
Line 367 ⟶ 429:
return {
main = makeWrapper(getLinks),
single = makeWrapper(getSingleLink),
linktable = makeWrapper(getLinkTable)
}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu