Anonymous user
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:
----------------------------------------------------------------------------------------------
--
-- 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
for i, value in ipairs(linktypes) do
end
if not linkNumber then
return err('"' .. linktype .. '" is not a valid link code')
end
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
return func(args)
end
Line 367 ⟶ 429:
return {
main = makeWrapper(getLinks),
single = makeWrapper(getSingleLink),
linktable = makeWrapper(getLinkTable)
}
|