Module:UserLinks
![]() | This Lua module is used in system messages, and on approximately 1,030,000 pages, or roughly 2% of all pages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This module depends on the following other modules: |
This module generates links about a given user. It is used to generate templates such as {{user}}, {{user5}}, and {{admin}}, usually through its wrapper template {{user-multi}}.
Functions
Main
The main
function implements the {{user-multi}} template. It generates a list of links about a given user. Please see the template page for documentation.
Single
The single
function generates a single link about a given user. See {{user-multi/link}} for documentation.
Porting to other wikis
If you want to use this module on another wiki, there are a few modules that you must also copy across, and some that can be used but are not essential.
Required modules:
- Module:UserLinks
- Module:UserLinks/shared
- Module:UserLinks/config
- Module:Arguments
- Module:Yesno
- Module:Toolbar
- Module:InterwikiTable
- Module:TableTools (optional in Module:UserLinks, but required by Module:Toolbar)
Optional modules:
- Module:UserLinks/extra - used for testing new link functions before they are moved to the main module.
- Module:Category handler - if an error occurs, and this module is present, pages are not categorised if they match the module's blacklist.
After you have copied over the necessary modules, you should adjust the configuration settings in Module:UserLinks/config for your language and for your wiki's setup.
p = {}
local toolbar = require('Module:Toolbar')
local project, username
local function makeTalkLink()
local plink = (project and (':' .. project .. ':')) or ''
return '[[' .. plink .. 'User talk:' .. username .. '|talk]]'
end
local function getLink(linktype)
local linktypes = {
t = makeTalkLink
}
return linktypes[linktype]()
end
local function makeToolbar(args)
local targs = {}
for k, v in pairs(args) do
if type(k) == 'number' then
targs[k] = getLink(v)
end
end
targs.style = args.small and 'font-size: 90%;'
targs.separator = args.separator or 'dot'
return toolbar.main(targs)
end
local function getLinks(args)
-- If the username 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
username = args.user or args.User
end
-- Get the values of the other module-wide variables.
project = args.Project
small = args.small
separator = args.separator
return makeToolbar(args)
end
function p.main(frame)
-- If called via #invoke, use the args passed into the invoking template.
-- Otherwise, for testing purposes, assume args are being passed directly in.
local origArgs
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
for k, v in pairs(frame.args) do
origArgs = frame.args
break
end
else
origArgs = frame
end
-- Strip whitespace, and treat blank arguments as nil.
-- 'user', 'User', and 'separator' have different behaviour depending on
-- whether they are blank or nil, so keep them as they are.
local args = {}
for k, v in pairs(origArgs) do
v = mw.text.trim(v)
if v ~= '' or k == 'user' or k == 'User' or k == 'separator' then
args[k] = v
end
end
return getLinks(args)
end
return p