Module:WikiProject banner/sandbox: Difference between revisions

Content deleted Content added
no PIQA warning with custom criteria
m Removed protection from "Module:WikiProject banner/sandbox"
 
(149 intermediate revisions by 6 users not shown)
Line 1:
require('strict')
local p = {}
local sandbox = '/sandbox' -- BE SURE TO COMMENT OUT this definition when deploying to live
local cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or ''))
local auxiliary = cfg.auxiliary_module .. (sandbox or '')
Line 21:
end
end
 
local display_error = function(text)
local span = mw.html.create('div')
Line 46 ⟶ 47:
end
 
local isarticleimportance_mask = function(raw_importance, scale, banner_name, pagetype, class)
local article = true
for _,v in ipairs(cfg.quality.non_article_classes) do
if class==v then -- class matches one of the non-article classes
article = false
break
end
end
return article
end
 
local importance_mask = function(raw_importance, scale, banner_name, pagetype)
---------------------------
-- Importance mask --------
Line 71 ⟶ 61:
args = {
importance = raw_importance or '¬',
class = class,
pagetype = pagetype
}
Line 77 ⟶ 68:
elseif raw_importance then-- standard importance scale
importance = cfg.importance.na
if pagetype=='article' or pagetype=='set index article' or pagetype=='redirect' or pagetype=='draft' then
local mask = cfg.importance.mask
if mask[raw_importance:lower()] then -- valid importance specified
importance = mask[raw_importance:lower()]
elseif pagetype=='article' or pagetype=='set index article' then -- unspecified or invalid importance, use "Unknown" for articles
importance = cfg.importance.unknown
end
Line 101 ⟶ 92:
-- otherwise returns class parameter
end
p.class_mask = function(class, title, FQS, pagetype, article)
local resolveFQSgrade = function(class)
return FQS and lang:ucfirst(class) or 'NA'
Line 113 ⟶ 104:
elseif pagetype=='disambiguation page' then
out = resolveFQSgrade('disambig')
elseif article or pagetype=='article' or pagetype=='set index article' then
if classpagetype=='start'set orindex class=='stubarticle' then -- Ucfirst
out = 'List'
elseif class=='start' or class=='stub' then -- Ucfirst
out = lang:ucfirst(class)
elseif class=='b' or class=='c' or class=='fa' or class=='fl' or class=='a' or class=='ga' then -- Upper-case
Line 159 ⟶ 152:
local pagetype = demo_page==true and 'article' or require('Module:Pagetype')._main({
page = demo_page,
dab = 'disambiguation page',
sia = 'set index article',
draft = 'draft'
})
local article = pagetype=='article' or pagetype=='set index article'
local rows, nested_ratings, task_forces, notes, categories, taskforce_categories = {}, {}, {}, {}, {}, {}
local add_category = function(category, key)
Line 167 ⟶ 163:
end
end
local parse_textparse_pt = function(text) -- function to replace _PAGETYPE_ with the actual page type
local ptype = article and 'article' or pagetype -- display "article" for articles otherwise page type
return text and text:gsub('_PAGETYPE_', pagetype)
return text and text:gsub('_PAGETYPE_', ptype)
end
for arg_name, arg_value in pairs(args) do
Line 189 ⟶ 186:
table.sort(task_forces, function (x, y) return tonumber(x) < tonumber(y) end)
table.sort(notes, function (x, y) return tonumber(x) < tonumber(y) end)
local assessment_category = function(cat, name)
if cat then
return cat:gsub(' articles', '') -- remove "articles" from category
else
return name or ''
end
end
local assessment_cat = assessment_category(args.ASSESSMENT_CAT, project)
---------------------------
-- Location warning -------
---------------------------
local warning = ''
local show_namespace_warning =if not (current_title.isTalkPage orand not demo_page) then
if show_namespace_warning then
local text = cfg.namespace_warning.text:format(
pagetype,
current_title.talkPageTitle.fullText,
parameter_format('category', 'no')
Line 210 ⟶ 213:
image = '[[File:' .. cfg.namespace_warning.image .. '|40px]]',
type = cfg.namespace_warning.type_,
text = parse_pt(text)
})
if not current_title.subjectPageTitle:inNamespace(2) then
Line 233 ⟶ 236:
-- Primary image/text -----
---------------------------
local assessment_cat = args.ASSESSMENT_CAT or project .. ' articles'
local primary_image = function(image_name, size)
local cell = mw.html.create('td')
Line 246 ⟶ 248:
local portal = args.PORTAL
local portal_box = portal and frame:expandTemplate{title='Portal', args={portal}} or ''
local main_text = portal_box .. (parse_textparse_pt(args.MAIN_TEXT) or cfg.main_text:format(
pagetype,
project_link.prefixedText,
project_name,
Line 300 ⟶ 301:
end
else -- no banner shell on page
if pagetype=='article' then
add_category(cfg.banner_shell.category.no_banner_shell_articles)
elseif title.namespace==3 then --User talk namespace
Line 308 ⟶ 309:
end
end
elseif title.namespace~=2 then --User namespace
else
add_category(cfg.banner_shell.category.no_banner_shell)
end
Line 322 ⟶ 323:
assessment_link = nil
end
local check_existscheck_fallbacks = function(class, assessment_catcategory) -- check if category exists and is not blank
if article or args.QUALITY_CRITERIA=='custom' then -- no fallbacks for articles or projects with custom quality scales
if not isarticle(class) then
local cat = mw.title.new('Category:' .. class .. '-Class' .. ' ' .. assessment_cat)
return (cat.exists and #cat:getContent()>0) and class or 'NA' -- automatically use NA for non-article pages if category does not exist
else
return class
else -- check fallbacks for non-article classes
local new_class = class
local category_exists = function(class)
local cat = mw.title.new(cfg.quality.assessment_category:format(class, category .. ' ' .. (article and 'articles' or 'pages')))
return cat.exists and #cat:getContent()>0 -- check if category exists and is not blank
end
if class=='FM' and not category_exists('FM') then
new_class = 'File' -- fall back to File-class if FM category does not exist
end
if not category_exists(new_class) then
new_class = 'NA' -- use NA for non-article pages if category does not exist
end
return new_class
end
end
local class = raw_args.class
if class then -- banner gives quality ratings
article_class = article_class and p.class_mask(article_class, title, false, pagetype, article)
local show_quality, conflict = true, false
if args.QUALITY_CRITERIA=='custom' then -- project has opted out of standard assessment scale and uses a custom mask
local custom_mask = banner_name:subPageTitle('class')
Line 360 ⟶ 370:
end
else
class = p.class_mask(class, title, true, pagetype, article)
end
local check_redundant = function()
if raw_args.class~='' and args.QUALITY_CRITERIA~='custom' then -- banner has a non-blank class value which is ignored
add_category(cfg.banner_shell.category.redundant_class)
end
end
class = check_fallbacks(class, assessment_cat)
local show = false -- hide quality class in project banner by default
if article_class then -- banner shell exists
if class=='' or class==article_class or article_class=='FM' then -- local class matches article class or is blank
class = check_fallbacks(article_class, assessment_cat) -- check fallbacks again now that class may have changed
show_quality = false -- hide quality class in project banner
check_redundant()
class = article_class
elseif class==article_class then -- local class matches article class
if raw_args.class~='' and args.QUALITY_CRITERIA~='custom' then
check_redundant()
add_category(cfg.banner_shell.category.redundant_class)
end
elseif article_class=='' then -- local class defined and no article class defined
show = true
add_category(cfg.banner_shell.category.no_quality_rating)
if args.QUALITY_CRITERIA~='custom' then
warning = warning .. display_error(cfg.banner_shell.piqa_warning)
end
elseif article_class=='FM' and args.QUALITY_CRITERIA~='custom' then
elseif pagetype~='article' and not isarticle(class) and class~='FM' then -- article class and local class are both non-article classes
class = check_fallbacks('FM', assessment_cat)
show_quality = false
check_redundant()
elseif args.QUALITY_CRITERIA~='custom' then -- article class exists and differs from local class
elseif not article and class~='FM' then -- article class and local class are both non-article classes
conflict = true
check_redundant()
add_category(class .. cfg.banner_shell.conflict.category)
elseif args.QUALITY_CRITERIA=='custom' then -- project uses custom criteria and class differs
end
show = true -- show quality class in project banner
end
else -- article class exists and differs from local class
if not isarticle(class) then -- check fallbacks for non-article classes
show = 'conflict'
local category_exists = function(class)
local cat = mw.title.newadd_category(cfg.qualitybanner_shell.conflict.assessment_categorycategory2:format(class, assessment_catarticle_class))
return cat.exists and #cat:getContent()>0 -- check if category exists and is not blank
end
if class=='FM' and not category_exists('FM') then
class = 'File' -- fall back to File-class if FM category does not exist
end
if not category_exists(class) then
class = 'NA' -- automatically use NA for non-article pages if category does not exist
end
else -- banner shell does not exist
show = true
end
local category = (class=='' and 'Unassessed' or class..'-Class') .. ' ' .. assessment_cat .. ' ' .. (article and 'articles' or 'pages')
if show_qualityshow then -- quality rating shown in banner
local rating
if pagetype=='article' then
rating = class=='' and cfg.quality.not_yet or cfg.quality.rated:format(class)
else
Line 405 ⟶ 417:
and cfg.quality.project_scale:format(wikilink(assessment_link..'#'..lang:ucfirst(cfg.quality.name), cfg.quality.name))
or cfg.quality.default_scale
local quality_rating = show=='conflict'
and cfg.banner_shell.conflict.text:format(pagetype)
or cfg.quality.rating:format(pagetype, rating, scale)
local cssClass = 'class-' .. (class=='' and 'unassessed' or class:lower())
local class_row = mw.html.create('tr')
Line 413 ⟶ 425:
:addClass('assess')
:addClass(cssClass)
:addClass(show=='conflict' and 'conflict' or nil)
:wikitext(wikilink(':Category:' .. category, class=='' and '???' or class))
:done()
Line 419 ⟶ 431:
:addClass('mbox-text')
:attr('colspan', '2')
:wikitext(parse_pt(quality_rating))
:done()
table.insert(rows, class_row)
Line 425 ⟶ 437:
nested_ratings,
1,
bubble(class=='' and 'Unassessed' or (class..'‑class'), show=='conflict', cssClass)
)
end
Line 440 ⟶ 452:
-- Importance assessment --
---------------------------
local importance = importance_mask(raw_args.importance or raw_args.priority, args.IMPORTANCE_SCALE, banner_name, pagetype, class)
local importance_name = args.IMPN or (raw_args.priority and 'priority' or cfg.importance.default_name)
if importance then -- banner gives importance ratings
local category = importance .. '-' .. importance_name .. ' ' .. assessment_cat .. ' ' .. (importance=='NA' and 'pages' or 'articles')
if importance~='NA' then -- display importance rating
local rating = importance=='Unknown' and cfg.importance.not_yet or cfg.importance.rated:format(importance, importance_name)
Line 450 ⟶ 462:
and cfg.importance.project_scale:format(assessment_link..'#'..lang:ucfirst(scale_name), scale_name)
or cfg.importance.default_scale
local importance_rating = parse_pt(cfg.importance.rating:format(pagetype, rating, scale))
local cssClass = 'import-' .. importance:lower()
local importance_row = mw.html.create('tr')
Line 473 ⟶ 485:
add_category(category)
end
page_assessment(project,if class, or importance) then
page_assessment(project, class, importance)
end
if args.HOOK_IMPORTANCE then
table.insert(rows, args.HOOK_IMPORTANCE)
end
if args.QII_FORMAT then
add_category(require(auxiliary).quality_importance_insection(args, class, importance, importance_name, assessment_cat, article))
end
---------------------------
Line 529 ⟶ 543:
for _, k in ipairs(task_forces) do
local tf_prefix = 'TF_' .. k .. '_'
local tf_assessment_cat = assessment_category(
args[tf_prefix..'ASSESSMENT_CAT'] or (,
args[tf_prefix..'NAME'] or '')..' articles'
)
local tf_importance
if yesno(args[tf_prefix..'QUALITY']) and class then
local tf_class = check_fallbacks(class, tf_assessment_cat)
add_category((tf_class=='' and 'Unassessed' or tf_class..'-Class') .. ' ' .. tf_assessment_cat .. ' ' .. (article and 'articles' or 'pages'))
end
local tf_importance, tf_importance_category
if raw_args['tf '..k..' importance'] then
tf_importance = importance_mask(raw_args['tf '..k..' importance'], args.IMPORTANCE_SCALE, banner_name, pagetype, class)
if tf_importance=='Unknown' and yesno(args.INHERIT_IMPORTANCE) then
tf_importance = importance
end
tf_importance_category = tf_importance .. '-' .. importance_name .. ' ' .. tf_assessment_cat .. ' ' .. (tf_importance=='NA' and 'pages' or 'articles')
add_category(tf_importance_category)
end
if args[tf_prefix .. 'TEXT']~='none' then
Line 549 ⟶ 572:
:gsub('_LINK_', args[tf_prefix .. 'LINK'] or '')
:gsub('_IMPORTANCE_', tf_importance or '')
:gsub('_PAGETYPE_', pagetype)
else
local tf_importance_text = tf_importance
Line 555 ⟶ 577:
and tf_importance~='Unknown'
and ' ' .. cfg.task_force.importance:format(
wikilink(
wikilink(':Category:' .. tf_importance .. '-' .. importance_name .. ' ' .. tf_assessment_cat, tf_importance .. '-' .. importance_name)
':Category:' .. tf_importance_category,
tf_importance .. '-' .. importance_name
)
) or ''
text = portal .. cfg.task_force.text:format(
pagetype,
wikilink(args[tf_prefix .. 'LINK'], args[tf_prefix .. 'NAME']),
tf_importance_text
Line 575 ⟶ 599:
:addClass('mbox-text')
:attr('colspan','2')
:wikitext(parse_pt(text))
:done()
table.insert(taskforce_output, taskforce)
Line 581 ⟶ 605:
if args[tf_prefix..'HOOK'] then
table.insert(taskforce_output, args[tf_prefix..'HOOK'])
end
if yesno(args[tf_prefix..'QUALITY']) and class then
local tf_class = check_exists(class, tf_assessment_cat)
add_category((tf_class=='' and 'Unassessed' or tf_class..'-Class') .. ' ' .. tf_assessment_cat)
end
if tf_importance then
add_category(tf_importance .. '-' .. importance_name .. ' ' .. tf_assessment_cat)
end
if args[tf_prefix..'QII_FORMAT'] then
add_category(require(auxiliary).quality_importance_insection(args, class, tf_importance, importance_name, tf_assessment_cat, article, tf_prefix))
end
if args[tf_prefix..'NAME'] then
Line 624 ⟶ 641:
add_category(note_args.category2, sort)
if note_args.text then
local note_image = image(
note_args.image_name,
note_args.size or note_default_size,
cfg.note.icon_alt,
'center')
)
local new_note = mw.html.create('tr')
:tag('td')
Line 633 ⟶ 655:
:addClass('mbox-text')
:attr('colspan', '2')
:wikitext(parse_pt(note_args.text))
:done()
table.insert(note_output, new_note)
Line 639 ⟶ 661:
local icon = mw.html.create('span')
:addClass('wpb-header-bubbles')
:wikitext('[[File:' .. note_args.image_name .. '|' .. cfg.note.header_icon .. '|' .. parse_pt(note_args.text) .. '|link=|alt=]]')
table.insert(nested_ratings, tostring(icon))
end
Line 654 ⟶ 676:
local auto_cat = args.AUTO_ASSESS_CAT or cfg.auto.default_cat:format(project)
local auto_text = cfg.auto.assessed:format(
pagetype,
cfg.auto[auto], -- method of automatic assessment
parameter_format('auto')
Line 677 ⟶ 698:
local attention_cat = args.ATTENTION_CAT or cfg.attention.default_cat:format(project)
render_note{
text = cfg.attention.text:format(pagetype),
image_name = cfg.attention.icon,
category = attention_cat
Line 685 ⟶ 706:
local infobox_cat = args.INFOBOX_CAT or cfg.infobox.default_cat:format(project)
render_note{
text = cfg.infobox.text:format(pagetype),
image_name = cfg.infobox.icon,
category = infobox_cat
Line 693 ⟶ 714:
local note_prefix = 'NOTE_' .. k .. '_'
render_note{
text = parse_textparse_pt(args[note_prefix..'TEXT']),
image_name = args[note_prefix..'IMAGE'],
size = args[note_prefix..'SIZE'],
Line 700 ⟶ 721:
end
if yesno(args['image-needed'], true) then
local image_needed_args = require(auxiliary).image_needed(args, pagetype)
render_note(image_needed_args)
end
if yesno(args['collaboration-candidate'], true) or yesno(args['collaboration-current'], true) or yesno(args['collaboration-past'], true) then
local collaboration_args = require(auxiliary).collaboration(args, pagetype, current_title)
render_note(collaboration_args.candidate)
render_note(collaboration_args.current)
Line 751 ⟶ 772:
:tag('td')
:attr('colspan','3')
:wikitext(parse_textparse_pt(args.BOTTOM_TEXT))
:done()
table.insert(rows, bottom_text)
Line 789 ⟶ 810:
:wikitext(wikilink(project_link.prefixedText, project) .. nested_tf_str .. ' ' .. nested_ratings_str)
:done()
---------------------------
-- Default sort -----------
---------------------------
if args.listas then
frame:preprocess('{{DEFAULTSORT:' .. args.listas .. '}}')
if title.namespace~=3 then -- exclude user talk namespace
local success, shell_listas_value = require('Module:Template parameter value').getParameter(
title.prefixedText,
cfg.banner_shell.redirects,
'listas',
{ignore_subtemplates = true, ignore_blank = true}
)
if success and shell_listas_value~='' then
if args.listas==shell_listas_value then-- same value in both (with spacing trimming)
add_category('WikiProject banners with redundant listas value')
end
else-- listas is blank or not defined in banner shell
add_category('WikiProject banners with listas value which needs moving to banner shell')
end
end
end
---------------------------
-- Prepare categories -----
Line 843:
local banner = mw.html.create('table')
:addClass('tmbox tmbox-notice mw-collapsible innercollapse wpb wpb-table')
:addClass(inactive and cfg.statusinactive.inactive_classclass or nil)
:node(header_row)
:tag('tr')
Line 863:
local category = parent_args.category or args.category or true
local demo_page = parent_args.demo_page
local config, project
if args.project then -- check for config page
project = args.project
local config_file = mw.title.new('Template:WikiProject ' .. args.project .. '/config')
if config_file.exists then
config = mw.loadJsonData(config_file.fullText)
else
return nil
end
end
if config then -- use config file
if parent_args.taskforce then -- split comma-separated list
for taskforce in mw.text.gsplit(parent_args.taskforce, ',%s*') do
parent_args[taskforce] = 'yes'
end
end
args, raw_args = require(auxiliary).map_config(config, parent_args) -- map parameters from config page
args.PROJECT = project
end
local on_template_page = false
local banner_name = mw.title.new(args.BANNER_NAME or 'Template:WikiProject ' .. (args.PROJECT or 'PROJECT'))
Line 879 ⟶ 898:
table.insert(parameters, parameter)
end
parameters.showblankpositional = "1"
local check_for_unknown = require('Module:Check for unknown parameters')._check
local unknowns = check_for_unknown(parameters, parent_args)
if unknowns and unknowns~='' then -- there are some unknown parameters
parameters.preview = cfg.unknown_parameters.preview:format(wikilink(banner_name.fullText))
local unknown_category = cfg.unknown_parameters.tracking:format(project_name)
Line 893 ⟶ 913:
if on_template_page then
local templatepage = require('Module:WikiProject banner/templatepage' .. (sandbox or '')).templatepage
return templatepage(args, raw_args, inactive_status, config)
else
return unknown_parameters
Line 912 ⟶ 932:
local project_name = args.PROJECT_NAME or 'WikiProject ' .. (args.PROJECT or 'PROJECT')
local project_link = mw.title.new(args.PROJECT_LINK or 'Wikipedia:' .. project_name)
local _status = cfg.inactive.status[args.PROJECT_STATUS] or cfg.statusinactive.default_inactivedefault
local main_text = cfg.inactive.text:format(
'_PAGETYPE_',
project_link.prefixedText,
project_name,