Module:Banner shell/sandbox: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
the death category is unlike the living category, and the container isn't populated Tag: Reverted |
||
(7 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
local sandbox = '/sandbox' |
local sandbox = '/sandbox' |
||
local yesno = require('Module:Yesno') |
local yesno = require('Module:Yesno') |
||
⚫ | |||
-- Standardize the blp parameter. |
|||
local function getBLPStatus(args) |
|||
if args.blp then |
|||
⚫ | |||
end |
|||
⚫ | |||
return cfg.blp_status.living |
|||
else |
|||
return cfg.blp_status.dead |
|||
end |
|||
if args.activepol then |
|||
return cfg.blp_status.active |
|||
end |
|||
if args.blpo then |
|||
return cfg.blp_status.others |
|||
end |
|||
end |
|||
local shell = function(frame, header, content, collapsed, class) |
local shell = function(frame, header, content, collapsed, class) |
||
Line 12: | Line 34: | ||
:tag('td') |
:tag('td') |
||
:attr('colspan', '2') |
:attr('colspan', '2') |
||
:addClass('banner-shell-inner'):addClass('outercollapse') |
:addClass('banner-shell-inner') |
||
:addClass('outercollapse') |
|||
:wikitext(content) |
:wikitext(content) |
||
:done() |
:done() |
||
Line 18: | Line 41: | ||
local holder = mw.html.create('table') |
local holder = mw.html.create('table') |
||
:attr('role', 'presentation') |
:attr('role', 'presentation') |
||
:addClass('tmbox'):addClass('tmbox-notice'):addClass('banner-shell') |
:addClass('tmbox') |
||
:addClass('tmbox-notice') |
|||
:addClass('banner-shell') |
|||
:addClass(class) -- allow additional class to be specified |
:addClass(class) -- allow additional class to be specified |
||
:addClass(content and 'mw-collapsible' or nil) |
:addClass(content and 'mw-collapsible' or nil) |
||
Line 37: | Line 62: | ||
:wikitext(image) |
:wikitext(image) |
||
local text_cell = mw.html.create('td') |
local text_cell = mw.html.create('td') |
||
:addClass('mbox-text'):addClass('banner-shell-header') |
:addClass('mbox-text') |
||
:addClass('banner-shell-header') |
|||
:tag('span'):addClass('collapseButton'):addClass('nowrap'):css('float', 'left'):wikitext(string.rep(' ', 10)):done() |
:tag('span') |
||
:addClass('collapseButton') |
|||
:addClass('nowrap') |
|||
:css('float', 'left') --TODO: move to TemplateStyles |
|||
:wikitext(string.rep(' ', 10)) |
|||
:done() |
|||
:wikitext(args.text or 'Other talk page banners') |
:wikitext(args.text or 'Other talk page banners') |
||
local header = mw.html.create('tr'):node(image_cell):node(text_cell) |
local header = mw.html.create('tr') |
||
:node(image_cell) |
|||
:node(text_cell) |
|||
return shell(frame, header, args[1], yesno(args.collapsed)) |
return shell(frame, header, args[1], yesno(args.collapsed)) |
||
end |
end |
||
Line 56: | Line 89: | ||
p.banner_shell = function(frame) |
p.banner_shell = function(frame) |
||
⚫ | |||
local args = require('Module:Arguments').getArgs(frame, {wrappers = {cfg.template}}) |
local args = require('Module:Arguments').getArgs(frame, {wrappers = {cfg.template}}) |
||
local title = args.demo_page and mw.title.new(args.demo_page) or mw.title.getCurrentTitle() |
local title = args.demo_page and mw.title.new(args.demo_page) or mw.title.getCurrentTitle() |
||
Line 81: | Line 113: | ||
pagetype = 'article' |
pagetype = 'article' |
||
end |
end |
||
⚫ | |||
-- Standardize the blp parameter now |
|||
⚫ | |||
local blp = getBLPStatus(args) |
|||
if blp == cfg.blp_status.living or blp == cfg.blp_status.active then |
|||
local activepol = blp==cfg.blp_status.active or yesno(args.activepol) |
|||
table.insert(out, frame:expandTemplate{ |
table.insert(out, frame:expandTemplate{ |
||
title = cfg.blp_template.blp..sandbox, |
title = cfg.blp_template.blp..sandbox, |
||
Line 91: | Line 126: | ||
} |
} |
||
}) |
}) |
||
elseif blp== |
elseif blp == cfg.blp_status.other then |
||
table.insert(out, frame:expandTemplate{ |
table.insert(out, frame:expandTemplate{ |
||
title = cfg.blp_template.blpo..sandbox, |
title = cfg.blp_template.blpo..sandbox, |
||
Line 97: | Line 132: | ||
}) |
}) |
||
end |
end |
||
-- This can be used to check for conflicting (if blp is set to no) or missing blp. |
|||
-- It's an expensive call to categories so this should be tested to make sure it doesn't break stuff. |
|||
local non_talk_title = mw.title.new(title.text) |
|||
for _, v in ipairs(non_talk_title.categories) do |
|||
if v == "Living people" then |
|||
if blp == cfg.blp_status.dead then |
|||
addCategory(cfg.blp_category) |
|||
end |
|||
break |
|||
elseif v == "deaths" then |
|||
if blp == cfg.blp_status.living or blp == cfg.blp_status.active or blp == cfg.blp_status.other then |
|||
addCategory(cfg.blp_category) |
|||
end |
|||
break |
|||
end |
|||
end |
|||
local class2 = class=='' and 'Unassessed' or (class .. '-Class') |
local class2 = class=='' and 'Unassessed' or (class .. '-Class') |
||
local vital |
local vital |
||
Line 181: | Line 234: | ||
:tag('td') |
:tag('td') |
||
:addClass('banner-shell-header') |
:addClass('banner-shell-header') |
||
:css('text-align', 'left') |
:css('text-align', 'left') --TODO: move to TemplateStyles |
||
:css('font-weight', 'normal') |
:css('font-weight', 'normal') --TODO: move to TemplateStyles |
||
:wikitext(table.concat(text)) |
:wikitext(table.concat(text)) |
||
:done() |
:done() |
||
Line 196: | Line 249: | ||
unknown = cfg.tracking.unknown, |
unknown = cfg.tracking.unknown, |
||
preview = cfg.tracking.preview, |
preview = cfg.tracking.preview, |
||
'1', 'activepol', 'blp', 'blpo', 'category', 'class', 'collapsed', 'demo_page', 'listas', 'living', 'vital' |
'1', 'activepol', 'blp', 'blpo', 'category', 'class', 'collapsed', 'demo_page', 'listas', 'living', 'vital' -- TODO: move to config the list of known parameters |
||
}, frame:getParent().args) |
}, frame:getParent().args) |
||
table.insert(out, tracking) |
table.insert(out, tracking) |
||
Line 204: | Line 257: | ||
end |
end |
||
end |
end |
||
if yesno(blp)==nil and blp~=nil and blp~= |
if yesno(blp)==nil and blp~=nil and blp~=cfg.blp_status.other and blp~=cfg.blp_status.active then |
||
addCategory(cfg.tracking.invalid, 'Pblp') |
addCategory(cfg.tracking.invalid, 'Pblp') |
||
end |
end |
Revision as of 12:28, 30 October 2024
![]() | This is the module sandbox page for Module:Banner shell (diff). |
![]() | 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.
require('strict')
local p = {}
local sandbox = '/sandbox'
local yesno = require('Module:Yesno')
local cfg = mw.loadData('Module:Banner shell/config' .. (sandbox or ''))
-- Standardize the blp parameter.
local function getBLPStatus(args)
if args.blp then
return args.blp:lower()
end
if yesno(args.living) then
return cfg.blp_status.living
else
return cfg.blp_status.dead
end
if args.activepol then
return cfg.blp_status.active
end
if args.blpo then
return cfg.blp_status.others
end
end
local shell = function(frame, header, content, collapsed, class)
local styles = frame:extensionTag('templatestyles', '', {src = 'Module:Message box/tmbox.css'})
.. frame:extensionTag('templatestyles', '', {src = 'Module:Banner shell' .. (sandbox or '') .. '/styles.css'})
local content_row
if content then
content_row = mw.html.create('tr')
:tag('td')
:attr('colspan', '2')
:addClass('banner-shell-inner')
:addClass('outercollapse')
:wikitext(content)
:done()
end
local holder = mw.html.create('table')
:attr('role', 'presentation')
:addClass('tmbox')
:addClass('tmbox-notice')
:addClass('banner-shell')
:addClass(class) -- allow additional class to be specified
:addClass(content and 'mw-collapsible' or nil)
:addClass(collapsed and 'mw-collapsed' or nil)
:node(header)
:node(content_row)
return styles .. tostring(holder)
end
p.banner_holder = function(frame)
local args = require('Module:Arguments').getArgs(frame, {wrappers = {'Template:Banner holder'}})
local image = '[[File:' .. (args.image or 'NewFavicon icon.svg')
.. '|' .. (args.size or '24') .. 'px'
.. '|link=' .. (args.image_link or '')
.. '|alt=' .. (args.alt or '') .. ']]'
local image_cell = mw.html.create('td')
:addClass('mbox-image')
:wikitext(image)
local text_cell = mw.html.create('td')
:addClass('mbox-text')
:addClass('banner-shell-header')
:tag('span')
:addClass('collapseButton')
:addClass('nowrap')
:css('float', 'left') --TODO: move to TemplateStyles
:wikitext(string.rep(' ', 10))
:done()
:wikitext(args.text or 'Other talk page banners')
local header = mw.html.create('tr')
:node(image_cell)
:node(text_cell)
return shell(frame, header, args[1], yesno(args.collapsed))
end
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 project
end
banners[project] = true
end
end
p.banner_shell = function(frame)
local args = require('Module:Arguments').getArgs(frame, {wrappers = {cfg.template}})
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 = cfg.page_types.dab,
soft_redirect = cfg.page_types.soft_redirect,
nonexistent = cfg.page_types.nonexistent,
defaultns = 'extended'
}
local lang = mw.language.getContentLanguage()
local classmask = require('Module:WikiProject banner' .. (sandbox or '')).class_mask
local class = classmask(args.class or '', title.talkPageTitle, false, pagetype)
local demo = not yesno(args.category or true, true) or args.demo_page
local out = {}
local addCategory = function(category, sort_key)
if not demo and title.isTalkPage then
local category_title = mw.title.new('Category:' .. category)
table.insert(out, '[[' .. category_title.prefixedText .. (sort_key and ('|' .. sort_key) or '') .. ']]')
end
end
if demo and not args.demo_page then
pagetype = 'article'
end
-- Standardize the blp parameter now
local blp = getBLPStatus(args)
if blp == cfg.blp_status.living or blp == cfg.blp_status.active then
local activepol = blp==cfg.blp_status.active or yesno(args.activepol)
table.insert(out, frame:expandTemplate{
title = cfg.blp_template.blp..sandbox,
args = {
activepol = activepol and 'yes',
from_shell = 'yes'
}
})
elseif blp == cfg.blp_status.other then
table.insert(out, frame:expandTemplate{
title = cfg.blp_template.blpo..sandbox,
args = {from_shell = 'yes'}
})
end
-- This can be used to check for conflicting (if blp is set to no) or missing blp.
-- It's an expensive call to categories so this should be tested to make sure it doesn't break stuff.
local non_talk_title = mw.title.new(title.text)
for _, v in ipairs(non_talk_title.categories) do
if v == "Living people" then
if blp == cfg.blp_status.dead then
addCategory(cfg.blp_category)
end
break
elseif v == "deaths" then
if blp == cfg.blp_status.living or blp == cfg.blp_status.active or blp == cfg.blp_status.other then
addCategory(cfg.blp_category)
end
break
end
end
local class2 = class=='' and 'Unassessed' or (class .. '-Class')
local vital
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 index = title.subjectPageTitle.text
index = tostring(tonumber(index))==index and tonumber(index) or index --convert to number if page is numerical, otherwise loadJsonData does not work
local data = mw.loadJsonData(data_page.fullText)[index]
if data then
local level = data.level and tostring(data.level)
if level and data.topic then
local link = 'Wikipedia:Vital articles/Level/' .. level
if (level=='4' or level=='5') then
link = link .. '/' .. data.topic
end
if data.sublist then
link = link .. '/' .. data.sublist
end
if data.section then
link = link .. '#' .. data.section
end
if not mw.title.new(link).exists then -- add tracking category if link does not exist
addCategory(cfg.vital.attention, 'L')
end
vital = cfg.vital.with_level:format(link, level)
else
vital = cfg.vital.without_level
end
for _, cat in ipairs(cfg.vital.categories) do
if cat:find('_CLASS') and (class=='NA' or class=='') then
addCategory(cfg.vital.attention, class=='NA' and 'N' or 'U')
elseif level==nil then
addCategory(cfg.vital.attention, 'V')
elseif data.topic==nil then
addCategory(cfg.vital.attention, 'T')
else
local category = cat
:gsub('_CLASS', class2)
:gsub('_LEVEL', level)
:gsub('_TOPIC', data.topic)
addCategory(category)
end
end
else
addCategory(cfg.vital.not_listed)
end
end
end
local icon = string.format(
'[[File:%s|%s|35px|class=noviewer|alt=]]',
class=='NA' and cfg.icons.type[pagetype] or cfg.icons.quality[class],
class=='NA' and lang:ucfirst(pagetype) or (class2 .. ' ' .. pagetype)
)
local text
if class=='' then
text = {cfg.rating.not_yet:format(vital or pagetype)}
elseif class=='NA' then
text = {cfg.rating.not_required:format(vital or pagetype)}
else
text = {cfg.rating.rated:format(vital or pagetype, class)}
end
table.insert(text, ' ' .. cfg.rating.scale)
if args[1] then
table.insert(text, '<br>' .. cfg.project.interest .. ' ')
table.insert(text, yesno(args.collapsed) and cfg.project.collapsed or cfg.project.uncollapsed)
local duplicate_cat = DuplicateBanners(args[1])
if duplicate_cat and title.isTalkPage then
addCategory(cfg.tracking.duplicate, duplicate_cat)
end
elseif not yesno(args.vital) then -- if no projects and not vital then add class super category
addCategory(class2 .. ' articles')
end
local header = mw.html.create('tr')
:tag('td')
:addClass('assess')
:wikitext(icon)
:done()
:tag('td')
:addClass('banner-shell-header')
:css('text-align', 'left') --TODO: move to TemplateStyles
:css('font-weight', 'normal') --TODO: move to TemplateStyles
:wikitext(table.concat(text))
:done()
table.insert(
out,
shell(frame, header, args[1], yesno(args.collapsed), 'wpbs')
)
if args.listas then
table.insert(out, frame:preprocess('{{DEFAULTSORT:' .. args.listas .. '}}'))
end
if not demo then
local tracking = require('Module:Check for unknown parameters')._check({
unknown = cfg.tracking.unknown,
preview = cfg.tracking.preview,
'1', 'activepol', 'blp', 'blpo', 'category', 'class', 'collapsed', 'demo_page', 'listas', 'living', 'vital' -- TODO: move to config the list of known parameters
}, frame:getParent().args)
table.insert(out, tracking)
for _, param in ipairs{'activepol', 'blpo', 'category', 'collapsed', 'living'} do -- check if each has a boolean value
if yesno(args[param], 'invalid')=='invalid' then
addCategory(cfg.tracking.invalid, param)
end
end
if yesno(blp)==nil and blp~=nil and blp~=cfg.blp_status.other and blp~=cfg.blp_status.active then
addCategory(cfg.tracking.invalid, 'Pblp')
end
if pagetype=='article' and args.class and class=='' then -- find pages with invalid class parameter
addCategory(cfg.tracking.invalid, 'Zclass')
end
end
return table.concat(out)
end
return p