Module:Asbox: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Codehydro
(original template is supposed to go to #default even with invalid name)
meta>Mr. Stradivarius
(pass the frame variable through, and only initialise it from Lua when we need it)
Line 3: Line 3:
local p = {}
local p = {}


function p._main(args)
function p._main(args, frame)
local output = mw.html.create('table')
local output = mw.html.create('table')
local page = mw.title.getCurrentTitle()
local page = mw.title.getCurrentTitle()
Line 59: Line 59:
local nameTitle = mw.title.new(args.name or '')
local nameTitle = mw.title.new(args.name or '')
if nameTitle == page then
if nameTitle == page then
frame = frame or mw.getCurrentFrame()
output = output .. frame:expandTemplate{
output = output .. frame:expandTemplate{
title = 'Asbox/templatepage',
title = 'Asbox/templatepage',
Line 77: Line 78:
wrappers = WRAPPER_TEMPLATE
wrappers = WRAPPER_TEMPLATE
})
})
return p._main(args)
return p._main(args, frame)
end
end


return p
return p

Revision as of 16:52, 24 December 2014

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

local WRAPPER_TEMPLATE = 'Template:Asbox'

local p = {}

function p._main(args, frame)
	local output = mw.html.create('table')
	local page = mw.title.getCurrentTitle()
	local buffer = mw.html.create('td')
	output
		:addClass('metadata plainlinks stub')
		:css('background','transparent')
		:attr('role','presentation')
	if args.icon or args.image then
		output
			:tag('td'):wikitext(args.icon or string.format(
				'[[File:%s|%spx|alt=%s]]',
				args.image,
				args.pix and ('|' .. args.pix) or '40x30',
				args.imagealt or 'Stub icon'
			))
	end
	buffer
		:tag('i')
			:wikitext(string.format(
				'This %s %s %s is a [[Wikipedia:stub|stub]]. You can help Wikipedia by [%s expanding it].',
				args.subject or '',
				args.article or 'article',
				args.qualifier or '',
				page:fullUrl('action=edit', 'relative')
			))
	if args.name then
		buffer
			:wikitext(require('Module:Navbar')._navbar{
				args.name,
				mini = 'yes',
				style = 'position: absolute; right: 15px; display: none;'
			})
	end
	if args.note then
		buffer:tag('br', {selfClosing = true})
		buffer
			:tag('span')
				:css('font-style', 'normal')
				:css('font-size', 'smaller')
				:wikitext(args.note)
	end
	output
		:node(buffer)
	output = tostring(output)
	if page.namespace == 0 then -- Main namespace
		output = output .. '[[Category:All stub articles]]'
		for k,v in pairs(args) do
			if string.match(k, 'category%d?') then
				output = string.format('%s[[Category:%s]]', output, v)
			end
		end
	end
	if not args.demo and page.basePageTitle ~= WRAPPER_TEMPLATE then
		local nameTitle = mw.title.new(args.name or '')
		if nameTitle == page then
			frame = frame or mw.getCurrentFrame()
			output = output .. frame:expandTemplate{
				title = 'Asbox/templatepage',
				args = args
			}
		elseif not nameTitle.isSubpage and nameTitle.namespace == 10 then -- Template namespace and not a subpage
			output = output .. string.format(
				'[[Category:Stub message templates needing attention|%s]]',
				(args.name and 'E' or 'W') .. page.text
			)
		end
	end
	return output
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = WRAPPER_TEMPLATE
	})
	return p._main(args, frame)
end

return p