Module:No ping: Difference between revisions
Appearance
Content deleted Content added
let's prepare this for 'global' usage. avoid having to correct it in the future |
added link colour based on whether page exists |
||
Line 15: | Line 15: | ||
local url = fullUrl(mw.site.namespaces.User.name .. ':' .. username) |
local url = fullUrl(mw.site.namespaces.User.name .. ':' .. username) |
||
url = tostring(url) |
url = tostring(url) |
||
local label = args['label' .. tostring(i)] |
local label = args['label' .. tostring(i)] or username |
||
local color = '#cc2200' |
|||
⚫ | |||
if mw.title.new(username, mw.site.namespaces.User.name).exists then color = '#0645ad' end |
|||
label = '<span style="color:' .. color .. '">' .. label .. '</span>' |
|||
⚫ | |||
ret[#ret + 1] = url |
ret[#ret + 1] = url |
||
end |
end |
Revision as of 05:14, 18 April 2017
![]() | This Lua module is used on approximately 476,000 pages, or roughly 1% of all 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 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 implements {{no ping}}. Please see the template page for documentation.
-- This module implements {{noping}}.
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 url = fullUrl(mw.site.namespaces.User.name .. ':' .. username)
url = tostring(url)
local label = args['label' .. tostring(i)] or username
local color = '#cc2200'
if mw.title.new(username, mw.site.namespaces.User.name).exists then color = '#0645ad' end
label = '<span style="color:' .. color .. '">' .. label .. '</span>'
url = format('[%s %s]', url, label)
ret[#ret + 1] = url
end
ret = mw.text.listToText(ret)
ret = '<span class="plainlinks">' .. ret .. '</span>'
return ret
end
return p