require('strict')local p = local sandbox = '/sandbox' -- BE SURE TO COMMENT OUT this definition when deploying to livelocal cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or ))local auxiliary = cfg.auxiliary_module .. (sandbox or )local args_module = require('Module:Arguments')local mbox = require('Module:Message box').mainlocal yesno = require('Module:Yesno')local frame = mw.getCurrentFramelocal lang = mw.getLanguage(cfg.language)local current_title = mw.title.getCurrentTitlelocal parameter_format = function(parameter, value) return frame:expandTemplateend
local wikilink = function(link, display) if link then return display and ''..display..'' or ''..link..'' else return display or endend
local display_error = function(text) local span = mw.html.create('div') :addClass('error') :wikitext(text) return tostring(span) end
local image = function(image_name, size, alt, position) return image_name and ''end
local if_exists = function(target, fallback) -- function to add wikilink if target exists local title = mw.title.new(target) if title and title.exists then return wikilink(target) else return fallback or target endend
local isarticle = function(class) local article = true for _,v in ipairs(cfg.quality.non_article_classes) do if class
local importance_mask = function(raw_importance, scale, banner_name, pagetype, class)----------------------------- Importance mask -----------------------------------local importanceif scale
'subpage' then local custom_mask = banner_name:subPageTitle('importance') if custom_mask.exists and #custom_mask:getContent>1 then -- pass to custom importance mask importance = mw.text.trim(frame:expandTemplate) endelseif raw_importance then-- standard importance scale importance = cfg.importance.na if pagetype
'set index article' 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
'set index article' then -- unspecified or invalid importance, use "Unknown" for articles importance = cfg.importance.unknown end endendreturn importanceend
----------------------------- Quality class mask --------------------------------p.readarticleclass = function(options, page) -- used by _main and also Module:Banner shell page = page or current_title.prefixedText local get_parameter_value = require('Module:Template parameter value').getParameter local success, result = get_parameter_value(page, cfg.banner_shell.redirects, 'class', options) return success and result -- returns FALSE if banner shell template does not exist on page -- returns BLANK if class parameter is not defined or is defined blank -- otherwise returns class parameterendp.class_mask = function(class, title, FQS, pagetype) local resolveFQSgrade = function(class) return FQS and lang:ucfirst(class) or 'NA' end local out title = title or mw.title.getCurrentTitle local ns = title.namespace class = class:match('^%s*(.-)%s*$'):lower if pagetype
'soft redirect' then out = resolveFQSgrade('redirect') elseif pagetype
'set index article' then out = 'List' elseif pagetype
'start' or class
'b' or class
'fa' or class
'a' or class
'list' or class
'si' or class
7 or ns
'fm' then out = 'FM' else out = resolveFQSgrade('file') end else local grade = cfg.quality.ns_to_class[ns] or 'NA' out = resolveFQSgrade(grade) end return outend
local page_assessment = function(project, class, importance) -- add PageAssessments parser function local assessment = table.concat('|') frame:preprocess('')end
local bubble = function(text, conflict, style) local out = mw.html.create('span') :addClass('wpb-header-bubbles') :addClass(style) :addClass(conflict and 'conflict' or nil) :wikitext(text) return tostring(out)end
p._main = function(args, raw_args, demo_page, banner_name, inactive)----------------------------- Initialise parameters -----------------------------local project = args.PROJECT or 'PROJECT'local project_name = args.PROJECT_NAME or 'WikiProject ' .. projectlocal project_link = mw.title.new(args.PROJECT_LINK or 'Wikipedia:' .. project_name)local pagetype = demo_page
'set index article' and 'article' or pagetype -- display "article" instead of "set index article" return text and text:gsub('_PAGETYPE_', ptype)endfor arg_name, arg_value in pairs(args) do local tf_match = mw.ustring.match(arg_name,'^tf (%d+)$') local note_match = mw.ustring.match(arg_name,'^note (%d+)$') if tf_match and yesno(arg_value, true) then table.insert(task_forces, tf_match) elseif note_match and yesno(arg_value, true) then table.insert(notes, note_match) else local tf, cat = mw.ustring.match(arg_name,'^tf (%d+) cat (%d+)$') if tf and yesno(arg_value, true) then if not taskforce_categories[tf] then -- initialise table taskforce_categories[tf] = end table.insert(taskforce_categories[tf], cat) end endendtable.sort(task_forces, function (x, y) return tonumber(x) < tonumber(y) end)table.sort(notes, function (x, y) return tonumber(x) < tonumber(y) end)----------------------------- Location warning ----------------------------------local warning = local show_namespace_warning = not (current_title.isTalkPage or demo_page)if show_namespace_warning then local text = cfg.namespace_warning.text:format(current_title.talkPageTitle.fullText, parameter_format('category', 'no') ) local sortkey = current_title.namespace
10 then -- on the Template namespace text = text .. ' ' .. cfg.namespace_warning.on_template_page:format(parameter_format('BANNER_NAME'), current_title.prefixedText ) end warning = mbox('ombox',) if not current_title.subjectPageTitle:inNamespace(2) then add_category(cfg.namespace_warning.categories, sortkey) endend----------------------------- Substitution warning ------------------------------if args.substcheck