Module:No ping: Difference between revisions

From Meta Wiki
Jump to navigation Jump to search
m>Jc86035
added link colour based on whether page exists
m>JJMC89
Undid revision 775971588 by Jc86035 (talk) Caused the template to ping users
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)] or username
local label = args['label' .. tostring(i)]
local color = '#cc2200'
url = format('[%s %s]', url, label or username)
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
ret[#ret + 1] = url
end
end

Revision as of 01:30, 25 April 2017

Documentation for this module may be created at Module:No ping/doc

-- 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)]
		url = format('[%s %s]', url, label or username)
		ret[#ret + 1] = url
	end
	ret = mw.text.listToText(ret)
	ret = '<span class="plainlinks">' .. ret .. '</span>'
	return ret
end

return p