Jump to content

Module:Banner shell

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MSGJ (talk | contribs) at 19:54, 13 November 2023 (display for articles with/without global assessment to match, add demo_page parameter for testing). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local DuplicateBanners = function(text)
	local capture = '<span class="wpb%-project">([%w%s]*)</span>'
	local banners = {}
	for project in text:gmatch(capture) do
		if banners[project] == true then
			return '[[Category:Pages using WikiProject banner shell with duplicate banner templates|' .. project .. ']]'
		end
		banners[project] = true
	end
end

p.main = function(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = {'Template:WikiProject banner shell'}
	})
	local title = args.demo_page and mw.title.new(args.demo_page) or mw.title.getCurrentTitle()
	local classmask = require('Module:Class mask')
	local class = classmask._main({args.class or ''}, title.talkPageTitle)
	local yesno = require('Module:Yesno')
	local demo = not yesno(args.category or true, true) or args.demo_page
	local pagetype = require('Module:Pagetype')._main{
		page = title.prefixedText,
		[1] = args.class,
		dab = 'disambiguation page',
		defaultns = 'extended'
	}
	if demo and not args.demo_page then
		pagetype = 'article'
	end
	local out = {}
	if yesno(args.blp) or yesno(args.living) then
		table.insert(out,frame:expandTemplate{title = 'BLP'})
	elseif yesno(args.blpo) then
		table.insert(out,frame:expandTemplate{title = 'BLP others'})
	end
	if yesno(args.activepol) then
		table.insert(out, frame:expandTemplate{title = 'Active politician'})
	end
	local banner_args = {
		templatestyles = 'WikiProject banner shell/styles.css',
		collapsed = args.collapsed,
		class = 'wpbs',
	}
	local globalclass = false
	if class == '' then -- check if class parameters are defined by any project banner
		local articleclass = require('Module:WikiProject banner').readarticleclass(
			{ignore_blank = true, only_subtemplates = true},
			title.talkPageTitle.prefixedText
		)
		if articleclass == '' then -- no class parameters are defined by any project banner, so globally unassessed
			globalclass = true
		end
	else -- global class defined, so display it
		globalclass = true
	end
	local text = 'This ' .. (pagetype=='article' and 'article' or ('<b>'..pagetype..'</b>')) .. ' '-- use bold if page type is not article
	local icon_class = 'council'
	if globalclass or not args[1] then
		local icons = { -- map output of pagetype function to input of class icon function
			['project page'] = 'project',
			['user page'] = 'user',
			['interface page'] = 'interface',
			['help page'] = 'help',
			['module'] = 'module',
			['disambiguation page'] = 'disambig',
			['page'] = 'na'
		}
		icon_class = class=='NA' and (icons[pagetype] or pagetype) or class
		if class == '' then
			text = text .. 'has not yet been rated'
		else
			if args.class and class~='NA' then
				text = text .. 'is rated <span style="font-weight:bold;">' .. class .. '-class</span>'
			else
				text = text .. 'does not require a rating'
			end
		end
		text = text .. ' on Wikipedia\'s [[Wikipedia:Content assessment|content assessment]] scale.'
		if args[1] then
			text = text .. '<br>It'
		else
			if not demo then
				if title.isTalkPage then
					text = text .. '[[Category:' .. (class=='' and 'Unassessed' or (class .. '-Class')) .. ' articles]]'
				end
			end
		end
	end
	if args[1] then
		text = text .. ' is of interest to ' ..
			(yesno(args.collapsed) and 'multiple [[Wikipedia:WikiProject|WikiProjects]].'
			or ('the following [[Wikipedia:WikiProject|WikiProjects]]:'))
	end
	local icon = require('Module:Class')._icon{icon_class, size='35px'}
	local header = mw.html.create('td')
		:addClass('assess'):wikitext(icon):done()
		:tag('td'):addClass('banner-shell-header'):css('text-align', 'left'):css('font-weight', 'normal'):wikitext(text):done()
	banner_args.header = tostring(header)
	banner_args[1] = args[1] or ''
	table.insert(out,frame:expandTemplate{title='Banner holder', args=banner_args})
	if args[1] and args[1]~='' then
		local duplicate_cat = DuplicateBanners(args[1])
		if duplicate_cat and title.isTalkPage then
			table.insert(out, duplicate_cat)
		end
	elseif title.isTalkPage then
		table.insert(out,'[[Category:Pages using WikiProject banner shell without banner templates]]')
	end
	if args.listas then
		table.insert(out,frame:preprocess('{{DEFAULTSORT:' .. args.listas .. '}}'))
	end
	return table.concat(out)
end
return p