Module:No ping/sandbox
Appearance
| This is the module sandbox page for Module:No ping (diff). |
| This Lua module is used on approximately 487,000 pages. 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. Consider discussing changes on the talk page before implementing them. |
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
This module implements {{no ping}}. Please see the template page for documentation.
local p = {}
function p.main(frame)
local args = frame:getParent().args
return p._main(args)
end
function p._main(args)
local ret = {}
local fullUrl = mw.uri.fullUrl
local format = string.format
for i, username in ipairs(args) do
local label = args['label' .. tostring(i)]
local url = ""
local targetUser = username
if (username:sub(1, (mw.site.namespaces.User.name .. ':'):len()) == (mw.site.namespaces.User.name .. ':')) then
targetUser = username:sub((mw.site.namespaces.User.name .. ':'):len() + 1)
end
if targetUser:sub(1, 2) == '~2' then
-- Temporary user target; use internal contributions link
url = mw.site.namespaces.Special.name .. ':Contributions/' .. targetUser
url = format('[[%s|%s]]', url, label or username)
else
-- Named user target; use external link
url = fullUrl(mw.site.namespaces.User.name .. ':' .. targetUser)
url = tostring(url)
url = format('[%s %s]', url, label or username)
end
ret[#ret + 1] = url
end
ret = mw.text.listToText(ret)
ret = '<span class="plainlinks">' .. ret .. '</span>'
return ret
end
return p