https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AUser%2FsandboxModule:User/sandbox - Revision history2025-06-26T01:15:13ZRevision history for this page on the wikiMediaWiki 1.45.0-wmf.6https://en.wikipedia.org/w/index.php?title=Module:User/sandbox&diff=1048572910&oldid=prevPppery: Create sandbox version of Module:User2021-10-06T19:01:42Z<p>Create sandbox version of <a href="/wiki/Module:User" title="Module:User">Module:User</a></p>
<p><b>New page</b></p><div>--[=[<br />
-- This module implements {{user}}. {{user}} is a high-use template, sometimes<br />
-- with thousands of transclusions on a page. This module optimises the<br />
-- template's performance by reducing the number of parameters called from<br />
-- wikitext, while still allowing all the features provided by<br />
-- [[Module:UserLinks]]. It is about twice as fast as the version of {{user}}<br />
-- that called the {{user-multi}} template from wikitext.<br />
--]=]<br />
<br />
local mUserLinks = require('Module:UserLinks')<br />
local mShared = require('Module:UserLinks/shared')<br />
local yesno = require('Module:Yesno')<br />
<br />
local p = {}<br />
<br />
local function validateArg(arg)<br />
-- Validates one argument. Whitespace is stripped, and blank arguments<br />
-- are treated as nil.<br />
if not arg then<br />
return nil<br />
end<br />
arg = arg:match('^%s*(.-)%s*$')<br />
if arg ~= '' then<br />
return arg<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
function p.main(frame)<br />
-- Grab the user, project and lang args from wikitext.<br />
local argKeys = {<br />
user = {<br />
1,<br />
'User',<br />
'user'<br />
},<br />
project = {<br />
2,<br />
'Project',<br />
'project'<br />
},<br />
lang = {<br />
3,<br />
'Lang',<br />
'lang'<br />
}<br />
}<br />
local origArgs = frame:getParent().args<br />
local args = {}<br />
for argKey, t in pairs(argKeys) do<br />
for i, origArgKey in ipairs(t) do<br />
local value = origArgs[origArgKey]<br />
value = validateArg(value)<br />
if value then<br />
args[argKey] = value<br />
-- If we have found a value, break the loop. For the average<br />
-- invocation this saves two argument lookups.<br />
break<br />
end<br />
end<br />
end<br />
<br />
-- Generate options. Some of these need wikitext args also.<br />
local options = {<br />
span = false,<br />
separator = validateArg(origArgs.separator) or 'dot',<br />
isDemo = yesno(validateArg(origArgs.demo))<br />
}<br />
<br />
-- Input the codes directly. This saves two argument lookups for each<br />
-- invocation.<br />
local codes = {'t', 'c'}<br />
<br />
-- Plug the data into [[Module:UserLinks]].<br />
local snippets = mUserLinks.getSnippets(args)<br />
local links = mUserLinks.getLinks(snippets)<br />
local success, result = pcall(mUserLinks.export, codes, links, options)<br />
if success then<br />
return result<br />
else<br />
return mShared.makeWikitextError(result, options.isDemo)<br />
end<br />
end<br />
<br />
return p</div>Pppery