Content deleted Content added
implement class colours from templatestyles |
m Removed protection from "Module:WikiProject banner/sandbox" |
||
(184 intermediate revisions by 7 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
---------------------------
-- Importance mask --------
Line 77 ⟶ 67:
end
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()]
importance = cfg.importance.unknown
end
end
end
Line 103 ⟶ 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 115 ⟶ 104:
elseif pagetype=='disambiguation page' then
out = resolveFQSgrade('disambig')
elseif article or pagetype=='article' or pagetype=='set index article' then
if
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 126 ⟶ 117:
end
elseif ns==7 or ns==711 then -- File talk
if class=='fm'
out = 'FM'
else
Line 132 ⟶ 123:
end
else
local grade = cfg.quality.ns_to_class[ns] or 'NA'
out = resolveFQSgrade(grade)
end
return out
Line 156 ⟶ 138:
:addClass('wpb-header-bubbles')
:addClass(style)
:addClass(conflict and 'conflict' or nil)
:wikitext(text)
return tostring(out)
Line 168 ⟶ 150:
local project_name = args.PROJECT_NAME or 'WikiProject ' .. project
local project_link = mw.title.new(args.PROJECT_LINK or 'Wikipedia:' .. project_name)
local pagetype = demo_page==true and 'article' or require('Module:Pagetype
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 178 ⟶ 163:
end
end
local
local ptype = article and 'article' or pagetype -- display "article" for articles otherwise page type
return text and text:gsub('_PAGETYPE_', ptype)
end
for arg_name, arg_value in pairs(args) do
Line 200 ⟶ 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 text = cfg.namespace_warning.text:format(
current_title.talkPageTitle.fullText,
parameter_format('category', 'no')
Line 221 ⟶ 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 244 ⟶ 236:
-- Primary image/text -----
---------------------------
local primary_image = function(image_name, size)
local cell = mw.html.create('td')
if image_name and image_name~='' then
cell:addClass('mbox-image wpb-image')
:wikitext(image(image_name, size, cfg.image.alt))
else
Line 258 ⟶ 248:
local portal = args.PORTAL
local portal_box = portal and frame:expandTemplate{title='Portal', args={portal}} or ''
local main_text = portal_box ..
project_link.prefixedText,
project_name,
Line 294 ⟶ 283:
local special_chars = '([%%%(%)%.%+%-%*%?%[%]%^%$])'
local banner_name_escaped = banner_name.text
local page_content = require('Module:Wikitext Parsing').PrepareText(title:getContent()) -- get content of current page
local content_without_shell
for capture in mw.ustring.gmatch(page_content, '%b{}') do -- look for possible templates on page
Line 312 ⟶ 301:
end
else -- no banner shell on page
if
add_category(cfg.banner_shell.category.no_banner_shell_articles)
elseif title.namespace==3 then --User talk namespace
Line 320 ⟶ 309:
end
end
elseif title.namespace~=2 then --User namespace
add_category(cfg.banner_shell.category.no_banner_shell)
end
Line 334 ⟶ 323:
assessment_link = nil
end
local
if article or args.QUALITY_CRITERIA=='custom' then -- no fallbacks for articles or projects with custom quality scales
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)
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 372 ⟶ 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 = check_fallbacks(article_class, assessment_cat) -- check fallbacks again now that class may have changed
check_redundant()
check_redundant()
elseif article_class=='' then -- local class defined and no article class defined
show = true
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
class = check_fallbacks('FM', assessment_cat)
check_redundant()
elseif not article and class~='FM' then -- article class and local class are both non-article classes
check_redundant()
elseif args.QUALITY_CRITERIA=='custom' then -- project uses custom criteria and class differs
show = true -- show quality class in project banner
else -- article class exists and differs from local class
show = 'conflict'
add_category(cfg.banner_shell.conflict.category2:format(class, article_class))
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
local rating
if
rating = class=='' and cfg.quality.not_yet or cfg.quality.rated:format(class)
else
Line 418 ⟶ 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 or cfg.quality.rating:format( local cssClass = 'class-' .. (class=='' and 'unassessed' or class:lower())
local class_row = mw.html.create('tr')
Line 425:
:addClass('assess')
:addClass(cssClass)
:addClass(show=='conflict' and 'conflict' or nil)
:wikitext(wikilink(':Category:' .. category, class=='' and '???' or class))
:done()
:tag('td')
:addClass('mbox-text')
:attr('colspan', '2')
:wikitext(parse_pt(quality_rating))
:done()
table.insert(rows, class_row)
Line 437:
nested_ratings,
1,
bubble(class=='' and 'Unassessed' or (class..'‑class'), show=='conflict', cssClass)
)
end
Line 452:
-- Importance assessment --
---------------------------
local importance = importance_mask(raw_args.importance or raw_args.priority
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 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(
local importance_row = mw.html.create('tr')
:tag('td')
Line 480 ⟶ 479:
table.insert(
nested_ratings,
bubble(importance .. '‑' .. importance_name, false, cssClass)
)
end
Line 486 ⟶ 485:
add_category(category)
end
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 542 ⟶ 543:
for _, k in ipairs(task_forces) do
local tf_prefix = 'TF_' .. k .. '_'
local tf_assessment_cat = assessment_category(
args[tf_prefix..'ASSESSMENT_CAT'] args[tf_prefix..'NAME'] )
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']
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 562 ⟶ 572:
:gsub('_LINK_', args[tf_prefix .. 'LINK'] or '')
:gsub('_IMPORTANCE_', tf_importance or '')
else
local tf_importance_text = tf_importance
Line 568 ⟶ 577:
and tf_importance~='Unknown'
and ' ' .. cfg.task_force.importance:format(
wikilink(
':Category:' .. tf_importance_category,
tf_importance .. '-' .. importance_name
)
) or ''
text = portal .. cfg.task_force.text:format(
wikilink(args[tf_prefix .. 'LINK'], args[tf_prefix .. 'NAME']),
tf_importance_text
Line 588 ⟶ 599:
:addClass('mbox-text')
:attr('colspan','2')
:wikitext(parse_pt(text))
:done()
table.insert(taskforce_output, taskforce)
Line 594 ⟶ 605:
if args[tf_prefix..'HOOK'] then
table.insert(taskforce_output, args[tf_prefix..'HOOK'])
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 637 ⟶ 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 646 ⟶ 655:
:addClass('mbox-text')
:attr('colspan', '2')
:wikitext(parse_pt(note_args.text))
:done()
table.insert(note_output, new_note)
Line 652 ⟶ 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 667 ⟶ 676:
local auto_cat = args.AUTO_ASSESS_CAT or cfg.auto.default_cat:format(project)
local auto_text = cfg.auto.assessed:format(
cfg.auto[auto], -- method of automatic assessment
parameter_format('auto')
Line 690 ⟶ 698:
local attention_cat = args.ATTENTION_CAT or cfg.attention.default_cat:format(project)
render_note{
text = cfg.attention.text
image_name = cfg.attention.icon,
category = attention_cat
Line 698 ⟶ 706:
local infobox_cat = args.INFOBOX_CAT or cfg.infobox.default_cat:format(project)
render_note{
text = cfg.infobox.text
image_name = cfg.infobox.icon,
category = infobox_cat
Line 706 ⟶ 714:
local note_prefix = 'NOTE_' .. k .. '_'
render_note{
text =
image_name = args[note_prefix..'IMAGE'],
size = args[note_prefix..'SIZE'],
Line 713 ⟶ 721:
end
if yesno(args['image-needed'], true) then
local image_needed_args = require(auxiliary).image_needed(args
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
render_note(collaboration_args.candidate)
render_note(collaboration_args.current)
Line 764 ⟶ 772:
:tag('td')
:attr('colspan','3')
:wikitext(
:done()
table.insert(rows, bottom_text)
Line 802 ⟶ 810:
:wikitext(wikilink(project_link.prefixedText, project) .. nested_tf_str .. ' ' .. nested_ratings_str)
:done()
---------------------------
-- Prepare categories -----
Line 856 ⟶ 843:
local banner = mw.html.create('table')
:addClass('tmbox tmbox-notice mw-collapsible innercollapse wpb wpb-table')
:addClass(inactive and cfg.
:node(header_row)
:tag('tr')
Line 876 ⟶ 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 892 ⟶ 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 906 ⟶ 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 925 ⟶ 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.
local main_text = cfg.inactive.text:format(
project_link.prefixedText,
project_name,
|