Jump to content

Module:Self

From Rolling Lounge Wiki
This article uses material from the Wikipedia article Module:Self, which is released under the Creative Commons Attribution-ShareAlike 4.0 International License (view authors). Wikipedia logo

local p = {}

function p.setup_template_params(template_name, frame, args)
	local title = mw.title.new(template_name, 10)
	if not title.exists then
		return {
			txt = '',
			errors = ('<span class="error scribunto-error">The license "' .. template_name ..
				'" does not exist.</span>[[Category:Files with invalid licenses]]')
		}
	end
	return {
		txt = frame:expandTemplate{
			title = template_name,
			args = { dw = args['dw'] or 'no' }
		},
		errors = ''
	}
end

function p.more_than_one(args)
	return args[2] ~= nil
end

function p.start_line(args)
	return mw.ustring.format(
		"'''''%s, the copyright holder of this work,''' hereby publish%s it under the following license%s:''",
		args['author'] or 'I',
		args['author'] and 'es' or '',
		p.more_than_one(args) and 's' or ''
	)
end

function p.categories(args)
	local currentTitle = mw.title.getCurrentTitle()
	if currentTitle.namespace ~= 6 then
		return ''
	end
	local cat = args['author'] and 'Files licensed by third parties' or 'Self-published work'
	return mw.ustring.format('[[Category:%s|%s]]', cat, currentTitle.text)
end

function p.main(frame)
	local args = frame:getParent().args
	local tstyles = frame:extensionTag('templatestyles', '', { src = 'Module:Self/styles.css' })
	local templates, errors = '', ''
	for _, template_name in ipairs(args) do
		local result = p.setup_template_params(template_name, frame, args)
		templates = templates .. result.txt
		errors = errors .. result.errors
	end
	local final_line = p.more_than_one(args)
		and "<div class=\"center\">''You may select the license of your choice.''</div>" or ''
	return tstyles .. mw.ustring.format(
		'<div class="wp-tmpl-self-license-wrapper"><div class="center">%s</div><div class="center">%s</div>%s</div>%s',
		p.start_line(args), templates, final_line, p.categories(args)
	) .. errors
end

return p