Module:Template view

From MattWiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Template view/doc

local p = {}

local getArgs

function p.main(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame, {wrappers = 'Template:V', 'Template:View'})
	local t_name = args.template or args[1]
	-- Calling URL parameters in fullurl: forces the url to be of the form index.php?title=, which is prefered
	-- We'll call ?action= here to force that, and pass an argument within switches[]
	local t_url = frame:preprocess('{{fullurl:Template:'..t_name..'|action=}}')
	local r_string = '<span class="noprint plainlinks navbar" style="white-space:nowrap;word-spacing:-.12em;">'
	local switches = {
		['t'] = ' <b>&middot;</b> [[Template talk:'..t_name..
				'|<span style="font-variant:small-caps;color:#002bb8;" title="Discuss this template">t</span>]]',
		['talk'] = ' <b>&middot;</b> [[Template talk:'..t_name..
				'|<span style="color:#002bb8;" title="Discuss this template">talk</span>]]',
		['h'] = ' <b>&middot;</b> ['..t_url..
				'history <span style="font-variant:small-caps;color:#002bb8;" title="Template history">h</span>]',
		['hist'] = ' <b>&middot;</b> ['..t_url..
				'history <span style="color:#002bb8;" title="Template history">hist</span>]',
		['e'] = ' <b>&middot;</b> ['..t_url..
				'edit <span style="font-variant:small-caps;color:#002bb8;" title="Edit this template">e</span>]',
		['edit'] = ' <b>&middot;</b> ['..t_url..
				'edit <span style="color:#002bb8;" title="Edit this template">edit</span>]',
		['m'] = ' <b>&middot;</b> ['..frame:preprocess('{{fullurl:Special:MovePage|target=Template:'..t_name..'}}')..
				'<span style="font-variant:small-caps;color:#002bb8;" title="Move this template">m</span>]',
		['move'] = ' <b>&middot;</b> ['..frame:preprocess('{{fullurl:Special:MovePage|target=Template:'..t_name..'}}')..
				'<span style="color:#002bb8;" title="Move this template">move</span>]',
		['w'] = '  <b>&middot;</b> ['..t_url..
				'watch <span style="font-variant:small-caps;color:#002bb8;" title="Watch this template">w</span>]',
		['watch'] = '  <b>&middot;</b> ['..t_url..
				'watch <span style="color:#002bb8;" title="Watch this template">watch</span>]',

	switches['d'] = switches['t']
	if args.view and args.view:find('%S') then
		r_string = r_string..'[[Template:'..t_name..'|<span title="View this template">view</span>]]'
		r_string = r_string..'[[Template:'..t_name..'|<span style="font-variant:small-caps;" title="View this template">v</span>]]'
	for _,v in ipairs(args) do
		if switches[v:lower()] then
			r_string = r_string..switches[v:lower()]

	r_string = r_string..'</span>'
	return r_string

return p