Module:Banner shell
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 11,300,000 pages, or roughly 18% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
Banner shell |
---|
Usage
This module implements Template:WikiProject banner shell and Template:Banner holder. Please refer to those templates' documentation.
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 pagetype = require('Module:Pagetype')._main{
page = title.prefixedText,
[1] = args.class,
dab = 'disambiguation page',
defaultns = 'extended'
}
local classmask = require('Module:Class mask')
local class = pagetype=='article' and args.class or ''
class = classmask._main({class}, title.talkPageTitle)
local yesno = require('Module:Yesno')
local demo = not yesno(args.category or true, true) or args.demo_page
local out = {}
local addCategory = function(category)
if not demo and title.isTalkPage then
local category_title = mw.title.new('Category:' .. category)
if category_title.exists then
table.insert(out, '[[' .. category_title.prefixedText .. ']]')
else
table.insert(out, '[[Category:Pages using WikiProject banner shell needing attention|C]]')
end
end
end
if demo and not args.demo_page then
pagetype = 'article'
end
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',
}
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
class = '' -- globally unassessed
else
class = nil -- no global assessment
end
end
local class2 = class and class~='' and (class .. '-Class') or 'Unassessed'
local text, vital
local icon_class = 'council'
if yesno(args.vital) then
local page = mw.ustring.upper(mw.ustring.sub(title.subjectPageTitle.text,1,1)) -- get first letter of article name
local codepoint = mw.ustring.codepoint(page, 1, 1)
if codepoint<65 or codepoint>90 then --first letter is not between A-Z
page = 'others'
end
local data_page = mw.title.new('Wikipedia:Vital articles/data/' .. page .. '.json')
if data_page.exists then
local data = mw.loadJsonData(data_page.fullText)[title.subjectPageTitle.text]
if data then
local level = tostring(data.level)
if level then
local link = 'Wikipedia:Vital articles/Level/' .. level
if (level=='4' or level=='5') and data.topic then
link = link .. '/' .. data.topic
end
if data.sublist then
link = link .. '/' .. data.sublist
end
--if data.section then -- not used until we have stable section anchors to link to
-- link = link .. '#' .. data.section
--end
if not mw.title.new(link).exists then -- add tracking category if link does not exist
table.insert(out, '[[Category:Pages using WikiProject banner shell needing attention|L]]')
end
vital = 'This [[File:Círculos Concéntricos.svg|16px|link=|alt=]] <b>[[' .. link .. '|level-' .. level .. ' vital article]]</b> '
end
local topic = data.topic or 'an unknown topic'
level = level or 'Unknown'
addCategory(string.format( -- CLASS
'%s vital articles',
class2
))
addCategory(string.format( -- LEVEL
'Wikipedia level-%s vital articles',
level
))
addCategory(string.format( -- TOPIC
'Wikipedia vital articles in %s',
topic
))
addCategory(string.format( -- CLASS/LEVEL
'%s level-%s vital articles',
class2,
level
))
addCategory(string.format( -- LEVEL/TOPIC
'Wikipedia level-%s vital articles in %s',
level,
topic
))
addCategory(string.format( -- CLASS/TOPIC
'%s vital articles in %s',
class2,
topic
))
end
end
end
text = vital or 'This ' .. (pagetype=='article' and 'article' or ('<b>'..pagetype..'</b>')) .. ' '-- use bold if page type is not article
if class 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'
elseif not yesno(args.vital) then
addCategory(class2 .. ' articles')
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
else
addCategory('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