Jump to content

Module:WikiProject banner

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Izno (talk | contribs) at 23:18, 6 November 2020 (this probably isn't interesting). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

--[[
This implements {{WPBannerMeta}}

]]
require ('Module:No globals')

local getArgs = require ('Module:Arguments').getArgs
local p = {}

-- we have to check always that the variables we get from the frame are set
-- and then map them otherwise set them to a default
local function is_set(var)
	return var and var ~= ''
end

local function warn_on_subst(subst, project, banner_name, frame)
	if subst ~= 'SUBST' then
		return
	end
	local warning = require('Module:Message box').main( 'tmbox', {
		image = '[[File:Stop hand nuvola.svg|40px]]',
		type = 'content',
		text = '<p>It seems that the \'\'WikiProject {{{PROJECT}}}\'\'' ..
		'banner has been [[Wikipedia:Substitution|substituted]] on this page ' ..
		'instead of being [[Wikipedia:Transclusion|transcluded]]. Please undo ' ..
		'the edit and type <code><nowiki>{{</nowiki>{{#if:{{{BANNER_NAME|}}}' ..
		'|{{PAGENAME:{{{BANNER_NAME}}}}}|WikiProject {{{PROJECT}}} }}' ..
		'<nowiki>}}</nowiki></code> instead.</p>'
	})
	local includeonly = '<includeonly>[[Category:WikiProject banners with ' ..
	'formatting errors|SUBST]][[Category:Pages with incorrectly substituted templates]]</includeonly>'
	
	return warning, includeonly
end

-- Make it cleaner to initialize 'trivial' variables.
local function arg_or_default(args, from_arg, default)
	if args[from_arg] and args[from_arg] ~= '' then
		return args[from_arg]
	else
		return default
	end
end

function p._main(args, frame)
	
	local subst = arg_or_default(args, 'substcheck', '¬')
	-- TODO: wikitext implementation seems to assume project is never nil. I
	-- don't see yet why that assumption is made or if we warn on nil project :D
	local project = arg_or_default(args, 'PROJECT', nil)
	local banner_name = arg_or_default(args, 'BANNER_NAME', nil)
	
	warn_on_subst(subst, project, banner_name, frame)

	local project_link = arg_or_default(args, 'PROJECT_LINK', nil)
	
	local builder = mw.html.create('table')
	builder:addClass('tmbox'):addClass('tmbox-notice'):addClass('mw-collapsible')
		:addClass('innercollapse'):addClass('wpb')
		:css('height', '0')
		:role('presentation')
		:tag('tr'):addClass('wpb-header')
			:tag('td')
			:cssText('text-align: right; padding: 0.3em 1em 0.3em 0.3em;'
				.. 'width: 50%; font-weight: bold;')
	
	return tostring(builder)

end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args, frame)
end

return p