Module:Class mask: Difference between revisions

Content deleted Content added
fix a logical error in quality function for NA-classes, improve some code efficiency
m Changed protection settings for "Module:Class mask": most less used now (although number of transclusions has not caught up) ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))
 
(11 intermediate revisions by the same user not shown)
Line 17:
-- Should not be used with non-ascii strings.
return s:sub(1, 1):upper() .. s:sub(2, -1)
end
 
local isTruthyBParam = function(s)
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 resolveFQSgrade = function(grade, args)
if (args[grade] or args.FQS) == 'yes' then
return ucfirst(grade)
else
Line 32 ⟶ 27:
end
 
local resolveExtraGradep._main = function(gradeargs, argstitle)
title = title or mw.title.getCurrentTitle()
if args[grade] == 'yes' then
local out = ''
return ucfirst(grade)
local grade = args[1]
if not grade or grade=='¬' then -- undefined
out = '¬'
else
local ns = title.namespace
return 'NA'
grade = grade:match('^%s*(.-)%s*$'):lower()
end
if title.subjectPageTitle.isRedirect then
end
out = resolveFQSgrade('redirect',args)
 
elseif ns==1 then -- Talk
local resolveDefaultGrade = function(args, title, talkDefault)
if require('Module:Disambiguation').isDisambiguation(title.subjectPageTitle.isRedirect:getContent()) then
return out resolveExtraGrade= resolveFQSgrade('redirectdisambig',args)
else
end
if grade=='start' or grade=='stub' then -- Ucfirst
local ns = title.namespace
if nsargs[grade]~==1'no' then -- Talk
out = ucfirst(grade)
if require('Module:Disambiguation').isDisambiguation(title.subjectPageTitle:getContent()) then
end
return resolveFQSgrade('disambig',args)
elseif grade=='b' or grade=='c' or grade=='fa' or grade=='fl' or grade=='a' or grade=='ga' then -- Upper-case
else
if args[grade]~='no' then
return talkDefault
out = grade:upper()
end
end
elseif ns==7 or ns==711 then -- File talk
elseif args[grade:upper()] then -- Upper-case syntax
return resolveFQSgrade('file', args)
out = args[grade:upper()]
elseif ns==15 then -- Category talk
elseif args[grade:lower()]=='yes' then -- Lower-case syntax
return resolveFQSgrade('category', args)
out = mw.language.getContentLanguage():ucfirst(grade:lower())
elseif ns==101 then -- Portal talk
elseif grade=='list' or grade=='sia' or grade=='si' or grade=='sl' then-- List
return resolveFQSgrade('portal', args)
if args['list']~='no' then
elseif ns==11 or ns==829 then -- Template talk
out = 'List'
return resolveFQSgrade('template', args)
end
elseif ns==5 then -- Wikipedia talk
elseif grade=='dab' or grade=='disambig' or grade=='disambiguation' or grade=='disamb' then
return resolveFQSgrade('project', args)
out = resolveFQSgrade('disambig', args)
elseif ns==119 then -- Draft talk
return resolveFQSgrade('draft', args)
elseif ns==13 then -- Help talk
return resolveExtraGrade('help', args)
else
return 'NA'
end
end
 
local getGrade = function(args, title)
local grade = args[1]
grade = grade and grade:match('^%s*(.-)%s*$'):lower()
local ret
 
if not grade or grade == '¬' then -- undefined
ret = '¬'
 
-- Ucfirst
elseif grade == 'start' or grade == 'stub' or grade == 'list' then
if args[grade] ~= 'no' then
ret = ucfirst(grade)
end
 
-- B
elseif grade == 'b' then
local bParams = {'b1', 'b2', 'b3', 'b4', 'b5', 'b6'}
local isExtended = false
for _, param in ipairs(bParams) do
if args[param] then
isExtended = true
break
end
end
if isExtended then
local isB = true
for _, param in ipairs(bParams) do
if not isTruthyBParam(args[param]) then
isB = false
break
end
end
retelseif ns==7 isBor andns==711 'B'then or-- File 'C'talk
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 grade ns==11 'na'or ns==829 then -- Template talk
out = resolveFQSgrade('template', args)
if args.forceNA == 'yes' then
elseif ns==5 then -- Wikipedia talk
ret = resolveDefaultGrade(args, title, 'NA')
out = resolveFQSgrade('project', args)
elseif ns==119 then -- Draft talk
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
elseif grade == 'file' or grade == 'image' or grade == 'img' then
ret = resolveFQSgrade('file', args)
elseif grade == 'category' or grade == 'cat' or grade == 'categ' then
ret = resolveFQSgrade('category', args)
elseif grade == 'dab' or grade == 'disambig' or grade == 'disambiguation' or grade == 'disamb' then
ret = resolveFQSgrade('disambig', args)
elseif grade == 'redirect' or grade == 'red' or grade == 'redir' then
ret = resolveExtraGrade('redirect', args)
elseif grade == 'help' then
ret = resolveExtraGrade('help', args)
elseif grade == 'portal' or grade == 'project' or grade == 'draft' then
ret = resolveFQSgrade(grade, args)
elseif grade == 'template' or grade == 'temp' or grade == 'tpl' or grade == 'templ' then
ret = resolveFQSgrade('template', args)
elseif grade == 'fm' then
if args.fm == 'yes' then
ret = 'FM'
else
ret = resolveFQSgrade('file', args)
end
 
else
-- Upper-case syntax
ret = args[grade:upper()]
 
-- Lower-case syntax
if not ret then
if args[grade:lower()] == 'yes' then
ret = mw.language.getContentLanguage():ucfirst(grade:lower())
end
end
 
-- Defaults
if not ret then
ret = resolveDefaultGrade(args, title)
end
end
return ret
end
 
p._main = function(args, title)
title = title or mw.title.getCurrentTitle()
local out = ''
if title.namespace == 10 and title.subpageText == 'class' then
out = mw.getCurrentFrame():expandTemplate{title = 'Class mask/doc warning'}
end
out = out .. (getGrade(args, title) or '')
return out
end
Line 170 ⟶ 91:
p.main = function(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {
removeBlanks = false,
wrappers = 'Template:Class mask'
})
return p._main(args)
end
Line 191 ⟶ 115:
end
 
p.readarticleclass = function(pageoptions, optionspage) -- used by p._quality and Module:Banner shell
page = page or mw.title.getCurrentTitle().prefixedText
local get_parameter_value = require("Module:Template parameter value").getValue
local WPBSredirects = {'WikiProject banner shell','WikiProject banner shell/sandbox','Bannershell','Multiple wikiprojects','Project shell','Scope shell','WPB','WPBS','WPBannerShell','WP Banner Shell','WP banner shell','WikiProjectBannerShell','WikiProjectBanner Shell','WikiProjectBanners','WikiProject BannerShell','WikiProject Banner Shell','WikiProject Banners','WikiProject Banners Shell','WikiProject Shell','WikiProject banner','WikiProject banner shell/redirect','WikiProject shell','WikiprojectBannerShell','Wikiproject banner holder','Wikiproject banner shell','Wikiprojectbanners','Wikiprojectbannershell','Wpb','Wpbannershell','Wpbsgclass'}
Line 208 ⟶ 133:
class = '¬'
elseif args.QUALITY_CRITERIA ~= 'custom' then -- project uses standard scale and will inherit article class if needed
local article_class = p.readarticleclass(title.prefixedText,{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(title.prefixedText,{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