Module:Sane mind

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:Sane mind/doc

Code

--	┌─────────────────────────────────────────┐
--	│  Back-end for {{sane mind}}    │
--	└─────────────────────────────────────────┘
local p = {}

-- shows a message box about blacklisting
function p.insane( frame, rule_name, rule_label, icon_size )
	local s_name, q_name
	local l_label = rule_label
	local l_size = icon_size
	local l_frame
	if (frame.args[1]) then
		l_frame = frame
	else
		l_frame = frame:getParent()
	end
	if (l_frame.args[3]) then
		s_name = 'argument to <tt>'..l_frame.args[3]..'</tt>'
	else
		s_name = 'string'
	end
	if (rule_name) then
		q_name = '“'..rule_name..'”'
	else
		q_name = 'undefined'
	end
	if (not l_label) then
		if (rule_name) then
			l_label = rule_name
		else
			l_label = ''
			l_size = '64px'
		end
	end
	if (not l_size) then l_size = '76px' end
	-- if (not l_style) then l_style = '' end
	return frame:expandTemplate{ title = 'fmbox', args = {
		id        = 'insane_minded',
		image     = '[[Image:Japan road sign 303.svg|72px|middle|link=]]',
		imageright= l_label..'[[Image:Barred ring.svg|'..l_size..'|middle|link=]]',
		text      = '<dl><dt style="text-align:center;">Blacklisted!</dt></dl>The '..
			s_name..' matches the '..q_name..
			' blacklist rule which prohibits its use as a source link. See [[Module:Sane mind]] for more information. The '..
			s_name..' is:<div style="color:#660066">'..l_frame.args[1]..'</div>'
		} }..'[[Category:Pages with blacklisted source links]]'
end

-- the checker function itself, rules are hard-coded
function p.check( frame )
	local l_frame
	if (frame.args[1]) then
		l_frame = frame
	else
		l_frame = frame:getParent()
		if (not l_frame.args[1]) then return '☺' end
	end
	
-- ┌──────── beginning of the rules’ list ─────────┐
	if mw.ustring.find(l_frame.args[1],
		'https?://[%-%.A-Za-z]*alamy%.com', 1, false)
	then
		return p.insane( frame, 
			'alamy.com', 
			'<span style="margin-right:-64px; font-weight:600">ALAMY</span>',
			'72px');
	end
-- │	
	if mw.ustring.find(l_frame.args[1],
		'granger.com/results.asp?', 1, true)
	then
		return p.insane( frame, 
			'granger.com', 
			'<span style="margin-right:-70px; font-size:88%; font-weight:600">GRANGER</span>');
	end
-- └──────── end of the rules’ list ───────────────┘

	return l_frame.args[2]
end

return p