require('strict')local p = local sandbox = '/sandbox'local template_page_cfg = local auto_doc_cfg =
p.templatepage = function(args, raw_args, inactive_status)local wikilink = function(link, display) if link then return display and ''..display..'' or ''..link..'' else return display or endend----------------------------- Initialise variables ------------------------------local cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or ))local cfg_tp = template_page_cfg -- convenient shortcut for template_page configuration settingslocal lang = mw.language.getContentLanguagelocal current_page = mw.title.getCurrentTitlelocal on_sandbox = lang:lc(current_page.subpageText)
2 -- in User namespace or current_page.rootText
'no' then assessment_link = nilend----------------------------- Project status ------------------------------------if inactive_status then table.insert(notices, cfg_tp.inactive:format(inactive_status))end----------------------------- Quality criteria ----------------------------------local custom_mask = banner_name:subPageTitle('class')if args.QUALITY_CRITERIA
'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 )) endelseif 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
0 and cfg_tp.more_than.zeroendlocal tf_threshold = tonumber(args.TF_COLLAPSE) or (args.TF_HEADER and cfg.task_force.lower_threshold) or cfg.task_force.upper_thresholdif 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') ))endlocal note_threshold = tonumber(args.COLLAPSED) or 2local hook_collapsedif 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
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
'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',) end return endlocal missing_cats, warnings =, local red_other_cats_in_use = falselocal 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 endendtable.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_forcesendfor _, 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]) endend----------------------------- Template categories -------------------------------local pagetype_module = require('Module:Pagetype')._mainlocal pagetype = function(title) return pagetype_moduleend
if on_sandbox then add_tracking(cfg_tp.template_categories.sandbox, true)elseif inactive_status 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
-- List of categories to check. Should probably have a one consistent style. local category_suffixes =
-- Check each category local found = false for _, suffix in ipairs(category_suffixes) do local category_title = mw.title.new('Category:' .. suffix) if category_title.exists and pagetype(category_title) ~= 'redirect' then table.insert(tracking_cats, wikilink(category_title.fullText, '*')) found = true break end endend----------------------------- Check parameters ----------------------------------local parameters = local append_table = function(source) for _, v in ipairs(source) do table.insert(parameters, v) endendappend_table(cfg_tp.parameters.parameters)for _, k in ipairs(task_forces) do local task_force_parameters = 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)endfor _, k in ipairs(notes) do local note_parameters = 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'])endfor _, 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 endendparameters.preview = cfg_tp.parameters.previewparameters.unknown = on_sandbox and or cfg_tp.parameters.categorylocal parameter_check = current_page.rootPageTitle.text