Module:Class mask/sandbox: Difference between revisions

Content deleted Content added
add bclassparams
fix?
 
(179 intermediate revisions by 6 users not shown)
Line 1:
local p = {}
 
local bclassparams = {
local cfg = mw.loadData('Module:WikiProject banner/config')
pass = {inputs = {'yes', 'y', '1', 'pass'}, output = 'y'},
 
fail = {inputs = {'no', 'n', '0', 'fail'}, output = 'n'},
local isarticle = function(class)
na = {inputs = {'na', 'n/a'}, output = 'x'},
local article = true
unused = {inputs = {'unused', '¬'}, output = '¬'},
for _, v in ipairs(cfg.quality.non_article_classes) do
unevaluated = {inputs = {'<yes/no>', 'yes/no', '?', ''}, output = ''},
if class == v then -- class matches one of the non-article classes
default = {inputs = {'!'}, output = '!'}
article = false
}
break
local function getDocWarning(title)
end
if title.namespace == 10 and title.subpageText == 'class' then
return mw.getCurrentFrame():expandTemplate{
title = 'Class mask/doc warning'
}
end
return article
end
 
local functionucfirst trim= function(s)
return s:match('^%s*(.-)%s*$')
end
 
local function ucfirst(s)
-- Returns the given string with the first character in upper case.
-- Should not be used with non-ascii strings.
Line 26 ⟶ 20:
end
 
local resolveFQSgrade = function(grade, args)
local function isTruthyBParam(s)
if (args[grade] or args.FQS) == 'yes' then
s = s and s:lower()
return not s or s == 'yes' or s == 'y' or s == '1' or s == 'pass' or s == 'na' or s == 'n/a' or s == '¬' or s == 'unused'
end
 
local bclass = function(param)
end
 
local function resolveFQSgrade(grade, args)
if (args[grade] == 'yes') or (args.FQS == 'yes') then
return ucfirst(grade)
else
Line 42 ⟶ 28:
end
 
p._main = function(args, title)
local function resolveExtraGrade(grade, args)
title = title or mw.title.getCurrentTitle()
if args[grade] == 'yes' then
local out = ''
return ucfirst(grade)
else
return 'NA'
end
end
 
local function resolveDefaultGrade(args, title, talkDefault)
if args.ignorenamespace then
return nil
end
if title.isRedirect then
return resolveExtraGrade('redirect',args)
end
local ns = title.namespace
if ns==0 then -- Talk
return talkDefault
elseif ns==6 or ns==710 then -- File talk
return resolveFQSgrade('file', args)
elseif ns==14 then -- Category talk
return resolveFQSgrade('category', args)
elseif ns==100 then -- Portal talk
return resolveFQSgrade('portal', args)
elseif ns==10 or ns==828 then -- Template talk
return resolveFQSgrade('template', args)
elseif ns==4 then -- Wikipedia talk
return resolveFQSgrade('project', args)
elseif ns==118 then -- Draft talk
return resolveFQSgrade('draft', args)
else
return 'NA'
end
end
 
local function getGrade(args, title)
local grade = args[1]
-- We use string.lower here as it's faster than mw.ustring.lower and none
-- of the standard grades have non-Ascii characters.
grade = grade and trim(grade):lower()
 
local ret
 
if not grade or grade == '¬' then -- undefined
retout = '¬'
else
elseif grade == '' then -- blank
local ns = title.namespace
 
grade = grade:match('^%s*(.-)%s*$'):lower()
-- Ucfirst
if title.subjectPageTitle.isRedirect then
-- We put these near the start as they are probably the most common grades
out = resolveFQSgrade('redirect', args)
-- on the site. The other grades are also roughly in order of prevalence.
elseif ns == 1 then -- Talk
elseif grade == 'start' or grade == 'stub' or grade == 'list' then
if require('Module:Disambiguation').isDisambiguation(title.subjectPageTitle:getContent()) then
if args[grade] ~= 'no' then
out = resolveFQSgrade('disambig', args)
ret = ucfirst(grade)
end else
if grade == 'start' or grade == 'stub' then -- Ucfirst
 
if args[grade] ~= 'no' then
-- B
out = ucfirst(grade)
elseif grade == 'b' then
end
local bParams = {'b1', 'b2', 'b3', 'b4', 'b5', 'b6'}
elseif grade == 'b' or grade == 'c' or grade == 'fa' or grade == 'fl' or grade == 'a' or grade == 'ga' then -- Upper-case
local isExtended = false
if args[grade] ~= 'no' then
for _, param in ipairs(bParams) do
out = grade:upper()
if args[param] then
end
isExtended = true
elseif args[grade:upper()] then -- Upper-case syntax
break
out = args[grade:upper()]
end
elseif args[grade:lower()] == 'yes' then -- Lower-case syntax
end
out = mw.language.getContentLanguage():ucfirst(grade:lower())
if isExtended then
elseif grade == 'list' or grade == 'sia' or grade == 'si' or grade == 'sl' then -- List
local isB = true
if args['list'] ~= 'no' then
for _, param in ipairs(bParams) do
out = 'List'
if not isTruthyBParam(args[param]) then
isB = falseend
elseif grade == 'dab' or grade == 'disambig' or grade == 'disambiguation' or grade == 'disamb' then
break
out = resolveFQSgrade('disambig', args)
end
end
elseif ns == 7 or ns == 711 then -- File talk
ret = isB and 'B' or 'C'
elseif if grade == 'fm' and (args.bfm ~or args.FQS) == 'noyes' then
ret out = 'BFM'
end else
out = resolveFQSgrade('file', args)
 
end
-- Upper-case
elseif ns == 15 then -- Category talk
elseif grade == 'fa' or grade == 'fl' or grade == 'a' or grade == 'ga' or grade == 'c' then
out = resolveFQSgrade('category', args)
if args[grade] ~= 'no' then
elseif ns == 101 then -- Portal talk
ret = grade:upper()
out = resolveFQSgrade('portal', args)
end
elseif ns == 11 or ns == 829 then -- Template talk
 
out = resolveFQSgrade('template', args)
-- NA
elseif gradens == 'na'5 then -- Wikipedia talk
out = resolveFQSgrade('project', args)
if args.forceNA == 'yes' then
elseif ns == 119 then -- Draft talk
ret = resolveDefaultGrade(args, title, 'NA')
out = resolveFQSgrade('draft', args)
elseif ns == 13 and args['help'] == 'yes' then -- Help talk
out = 'Help'
elseif ns == 3 and args['user'] == 'yes' then -- User talk
out = 'User'
else
retout = 'NA'
end
end
return out
end
 
p.main = function(frame)
-- File
local getArgs = require('Module:Arguments').getArgs
elseif grade == 'file' or grade == 'image' or grade == 'img' then
local args = getArgs(frame, {
ret = resolveFQSgrade('file', args)
removeBlanks = false,
wrappers = 'Template:Class mask'
})
return p._main(args)
end
 
local getclass = function(args, title)
-- Category
local class = '¬'
elseif grade == 'category' or grade == 'cat' or grade == 'categ' then
if args.QUALITY_SCALE == 'inline' then
ret = resolveFQSgrade('category', args)
class = args.class
 
elseif args.QUALITY_SCALE == 'subpage' then
-- Disambguation
local classTemplate = args.BANNER_NAME .. '/class'
elseif grade == 'dab' or grade == 'disambig' or grade == 'disambiguation' or grade == 'disamb' then
if mw.title.new(classTemplate).exists then
ret = resolveFQSgrade('disambig', args)
local frame = mw.getCurrentFrame()
 
class = frame:expandTemplate{title = classTemplate, args = args}
-- Redirect
elseif grade == 'redirect' or grade == 'red' or grade == 'redir' then
ret = resolveExtraGrade('redirect', args)
 
-- Portal, Project and Draft
elseif grade == 'portal' or grade == 'project' or grade == 'draft' then
ret = resolveFQSgrade(grade, args)
 
-- Template
elseif grade == 'template' or grade == 'temp' or grade == 'tpl' or grade == 'templ' then
ret = resolveFQSgrade('template', args)
 
-- FM
elseif grade == 'fm' then
if args.fm == 'yes' then
ret = 'FM'
else
ret = resolveFQSgrade('file', args)
end
 
else
args.FQS = (args.QUALITY_SCALE == 'extended') and 'yes' or 'no'
-- Upper-case syntax
retargs[1] = args[grade:upper()].class
class = p._main(args, title)
end
return class
end
 
p.readarticleclass = function(options, page) -- used by p._quality and Module:Banner shell
-- Lower-case syntax
page = page or mw.title.getCurrentTitle().prefixedText
if not ret then
local get_parameter_value = require("Module:Template parameter value").getValue
if args[grade:lower()] == 'yes' then
local success, result = get_parameter_value(page, cfg.WPBS_redirects, "class", options)
ret = mw.language.getContentLanguage():ucfirst(grade:lower())
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 parameter
end
 
p._quality = function(args)
local title = args.page and mw.title.new(args.page) or mw.title.getCurrentTitle()
local local_class = getclass(args, title)
local prefix, class = 'Y', local_class
if local_class=='¬' then
class = '¬'
elseif args.QUALITY_CRITERIA ~= 'custom' then -- project uses standard scale and will inherit article class if needed
local article_class = p.readarticleclass({ignore_subtemplates=true},title.prefixedText)
article_class = article_class and p._main({article_class}, title)
if article_class then -- banner shell exists
if article_class == '' then -- no article class defined
if local_class == '' then -- local class also does not exist, check whether any other class parameters are defined inside the shell
local classparam = p.readarticleclass({ignore_blank=true, only_subtemplates=true},title.prefixedText)
if classparam == '' then -- no class parameters defined, display as globally unassessed
prefix = 'H' -- hide quality class in project banner
end
end
elseif local_class == '' or local_class == article_class then -- local class matches article class or is blank
prefix = 'H' -- hide quality class in project banner
class = article_class
elseif (article_class == 'NA') and not isarticle(local_class) then -- article class and local class are both non-article classes
prefix = 'H'
else -- article class exists and differs from local class
prefix = 'X' -- X will indicate to meta banner that classes are different, so trigger a tracking category
end
end
end
return (args.noprefix and '' or prefix) .. class
 
-- Defaults
if not ret then
ret = resolveDefaultGrade(args, title)
end
 
return ret
end
 
p.quality = function(frame) -- used by WPBM to check global quality and compare with local parameter
function p._main(args, title)
return p._quality(frame.args)
title = title or mw.title.getCurrentTitle().subjectPageTitle
local docWarning = getDocWarning(title) or ''
local grade = getGrade(args, title) or ''
return docWarning .. grade
end
 
function p.main(frame)
local args = frame.args or frame:getParent().args
return p._main(args)
end