Module:WikiProject banner/templatepage/sandbox: Difference between revisions
Appearance
Content deleted Content added
not needed |
Harryboyles (talk | contribs) for auto-documentation, check every parameter to see if it's actually used by the WikiProject (e.g. Template:WikiProject Classical music doesn't support class ratings) |
||
Line 570: | Line 570: | ||
table.insert(auto_doc, 'Place this on the talk page of relevant articles:') |
table.insert(auto_doc, 'Place this on the talk page of relevant articles:') |
||
table.insert(auto_doc, '<br><code>{{' .. banner_name.text .. ' ') |
table.insert(auto_doc, '<br><code>{{' .. banner_name.text .. ' ') |
||
if raw_args.class then |
|||
⚫ | |||
end |
|||
if raw_args.importance then |
if raw_args.importance then |
||
show_param('importance') |
show_param('importance') |
||
elseif raw_args.priority then |
|||
else |
|||
show_param('priority') |
show_param('priority') |
||
end |
end |
||
Line 580: | Line 582: | ||
table.insert(auto_doc, 'It is usual to remove any unused parameters from the template call.') |
table.insert(auto_doc, 'It is usual to remove any unused parameters from the template call.') |
||
table.insert(auto_doc, '<br><code>{{' .. banner_name.text .. ' ') |
table.insert(auto_doc, '<br><code>{{' .. banner_name.text .. ' ') |
||
if raw_args.class then |
|||
show_param('class') |
|||
end |
|||
if raw_args.importance then |
if raw_args.importance then |
||
show_param('importance') |
show_param('importance') |
||
elseif raw_args.priority then |
|||
else |
|||
show_param('priority') |
show_param('priority') |
||
end |
end |
||
if raw_args.listas then |
|||
show_param(' |
show_param('listas') |
||
end |
|||
⚫ | |||
if raw_args.attention then |
|||
show_param('attention') |
|||
end |
|||
if raw_args.infobox then |
|||
show_param('infobox') |
|||
end |
|||
for _, k in ipairs(notes) do |
for _, k in ipairs(notes) do |
||
show_param('note ' .. k) |
show_param('note ' .. k) |
||
Line 594: | Line 604: | ||
for _, k in ipairs(task_forces) do |
for _, k in ipairs(task_forces) do |
||
show_param('tf ' .. k) |
show_param('tf ' .. k) |
||
if raw_args['tf ' .. k .. ' importance'] then |
|||
show_param('tf ' .. k .. ' importance') |
|||
end |
|||
end |
end |
||
table.insert(auto_doc, '}}</code>') |
table.insert(auto_doc, '}}</code>') |
Revision as of 15:36, 2 January 2024
![]() | This is the module sandbox page for Module:WikiProject banner/templatepage (diff). |
![]() | 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. |
WikiProject banners |
---|
Module |
Template:WPBannerMeta |
Config |
Styles |
Auxiliary |
templatepage |
Category (errors) |
This submodule of Module:WikiProject banner produces the output which will be displayed on WikiProject banner template pages. It will be displayed automatically on the following pages:
- Pages of the form Template:WikiProject PROJECT
- Pages specified by the BANNER_NAME parameter (if used)
The module produces the following main components:
- An example of the output of the template it is displayed on. This includes a demonstration of all assessments, notes, task forces that the template is set up for.
- Notices about the configuration of the template.
- Warnings about any missing categories needed by the template.
- Relevant template categories (e.g. Category:WikiProject banners with quality assessment).
- Automatically produced documentation (if selected), migrated from Template:WPBannerDoc and Template:Class mask/templatepage
require('strict')
local p = {}
p.templatepage = function(args, raw_args, inactive)
local wikilink = function(link, display)
if link then
return display and '[['..link..'|'..display..']]' or '[['..link..']]'
else
return display or ''
end
end
---------------------------
-- Initialise variables ---
---------------------------
local sandbox = '/sandbox'
local cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or ''))
local cfg_tp = cfg.template_page -- convenient shortcut for template_page configuration settings
local lang = mw.language.getContentLanguage()
local current_page = mw.title.getCurrentTitle()
local on_sandbox = lang:lc(current_page.subpageText)=='sandbox' -- on sandbox subpage
or current_page.namespace==2 -- in User namespace
or current_page.rootText=='WPBannerMeta' -- subpage of Template:WPBannerMeta
local frame = mw.getCurrentFrame()
local parameter_format = function(parameter, value)
local code = parameter and mw.html.create('code')
:addClass('tpl-para')
:css('word-break', 'break-word')
:wikitext('|' .. parameter .. '=' .. (value or ''))
:done()
return tostring(code)
end
local yesno = require('Module:Yesno')
local messageBox = require('Module:Message box').main
local project = args.PROJECT or ''
local banner_name = mw.title.new(args.BANNER_NAME or 'Template:WikiProject ' .. project)
local notices, tracking_cats = {}, {}
local add_tracking = function(tracking, show_on_sandbox)
local category = tracking.category or cfg_tp.default_tracking -- uses [[Category:WikiProject banners with errors]] by default
local key = tracking.sort_key or (project~='' and project or '*') -- sort key defaults to name of project
if not on_sandbox or show_on_sandbox then
table.insert(tracking_cats, wikilink('Category:' .. category, key))
end
end
local project_link = args.PROJECT_LINK or 'Wikipedia:WikiProject ' .. project
---------------------------
-- Count notes/taskforces -
---------------------------
local task_forces, notes, taskforce_categories = {}, {}, {}
for arg_name, _ in pairs(raw_args) do
local tf_match = mw.ustring.match(arg_name,'^tf (%d+)$')
if tf_match then
table.insert(task_forces, tf_match)
end
local tf, cat = mw.ustring.match(arg_name,'^tf (%d+) cat (%d+)$')
if tf then
if not taskforce_categories[tf] then-- initialise table
taskforce_categories[tf] = {}
end
table.insert(taskforce_categories[tf], cat)
end
local note_match = mw.ustring.match(arg_name,'^note (%d+)$')
if note_match then
table.insert(notes, note_match)
end
end
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)
---------------------------
-- Demonstrative banner ---
---------------------------
args.PROJECT = args.PROJECT or ''
args.class = raw_args.class and not inactive and 'C'
args.importance = raw_args.importance and 'High'
args.priority = raw_args.priority and 'High'
args.auto = raw_args.auto and 'inherit'
args.attention = raw_args.attention and 'yes'
args.infobox = raw_args.infobox and 'yes'
args.b1 = raw_args.b1 and 'yes'
args.b2 = raw_args.b2 and 'no'
args.b3 = raw_args.b3 and 'foo'
args.b4 = raw_args.b4 and 'yes'
args.b5 = raw_args.b5 and 'na'
args.b6 = raw_args.b6
args['image-needed'] = raw_args['image-needed'] and 'yes'
args['collaboration-candidate'] = raw_args['collaboration-candidate'] and 'yes'
args['collaboration-current'] = raw_args['collaboration-current'] and 'yes'
args['collaboration-past'] = raw_args['collaboration-past'] and 'yes'
args['a class'] = raw_args['a class'] and 'current'
args['peer review'] = raw_args['peer review'] and 'yes'
args['old peer review'] = raw_args['old peer review'] and 'yes'
for _, tf in ipairs(task_forces) do
args['tf '..tf] = 'yes'
if raw_args['tf '..tf..' importance'] then
args['tf '..tf..' importance'] = 'Top'
end
end
for _, note in ipairs(notes) do
local text_arg = args['NOTE_'..note..'_TEXT']
if text_arg and text_arg~='' then
args['note '..note] = 'yes'
end
end
local demo_banner, note_count, tf_count, assessment_link = require('Module:WikiProject banner' .. (sandbox or ''))._main(args, args, true, banner_name)
if not assessment_link then --temporary code until main module updated
assessment_link = args.ASSESSMENT_LINK
end
if not assessment_link then
local project_name = args.PROJECT_NAME or 'WikiProject ' .. project
local project_link = mw.title.new(args.PROJECT_LINK or 'Wikipedia:' .. project_name)
local fallback = mw.title.new(project_link.prefixedText .. '/Assessment')
assessment_link = fallback.exists and fallback.prefixedText
elseif assessment_link=='no' then
assessment_link = nil
end
---------------------------
-- Project status ---------
---------------------------
local status = args.PROJECT_STATUS and cfg.status[args.PROJECT_STATUS]
if inactive then
table.insert(notices, cfg_tp.inactive:format(status or 'inactive'))
elseif status then
table.insert(notices, 'The status of this project has been identified as ' .. status .. '.')
end
---------------------------
-- Quality criteria -------
---------------------------
local custom_mask = banner_name:subPageTitle('class')
if args.QUALITY_CRITERIA=='custom' then
add_tracking(cfg_tp.quality_criteria.custom_tracking)
if custom_mask.exists and #custom_mask:getContent()>1 then
table.insert(notices, cfg_tp.quality_criteria.custom:format(
custom_mask.prefixedText
))
else
table.insert(notices, string.format(
cfg_tp.quality_criteria.missing,
parameter_format('QUALITY_CRITERIA'),
custom_mask.prefixedText
))
end
end
local b_checklist = raw_args.b1 or raw_args.b2 or raw_args.b3 or raw_args.b4 or raw_args.b5 or raw_args.b6
if b_checklist then
if args.QUALITY_CRITERIA=='custom' then
add_tracking{category='WikiProject banners using a B-class checklist'}
else
table.insert(notices, 'Per consensus at [[Wikipedia talk:WikiProject Council#Determining the future of B-class checklists]], the B-class checklist has been removed from this template.')
end
end
---------------------------
-- Custom importance mask -
---------------------------
local custom_mask = banner_name:subPageTitle('importance')
if args.IMPORTANCE_SCALE=='subpage' then
if custom_mask.exists and #custom_mask:getContent()>1 then
table.insert(notices, string.format(
cfg_tp.custom_importance_mask.in_use,
custom_mask.prefixedText
))
else
table.insert(notices, string.format(
cfg_tp.custom_importance_mask.missing,
parameter_format('IMPORTANCE_SCALE'),
custom_mask.prefixedText
))
end
elseif custom_mask.exists and #custom_mask:getContent()>1 then
table.insert(notices, string.format(
cfg_tp.custom_importance_mask.unused,
custom_mask.prefixedText,
parameter_format('IMPORTANCE_SCALE','subpage')
))
end
---------------------------
-- Collapsed sections -----
---------------------------
local more_than = function(n)
return n>=2 and string.format(cfg_tp.more_than.more, tostring(n))
or n==1 and cfg_tp.more_than.one
or n==0 and cfg_tp.more_than.zero
end
local tf_threshold = tonumber(args.TF_COLLAPSE) or (args.TF_HEADER and cfg.task_force.lower_threshold) or cfg.task_force.upper_threshold
if tf_count > tf_threshold then
table.insert(notices, string.format(
cfg_tp.task_force.collapsing,
tf_count,
more_than(tf_threshold),
parameter_format('TF_COLLAPSE')
))
end
local note_threshold = tonumber(args.COLLAPSED) or 2
local hook_collapsed
if args.HOOK_COLLAPSED then
local success, result = pcall(mw.ext.ParserFunctions.expr, args.HOOK_COLLAPSED)
hook_collapsed = success and tonumber(result) or nil
if args.HOOK_COLLAPSED=='auto' then
hook_collapsed = args.HOOK_NOTE and 1 or 0 -- default assumption is that HOOK_NOTE produces max one note
end
end
if note_count > note_threshold then
table.insert(notices, string.format(
cfg_tp.note.collapsing,
note_count,
more_than(note_threshold),
parameter_format('COLLAPSED')
))
end
if args.HOOK_NOTE then
if not hook_collapsed then
table.insert(notices, string.format(
cfg_tp.note.counter,
parameter_format('HOOK_NOTE'),
parameter_format('HOOK_COLLAPSED')
))
add_tracking(cfg_tp.note.tracking)
end
end
---------------------------
-- Assessment link --------
---------------------------
if raw_args.class or raw_args.importance then
local url = mw.uri.fullUrl(banner_name.prefixedText,{
action = 'edit',
summary = cfg_tp.assessment_link.edit_summary
})
if args.ASSESSMENT_LINK then
if not mw.title.new(args.ASSESSMENT_LINK).exists then
table.insert(notices, string.format(
cfg_tp.assessment_link.missing,
wikilink(args.ASSESSMENT_LINK),
tostring(url),
parameter_format('ASSESSMENT_LINK')
))
end
end
end
---------------------------
-- Project parameter ------
---------------------------
if args.PROJECT=='' then
table.insert(notices, cfg_tp.project.text)
add_tracking(cfg_tp.project.tracking)
end
---------------------------
-- Subst check ------------
---------------------------
if not raw_args.substcheck then
table.insert(notices, string.format(
cfg_tp.substcheck.text,
parameter_format('substcheck')
))
add_tracking(cfg_tp.substcheck.tracking)
end
---------------------------
-- Portal link ------------
---------------------------
if args.PORTAL then
local portal_image = require('Module:Portal')._image(args.PORTAL)
local portal_link = mw.title.new('Portal:' .. args.PORTAL)
local explain
if portal_link and portal_link.exists then
if portal_image=='Portal-puzzle.svg' then
explain = string.format(cfg_tp.portal.no_image, cfg_tp.portal.instructions)
else
explain = string.format(
cfg_tp.portal.image_link,
wikilink(':File:' .. portal_image),
cfg_tp.portal.instructions
)
end
else
explain = string.format(cfg_tp.portal.missing, parameter_format('PORTAL'))
add_tracking(cfg_tp.portal.tracking)
end
local text = string.format(
cfg_tp.portal.text,
portal_link.prefixedText,
explain
)
table.insert(notices, text)
end
---------------------------
-- Task forces ------------
---------------------------
for _, k in ipairs(task_forces) do
local name_parameter = 'TF_'..k..'_NAME'
if raw_args['tf '..k] and not args['TF_'..k..'_NAME'] then
table.insert(notices, string.format(
cfg_tp.task_force.text,
parameter_format('TF_'..k..'_NAME')
))
add_tracking(cfg_tp.task_force.tracking)
end
end
---------------------------
-- Parameter checking -----
---------------------------
if not inactive then
local category = mw.title.new(cfg.unknown_parameters.tracking:format(
args.PROJECT_NAME or 'WikiProject ' .. project
))
local text = string.format(
category.exists and cfg_tp.parameters.tracking or cfg_tp.parameters.create,
':' .. category.fullText
)
table.insert(notices, text)
end
---------------------------
-- Assessment categories --
---------------------------
local importance_name = args.IMPN or (raw_args.priority and 'priority' or cfg.importance.default_name)
local check_assessment_categories = function(project, assessment_cat, quality, importance_scale, prefix, tf_name)
assessment_cat = assessment_cat or ((project or '') .. ' articles')
local missing_cats = {}
local red_cats_in_use = false
local check_cat = function(cat_name, preload)
local category = mw.title.new('Category:' .. cat_name)
if not category.exists then
local url = mw.uri.fullUrl('Category:' .. cat_name, {
action = 'edit',
preload = preload,
editintro = cfg_tp.check_assessment.editintro,
preview = 'no',
summary = cfg_tp.check_assessment.create_summary,
['preloadparams[1]'] = project,
['preloadparams[2]'] = mw.ustring.gsub(assessment_cat, ' articles', '')
})
local pages_in_category = mw.site.stats.pagesInCategory(cat_name, 'pages')
if pages_in_category>0 then
red_cats_in_use = true
end
local label = pages_in_category>0 and '<b>create</b>' or 'create'
local create_link = wikilink(':' .. category.prefixedText) .. ' – ([' .. tostring(url) .. ' ' .. label .. '])'
table.insert(missing_cats, create_link)
end
end
if quality then
check_cat(lang:ucfirst(assessment_cat) .. ' by quality', cfg_tp.check_assessment.meta_preload)
for _, class in ipairs(cfg_tp.check_assessment.classes) do
local cat_name = (class=='Unassessed' and 'Unassessed' or class..'-Class') .. ' ' .. assessment_cat
check_cat(cat_name, cfg_tp.check_assessment.quality_preload)
end
end
if importance_scale and importance_scale~='inline' and importance_scale~='subpage' then
check_cat(lang:ucfirst(assessment_cat) .. ' by ' .. importance_name, cfg_tp.check_assessment.meta_preload)
for _, importance in ipairs(cfg_tp.check_assessment.importances) do
local cat_name = importance .. '-' .. importance_name .. ' ' .. assessment_cat
check_cat(cat_name, cfg_tp.check_assessment.importance_preload)
end
end
if #missing_cats>0 then
local intro = string.format(
cfg_tp.check_assessment.text,
tf_name or project or '',
parameter_format((prefix or '') .. cfg_tp.check_assessment.parameter_suffix)
)
local list = mw.html.create('ul')
for _, missing in ipairs(missing_cats) do
list:tag('li'):wikitext(missing):done()
end
list:done()
if red_cats_in_use then
add_tracking(cfg_tp.check_assessment.tracking)
end
return messageBox('ombox', {
type = 'content',
image = '[[File:' .. cfg_tp.check_assessment.icon .. '|50px]]',
text = intro .. tostring(list)
})
end
return ''
end
local missing_cats, warnings = {}, {}
local red_other_cats_in_use = false
local check_other_category = function(cat_name)
if cat_name and cat_name~='none' then
local category = mw.title.new('Category:' .. (cat_name or ''))
if category and not category.exists then
local pages_in_category = mw.site.stats.pagesInCategory(cat_name, 'pages')
if pages_in_category>0 then
red_other_cats_in_use = true
end
table.insert(missing_cats, wikilink(':' .. category.prefixedText))
end
end
end
table.insert(warnings, check_assessment_categories(
project,
args.ASSESSMENT_CAT,
raw_args.class and args.QUALITY_CRITERIA~='custom',
(raw_args.importance or raw_args.priority) and (args.IMPORTANCE_SCALE or '')
))
local ntf, check_task_forces = #task_forces, {}
if ntf>10 then -- too many task forces to check all, so check a selection instead
local used = {}
math.randomseed(os.time())
for i = 1, 10 do
local new
repeat
new = math.random(ntf)
until not used[new]
table.insert(check_task_forces, task_forces[new])
used[new] = true
end
table.sort(check_task_forces, function (x, y) return tonumber(x) < tonumber(y) end)
table.insert(notices, string.format(cfg_tp.check_assessment.too_many, table.concat(check_task_forces,', ')))
else
check_task_forces = task_forces
end
for _, k in ipairs(check_task_forces) do
local tf_prefix = 'TF_' .. k .. '_'
table.insert(warnings, check_assessment_categories(
project,
args[tf_prefix..'ASSESSMENT_CAT'] or (args[tf_prefix..'NAME'] or '')..' articles',
raw_args.class and yesno(args[tf_prefix..'QUALITY']) and args.QUALITY_CRITERIA~='custom',
raw_args['tf '..k..' importance'] and (args.IMPORTANCE_SCALE or ''),
tf_prefix,
args[tf_prefix..'NAME']
))
check_other_category(args[tf_prefix .. 'MAIN_CAT'])
for _, p in ipairs(taskforce_categories[k] or {}) do
check_other_category(args[tf_prefix .. 'CAT_' .. p])
end
end
---------------------------
-- Template categories ----
---------------------------
if on_sandbox then
add_tracking(cfg_tp.template_categories.sandbox, true)
elseif inactive then
add_tracking(cfg_tp.template_categories.inactive)
else
if raw_args.class then
add_tracking(cfg_tp.template_categories.with_quality)
else
add_tracking(cfg_tp.template_categories.without_quality)
end
if (args.PROJECT_NAME=='WikiProject '..project or not args.PROJECT_NAME) and current_page.rootPageTitle.prefixedText~='Template:WikiProject ' .. project then
add_tracking(cfg_tp.template_categories.non_standard)
end
end
---------------------------
-- Check parameters -------
---------------------------
local parameters = {}
local append_table = function(source)
for _, v in ipairs(source) do
table.insert(parameters, v)
end
end
append_table(cfg_tp.parameters.parameters)
for _, k in ipairs(task_forces) do
local task_force_parameters = {'tf '..k, 'tf '..k..' importance'}
local prefix = string.format(cfg_tp.parameters.taskforce.prefix, k)
for _, p in ipairs(cfg_tp.parameters.taskforce.suffix) do
table.insert(task_force_parameters, prefix .. p)
end
for _, p in ipairs(taskforce_categories[k] or {}) do
table.insert(task_force_parameters, 'tf ' .. k .. ' cat ' .. p)
table.insert(task_force_parameters, prefix .. 'CAT_' .. p)
end
append_table(task_force_parameters)
end
for _, k in ipairs(notes) do
local note_parameters = {'note '..k}
local prefix = string.format(cfg_tp.parameters.note.prefix, k)
for _, p in ipairs(cfg_tp.parameters.note.suffix) do
table.insert(note_parameters, prefix .. p)
end
append_table(note_parameters)
check_other_category(args[prefix .. 'CAT'])
end
for _, set in ipairs(cfg_tp.parameters.extra) do
local allow_parameters = false
if set.trigger then
table.insert(parameters, set.trigger)
allow_parameters = raw_args[set.trigger] and true
elseif set.triggers then
append_table(set.triggers)
for _, trig in ipairs(set.triggers) do
if raw_args[trig] then
allow_parameters = true
end
end
end
if allow_parameters then
append_table(set.parameters)
if set.categories then
append_table(set.categories)
for _, cat in ipairs(set.categories) do
check_other_category(args[cat])
end
end
end
end
parameters.preview = cfg_tp.parameters.preview
parameters.unknown = on_sandbox and '' or cfg_tp.parameters.category
local parameter_check = current_page.rootPageTitle.text=='WikiProject Military history' and ''
or require('Module:Check for unknown parameters')._check(parameters, raw_args)
---------------------------
-- Other categories -------
---------------------------
if raw_args.attention then
local attention_cat = args.ATTENTION_CAT or string.format(cfg.attention.default_cat, project)
check_other_category(attention_cat)
end
if raw_args.infobox then
local infobox_cat = args.INFOBOX_CAT or string.format(cfg.infobox.default_cat, project)
check_other_category(infobox_cat)
end
if raw_args.auto then
local auto_cat = args.AUTO_ASSESS_CAT or string.format(cfg.auto.default_cat, project)
check_other_category(auto_cat)
end
check_other_category(args.MAIN_CAT)
if #missing_cats>0 then
local list = mw.html.create('ul')
for _, missing in ipairs(missing_cats) do
list:tag('li'):wikitext(missing):done()
end
list:done()
table.insert(warnings, messageBox('ombox', {
type = 'content',
image = '[[File:' .. cfg_tp.check_other.icon .. '|50px]]',
text = cfg_tp.check_other.text .. tostring(list)
}))
if red_other_cats_in_use then
add_tracking(cfg_tp.check_other.tracking)
end
end
---------------------------
-- Produce notices --------
---------------------------
local notice_html, notice_list
if #notices>=1 then
notice_html = mw.html.create('ul')
for _, notice in ipairs(notices) do
notice_html:tag('li'):wikitext(notice):done()
end
notice_list = ' ' .. cfg_tp.notice_text .. tostring(notice_html)
end
local info = messageBox('ombox', {
type = 'notice',
image = '[[File:Icon tools.svg|50px]]',
text = cfg_tp.info .. (notice_list or '')
})
---------------------------
-- Auto documentation -----
---------------------------
local auto_doc, parameter_name = {}, {}
local class_module = require('Module:Class')
local template_code = mw.title.getCurrentTitle():getContent()
for _, parameter in ipairs(parameters) do
parameter_name[parameter] = string.match(template_code, parameter..'%s*=%s*{%{%{([%a%d_%s-]*)')
end
local show_param = function(parameter)
local p = parameter_name[parameter] or parameter
if p then
table.insert(auto_doc, '|' .. p .. '= ')
end
end
local add_title = function(title, level)
local hl = 'h' .. tostring(level or 2)
table.insert(auto_doc, tostring(mw.html.create(hl):wikitext(title)) .. '\n')
end
table.insert(auto_doc, 'This is the WikiProject banner template used by ' .. wikilink(project_link, (args.PROJECT_NAME or 'WikiProject ' .. project)) .. ' to keep track of articles within its scope. ')
if args.MAIN_CAT then
table.insert(auto_doc, 'All articles are categorised into [[:Category:' .. args.MAIN_CAT .. ']].')
end
add_title('Basic usage', 3)
table.insert(auto_doc, 'Place this on the talk page of relevant articles:')
table.insert(auto_doc, '<br><code>{{' .. banner_name.text .. ' ')
if raw_args.class then
show_param('class')
end
if raw_args.importance then
show_param('importance')
elseif raw_args.priority then
show_param('priority')
end
table.insert(auto_doc, '}}</code>')
add_title('Full usage', 3)
table.insert(auto_doc, 'It is usual to remove any unused parameters from the template call.')
table.insert(auto_doc, '<br><code>{{' .. banner_name.text .. ' ')
if raw_args.class then
show_param('class')
end
if raw_args.importance then
show_param('importance')
elseif raw_args.priority then
show_param('priority')
end
if raw_args.listas then
show_param('listas')
end
if raw_args.attention then
show_param('attention')
end
if raw_args.infobox then
show_param('infobox')
end
for _, k in ipairs(notes) do
show_param('note ' .. k)
end
for _, k in ipairs(task_forces) do
show_param('tf ' .. k)
if raw_args['tf ' .. k .. ' importance'] then
show_param('tf ' .. k .. ' importance')
end
end
table.insert(auto_doc, '}}</code>')
local list_item = function(text)
return mw.html.create('li'):wikitext(text):done()
end
add_title('Parameters')
local parameter_list = {}
local add_list = function()
local out = mw.html.create('ul')
for _, v in ipairs(parameter_list) do
out:node(v)
end
table.insert(auto_doc, tostring(out:done()))
parameter_list = {} -- reset list to blank
end
local parameter_description = function(parameter, text)
local trigger = raw_args[parameter]
if trigger then
local p_name = parameter_name[parameter] or parameter
for params in text:gmatch('_PARAMETER%|?%a*_') do
end
if p_name then
local desc = '<b>' .. p_name .. '</b> – ' .. text
:gsub('_PARAMETER_', parameter_format(p_name))
:gsub('_PARAMETER%|?(%a*)_', parameter_format(p_name, '%1'))
:gsub('_PAGETYPE_', 'article')
table.insert(parameter_list, list_item(desc))
end
end
end
parameter_description('category', cfg.auto_doc.category)
parameter_description('listas', cfg.auto_doc.listas:format(
'John Smith', parameter_format('listas', 'Smith, John'), 'Smith', 'John',
'The Matrix', parameter_format('listas', 'Matrix, The'), 'Matrix'
))
parameter_description('class', cfg.auto_doc.quality.see_below)
parameter_description('importance', cfg.auto_doc.importance.see_below)
add_list()
if raw_args.attention or raw_args.infobox or #notes>0 then
add_title('Notes and alerts', 3)
end
parameter_description('auto', cfg.auto_doc.auto:format(args.AUTO_ASSESS_CAT or cfg.auto.default_cat:format(project)))
parameter_description('attention', cfg.auto_doc.attention:format(args.ATTENTION_CAT or cfg.attention.default_cat:format(project)))
parameter_description('infobox', cfg.auto_doc.infobox:format(args.INFOBOX_CAT or cfg.infobox.default_cat:format(project)))
if raw_args['image-needed'] then
parameter_description('image-needed', 'to request that ' .. (args['image-type'] or cfg.image_needed.default_type) .. ' be [[Wikipedia:Uploading images|added]] to the page.')
parameter_description('image-type', 'overrides the default text (' .. cfg.image_needed.default_type .. '); also used to categorise the request.')
parameter_description('image-details', 'additional text to insert before the words "be [[Wikipedia:Uploading images|added]] to this article" to describe the subject or type of image that is requested.')
parameter_description('image-location', 'specify the location of the requested image. Will be categorised into Category:Wikipedia requested ' .. (args['image-type'] or 'photographs') .. ' in {{{_PARAMETER_}}}')
parameter_description('image-topic', 'specify the topic of the requested image. Will be categorised into Category:Wikipedia requested ' .. (args['image-type'] or 'photographs') .. ' of {{{_PARAMETER_}}}')
--**This parameter populates {{cl|{{{LOCATION_CATEGORY}}}}}.}}{{#if:{{{location<includeonly>|</includeonly>}}}|
--**'''{{{location}}}''' – use {{#if:{{{type<includeonly>|</includeonly>}}}|in conjunction with {{para|{{{type}}}}}}} to {{#if:{{{LOCATION_CATEGORY<includeonly>|</includeonly>}}}|override the above and instead}} categorise the request into {{#if:{{{type<includeonly>|</includeonly>}}}|either <code>Wikipedia requested ''{{{type}}}''s in ''{{{location}}}''</code> or}} <code>Wikipedia requested photographs in ''{{{location}}}''</code>.}}{{#if:{{{TOPIC_CATEGORY<includeonly>|</includeonly>}}}|
--**This parameter populates {{cl|{{{TOPIC_CATEGORY}}}}}.}}{{#if:{{{topic<includeonly>|</includeonly>}}}|
--**'''{{{topic}}}''' – use {{#if:{{{type<includeonly>|</includeonly>}}}|in conjunction with {{para|{{{type}}}}}}} to {{#if:{{{TOPIC_CATEGORY<includeonly>|</includeonly>}}}|override the above and instead}} categorise the request into {{#if:{{{type<includeonly>|</includeonly>}}}|either <code>Wikipedia requested ''{{{type}}}''s of ''{{{topic}}}''</code> or}} <code>Wikipedia requested photographs of ''{{{topic}}}''</code>.}}<noinclude>
end
local note_doc = function(k)
local text = cfg.auto_doc.note.yes_no
if args['NOTE_'..k..'_TEXT'] then
text = text .. cfg.auto_doc.note.text:format(args['NOTE_'..k..'_TEXT'])
end
if args['NOTE_'..k..'_CAT'] then
text = text .. ' ' .. cfg.auto_doc.note.category:format(args['NOTE_'..k..'_CAT'])
end
parameter_description('note '..k, text)
end
for _, k in ipairs(notes) do
note_doc(k)
end
add_list()
if #task_forces>0 then
add_title('Task forces', 3)
end
local tf_doc = function(k)
local tf_imp_name = raw_args['tf ' .. k .. ' importance'] and parameter_name['tf ' .. k .. ' importance']
local prefix = 'TF_' .. k .. '_'
local text = cfg.auto_doc.task_force.yes_no:format(
args[prefix..'LINK'] or '',
args[prefix..'NAME'] or ''
)
if args[prefix..'MAIN_CAT'] then
text = text .. ' ' .. cfg.auto_doc.task_force.category:format(args[prefix..'MAIN_CAT'])
end
if yesno(args[prefix..'QUALITY']) and args[prefix..'ASSESSMENT_CAT'] then
text = text .. ' ' .. cfg.auto_doc.task_force.class:format(
args[prefix..'ASSESSMENT_CAT'],
'class'
)
end
if tf_imp_name and args[prefix..'ASSESSMENT_CAT'] then
text = text .. ' ' .. cfg.auto_doc.task_force.importance:format(
parameter_format(tf_imp_name),
args[prefix..'ASSESSMENT_CAT']
)
end
parameter_description('tf '..k, text)
end
for _, k in ipairs(task_forces) do
tf_doc(k)
end
add_list()
local assessment_cat = args.ASSESSMENT_CAT or project .. ' articles'
if raw_args.class then
add_title(cfg.auto_doc.quality.heading)
local text
if args.QUALITY_CRITERIA=='custom' and assessment_link then
local scale = cfg.quality.project_scale:format(wikilink(assessment_link..'#'..lang:ucfirst(cfg.quality.name), cfg.quality.name))
text = cfg.auto_doc.quality.custom:format(scale)
else
text = cfg.auto_doc.quality.default:format(cfg.quality.default_scale)
end
table.insert(auto_doc, text)
local exists = {}
add_title(cfg.auto_doc.quality.class_parameter, 3)
local add_row = function(class, input, rowspan)
local cat = class..'-Class '..assessment_cat
return mw.html.create('tr')
:tag('th'):wikitext(input or class):done()
:tag('td'):attr('rowspan', rowspan or 1):css('text-align', 'center'):wikitext(class_module.icon{class}):done()
:node(class_module._class{class, category=assessment_cat, image='no', rowspan=rowspan or 1})
:tag('td'):attr('rowspan', rowspan or 1):wikitext(wikilink(':Category:'..cat)):done()
:tag('td'):attr('rowspan', rowspan or 1):css('text-align', 'right'):wikitext(lang:formatNum(mw.site.stats.pagesInCategory(cat))):done()
end
local class_table = mw.html.create('table')
:addClass('wikitable')
:tag('tr')
:tag('th'):wikitext(cfg.auto_doc.quality._table._input):done()
:tag('th'):wikitext(cfg.auto_doc.quality._table.icon):done()
:tag('th'):wikitext(cfg.auto_doc.quality._table.class):done()
:tag('th'):wikitext(cfg.auto_doc.quality._table.category):done()
:tag('th'):wikitext(cfg.auto_doc.quality._table.population):done()
:done()
for _, class in ipairs{'FA', 'A', 'GA'} do
class_table:node(add_row(class))
end
if b_checklist then
class_table:tag('tr')
:tag('th'):wikitext('B'):done()
:tag('td'):attr('rowspan', 2):attr('colspan', 4):wikitext('Depends on status of B-class checklist - [[#B-class checklist|see below]]'):done()
:done():tag('tr')
:tag('th'):wikitext('C'):done():done()
else
class_table:node(add_row('B'))
class_table:node(add_row('C'))
end
for _, class in ipairs{'Start', 'Stub', 'FL', 'List', 'NA'} do
class_table:node(add_row(class))
end
for _, class in ipairs(cfg.auto_doc.quality.extended) do
local cat = mw.title.new('Category:' .. class .. '-Class ' .. assessment_cat)
if cat.exists and #cat:getContent()>1 then
exists[class] = true
class_table:node(add_row(class))
end
end
table.insert(auto_doc, tostring(class_table))
add_title(cfg.auto_doc.quality.redirect, 3)
local redirects = cfg.auto_doc.quality.redirects:format(
exists.Redirect and 'Redirect' or 'NA',
wikilink(':Category:' .. (exists.Redirect and 'Redirect' or 'NA') .. '-Class ' ..assessment_cat)
)
local dabs = cfg.auto_doc.quality.dabs:format(
exists.Disambig and 'Disambig' or 'NA',
wikilink(':Category:' .. (exists.Disambig and 'Disambig' or 'NA') .. '-Class ' ..assessment_cat)
)
table.insert(auto_doc, cfg.auto_doc.quality.not_defined)
local list = mw.html.create('ul')
:tag('li'):wikitext(redirects):done()
:tag('li'):wikitext(dabs):done()
:done()
table.insert(auto_doc, tostring(list))
add_title(cfg.auto_doc.quality.namespace, 3)
table.insert(auto_doc, cfg.auto_doc.quality.deduced)
local first_col = function(text)
return mw.html.create('tr'):tag('th'):wikitext(text):allDone()
end
local namespace_table = mw.html.create('table')
:addClass('wikitable')
:tag('tr')
:tag('th'):wikitext(cfg.auto_doc.quality._table.namespace):done()
:tag('th'):wikitext(cfg.auto_doc.quality._table.icon):done()
:tag('th'):wikitext(cfg.auto_doc.quality._table.class):done()
:tag('th'):wikitext(cfg.auto_doc.quality._table.category):done()
:tag('th'):wikitext(cfg.auto_doc.quality._table.population):done()
:done()
local na_rowspan = 5
+ (exists.File and 0 or 2)
+ (exists.Category and 0 or 1)
+ (exists.Portal and 0 or 1)
+ (exists.Template and 0 or 2)
+ (exists.Project and 0 or 1)
+ (exists.Draft and 0 or 1)
namespace_table:node(add_row('NA', 'User talk', na_rowspan))
:node(not exists.File and first_col('File talk'))
:node(not exists.File and first_col('TimedText talk'))
:node(not exists.Category and first_col('Category talk'))
:node(not exists.Portal and first_col('Portal talk'))
:node(not exists.Template and first_col('Template talk'))
:node(not exists.Template and first_col('Module talk'))
:node(not exists.Project and first_col('Project talk'))
:node(not exists.Draft and first_col('Draft talk'))
:node(first_col('Help talk'))
:node(first_col('MediaWiki talk'))
:node(first_col('Gadget talk'))
:node(first_col('Gadget definition talk'))
:node(exists.File and add_row('File', 'File talk', 2))
:node(exists.File and first_col('TimedText talk'))
:node(exists.Category and add_row('Category', 'Category talk'))
:node(exists.Portal and add_row('Portal', 'Portal talk'))
:node(exists.Template and add_row('Template', 'Template talk', 2))
:node(exists.Template and first_col('Module talk'))
:node(exists.Project and add_row('Project', 'Project talk'))
:node(exists.Draft and add_row('Draft', 'Draft talk'))
table.insert(auto_doc, tostring(namespace_table))
table.insert(auto_doc, cfg.auto_doc.quality.other:format(assessment_cat))
end
if raw_args.importance and args.IMPORTANCE_SCALE~='inline' and args.IMPORTANCE_SCALE~='subpage' then
add_title(cfg.auto_doc.importance.heading)
table.insert(auto_doc, cfg.auto_doc.importance.standard)
local add_row = function(importance)
local cat = importance..'-importance '..assessment_cat
return mw.html.create('tr')
:tag('th'):wikitext(importance):done()
:node(frame:expandTemplate{title='Template:Importance', args={importance, category=assessment_cat}})
:tag('td'):wikitext(wikilink(':Category:'..cat)):done()
:tag('td'):css('text-align', 'right'):wikitext(lang:formatNum(mw.site.stats.pagesInCategory(cat))):done()
end
local imp_table = mw.html.create('table')
:addClass('wikitable')
:tag('tr')
:tag('th'):wikitext(cfg.auto_doc.importance._table.input):done()
:tag('th'):wikitext(cfg.auto_doc.importance._table.importance):done()
:tag('th'):wikitext(cfg.auto_doc.importance._table.category):done()
:tag('th'):wikitext(cfg.auto_doc.importance._table.population):done()
:done()
for _, importance in ipairs(cfg.auto_doc.importance.classes) do
imp_table:node(add_row(importance))
end
table.insert(auto_doc, tostring(imp_table))
end
local doc = ''
if args.DOC=='auto' or args.DOC=='auto+custom' then
local not_documented = {'INHERIT_IMPORTANCE', 'priority', 'IMPN', 'QII_FORMAT', 'image-needed', 'collaboration-candidate', 'collaboration-current', 'collaboration-past', 'a class', 'peer review', 'old peer review'}
local doc_missing = false
for _, p in ipairs(not_documented) do
if raw_args[p] then
doc_missing = p
end
end
if doc_missing then
add_tracking{
category = 'WikiProject banner templates using undocumented features',
sort_key = doc_missing
}
end
doc = require('Module:Documentation').main{content = table.concat(auto_doc)}
end
if args.DOC=='custom' or args.DOC=='auto+custom' then
doc = doc .. require('Module:Documentation').main()
end
return parameter_check .. demo_banner .. info .. (inactive and '' or table.concat(warnings)) .. table.concat(tracking_cats) .. doc
end
return p