Module:Class mask/sandbox: Difference between revisions

Content deleted Content added
simp?
rewrite logic
Line 27:
end
 
local resolveExtraGradegetGrade = function(gradeargs, argstitle)
iflocal args[grade] =='yes' thenargs[1]
return ucfirst(grade)
else
return 'NA'
end
end
 
local resolveDefaultGrade = function(args, title, talkDefault)
local ns = title.namespace
if title.subjectPageTitle.isRedirect then
Line 43 ⟶ 36:
return resolveFQSgrade('disambig',args)
else
grade = grade and grade:match('^%s*(.-)%s*$'):lower()
return talkDefault
if grade=='start' or grade=='stub' then -- Ucfirst
if args[grade]~='no' then
return ucfirst(grade)
end
elseif grade=='b' or grade=='c' then
local mask = mw.loadData('Module:WikiProject banner/config').b_checklist.mask
local isExtended = args.b1 or args.b2 or args.b3 or args.b4 or args.b5 or args.b6
if isExtended then
local some_fail, all_pass = false, true
for i = 1, 6 do
local b_param = args['b'..i] and mask[string.lower(args['b'..i])]
if b_param and b_param~='y' and b_param~='x' then -- criterion in use and is not passed or marked not applicable
all_pass = false
if b_param=='n' then
some_fail = true
end
end
end
return all_pass and 'B' -- return B if all criteria are marked passed
or some_fail and 'C' -- or return C if any of the criteria are marked failed
or grade:upper() -- otherwise defer to entered grade
elseif args[grade]~='no' then
return grade:upper()
end
elseif grade=='fa' or grade=='fl' or grade=='a' or grade=='ga' then -- Upper-case
if args[grade]~='no' then
return grade:upper()
end
elseif args[grade:upper()] then -- Upper-case syntax
return args[grade:upper()]
elseif args[grade:lower()]=='yes' then -- Lower-case syntax
return mw.language.getContentLanguage():ucfirst(grade:lower())
elseif grade=='list' or grade=='sia' or grade=='si' or grade=='sl' then-- List
if args['list']~='no' then
return 'List'
end
end
end
elseif ns==7 or ns==711 then -- File talk
if grade=='fm' and (args.fm or args.FQS)=='yes' then
return resolveFQSgrade('file', args)
return 'FM'
else
return resolveFQSgrade('file', args)
end
elseif ns==15 then -- Category talk
return resolveFQSgrade('category', args)
Line 57 ⟶ 91:
elseif ns==119 then -- Draft talk
return resolveFQSgrade('draft', args)
elseif ns==13 and args['help']=='yes' then -- Help talk
return resolveExtraGrade('helpHelp', args)
elseif ns==3 and args['user']=='yes' then -- User talk
return resolveExtraGrade('userUser', args)
else
return 'NA'
end
end
 
local getGrade = function(args, title)
local grade = args[1]
grade = grade and grade:match('^%s*(.-)%s*$'):lower()
if not grade or grade=='¬' then -- undefined
return '¬'
elseif grade=='start' or grade=='stub' then -- Ucfirst
if args[grade]~='no' then
return ucfirst(grade)
end
elseif grade=='b' or grade=='c' then
local mask = mw.loadData('Module:WikiProject banner/config').b_checklist.mask
local isExtended = args.b1 or args.b2 or args.b3 or args.b4 or args.b5 or args.b6
if isExtended then
local some_fail, all_pass = false, true
for i = 1, 6 do
local b_param = args['b'..i] and mask[string.lower(args['b'..i])]
if b_param and b_param~='y' and b_param~='x' then -- criterion in use and is not passed or marked not applicable
all_pass = false
if b_param=='n' then
some_fail = true
end
end
end
return all_pass and 'B' -- return B if all criteria are marked passed
or some_fail and 'C' -- or return C if any of the criteria are marked failed
or grade:upper() -- otherwise defer to entered grade
elseif args[grade]~='no' then
return grade:upper()
end
elseif grade=='fa' or grade=='fl' or grade=='a' or grade=='ga' then -- Upper-case
if args[grade]~='no' then
return grade:upper()
end
elseif grade=='na' then
if args.forceNA=='yes' then
return resolveDefaultGrade(args, title, 'NA')
else
return 'NA'
end
elseif grade=='file' or grade=='image' or grade=='img' then
return resolveFQSgrade('file', args)
elseif grade=='category' or grade=='cat' or grade=='categ' then
return resolveFQSgrade('category', args)
elseif grade=='dab' or grade=='disambig' or grade=='disambiguation' or grade=='disamb' then
return resolveFQSgrade('disambig', args)
elseif grade=='redirect' or grade=='red' or grade=='redir' then
return resolveFQSgrade('redirect', args)
elseif grade=='portal' or grade=='project' or grade=='draft' then
return resolveFQSgrade(grade, args)
elseif grade=='template' or grade=='temp' or grade=='tpl' or grade=='templ' then
return resolveFQSgrade('template', args)
elseif grade=='help' or grade=='user' then
return resolveExtraGrade(grade, args)
elseif grade=='fm' then
if (args.fm or args.FQS)=='yes' then
return 'FM'
else
return resolveFQSgrade('file', args)
end
elseif args[grade:upper()] then -- Upper-case syntax
return args[grade:upper()]
elseif args[grade:lower()]=='yes' then -- Lower-case syntax
return mw.language.getContentLanguage():ucfirst(grade:lower())
elseif grade=='list' or grade=='sia' or grade=='si' or grade=='sl' then-- List
if args['list']~='no' then
return 'List'
end
else -- Defaults
return resolveDefaultGrade(args, title)
end
end
Line 140 ⟶ 102:
p._main = function(args, title)
title = title or mw.title.getCurrentTitle()
local out, warning = '', ''
if title.namespace == 10 and title.subpageText == 'class' then
outwarning = mw.getCurrentFrame():expandTemplate{title = 'Class mask/doc warning'}
end
if not args[1] or args[1]=='¬' then -- undefined
out = '¬'
else
out = (getGrade(args, title) or '')
end
return warning .. out
out = out .. (getGrade(args, title) or '')
return out
end