Module:User Explained

--[=[ -- This module implements {{user}}. {{user}} is a high-use template, sometimes -- with thousands of transclusions on a page. This module optimises the -- template's performance by reducing the number of parameters called from -- wikitext, while still allowing all the features provided by -- [[Module:UserLinks]]. It is about twice as fast as the version of -- that called the template from wikitext.--]=]

local mUserLinks = require('Module:UserLinks')local mShared = require('Module:UserLinks/shared')local yesno = require('Module:Yesno')

local p =

local function validateArg(arg) -- Validates one argument. Whitespace is stripped, and blank arguments -- are treated as nil. if not arg then return nil end arg = arg:match('^%s*(.-)%s*$') if arg ~= then return arg else return nil endend

function p.main(frame, opts) -- Grab the user, project and lang args from wikitext. local argKeys = local origArgs = require('Module:Arguments').getArgs(frame) local args = for argKey, t in pairs(argKeys) do for i, origArgKey in ipairs(t) do local value = origArgs[origArgKey] value = validateArg(value) if value then args[argKey] = value -- If we have found a value, break the loop. For the average -- invocation this saves two argument lookups. break end end end -- Generate options. Some of these need wikitext args also. local options = -- Input the codes directly. This saves two argument lookups for each -- invocation. local codes = type(opts) and opts or -- Generate mop icon for formeradmin local mop = (origArgs.mop and yesno(origArgs.mop)) and require('Module:Icon')._main or -- Plug the data into . local snippets = mUserLinks.getSnippets(args) local links = mUserLinks.getLinks(snippets) local success, result = pcall(mUserLinks.export, codes, links, options) if success then return mop .. result else return mShared.makeWikitextError(result, options.isDemo) endend

function p.admin(frame) return p.main(frame,)end

function p.eight(frame) return p.main(frame,)end

function p.five(frame) return p.main(frame,)end

function p.four(frame) return p.main(frame,)end

function p.formeradmin(frame) return p.main(frame,)end

function p.seven(frame) return p.main(frame,)end

function p.six(frame) return p.main(frame,)end

function p.three(frame) return p.main(frame,)end

function p.two(frame) return p.main(frame,)end

p[''] = p.mainp['2'] = p.twop['3'] = p.threep['4'] = p.fourp['5'] = p.fivep['6'] = p.sixp['7'] = p.sevenp['8'] = p.eightp['former admin'] = p.formeradmin

return p