Module:Class mask/sandbox: Difference between revisions

Content deleted Content added
split
fix?
 
(101 intermediate revisions by 5 users not shown)
Line 1:
local p = {}
 
local cfg = mw.loadData('Module:WikiProject banner/config')
local readarticleclass = function() -- look for article_class in page content
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'}
local target = mw.title.getCurrentTitle().prefixedText
local success, result = get_parameter_value(target, WPBSredirects, "class", {ignoreSubtemplates=true})
return success and result
end
 
local isarticle = function(class)
local nonarticleclasses = {'Template', 'File', 'Category', 'Disambig', 'Redirect', 'Portal', 'Project', 'Draft', 'Book', 'FM'} -- these classes will not be identified as conflicting with NA-class
local article = true
for _, v in ipairs(nonarticleclassescfg.quality.non_article_classes) do
if class == v then -- class matches one of the non-article classes
article = false
break
Line 25 ⟶ 18:
-- 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
 
Line 40 ⟶ 28:
end
 
local resolveExtraGradep._main = function(gradeargs, argstitle)
title = title or mw.title.getCurrentTitle()
if args[grade] == 'yes' then
local out = ''
return ucfirst(grade)
else
return 'NA'
end
end
 
local resolveDefaultGrade = function(args, title, talkDefault)
if args.ignorenamespace then
return nil
end
if title.subjectPageTitle.isRedirect then
return resolveExtraGrade('redirect',args)
end
local ns = title.namespace
if ns==1 then -- Talk
if require('Module:Disambiguation').isDisambiguation(title.subjectPageTitle:getContent()) then
return resolveFQSgrade('disambig',args)
else
return talkDefault
end
elseif ns==7 or ns==711 then -- File talk
return resolveFQSgrade('file', args)
elseif ns==15 then -- Category talk
return resolveFQSgrade('category', args)
elseif ns==101 then -- Portal talk
return resolveFQSgrade('portal', args)
elseif ns==11 or ns==829 then -- Template talk
return resolveFQSgrade('template', args)
elseif ns==5 then -- Wikipedia talk
return resolveFQSgrade('project', 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
retout = '¬'
else
 
local ns = title.namespace
-- Ucfirst
grade = grade:match('^%s*(.-)%s*$'):lower()
elseif grade == 'start' or grade == 'stub' or grade == 'list' then
if args[grade] ~= 'no'title.subjectPageTitle.isRedirect then
out = resolveFQSgrade('redirect', args)
ret = ucfirst(grade)
elseif ns == 1 then -- Talk
end
if require('Module:Disambiguation').isDisambiguation(title.subjectPageTitle:getContent()) then
 
out = resolveFQSgrade('disambig', args)
-- B
else
elseif grade == 'b' then
local if bParamsgrade == {'b1start', 'b2',or 'b3',grade 'b4',== 'b5stub', 'b6'}then -- Ucfirst
if args[grade] ~= 'no' then
local isExtended = false
out = ucfirst(grade)
for _, param in ipairs(bParams) do
end
if args[param] then
elseif grade == 'b' or grade == 'c' or grade == 'fa' or grade == 'fl' or grade == 'a' or grade == 'ga' then -- Upper-case
isExtended = true
if args[grade] ~= 'no' then
break
out = grade:upper()
end
end
elseif args[grade:upper()] then -- Upper-case syntax
if isExtended then
out = args[grade:upper()]
local isB = true
elseif args[grade:lower()] == 'yes' then -- Lower-case syntax
for _, param in ipairs(bParams) do
out = mw.language.getContentLanguage():ucfirst(grade:lower())
if not isTruthyBParam(args[param]) then
elseif grade == 'list' or grade == 'sia' or grade == 'si' or grade == 'sl' then -- List
isB = false
if args['list'] ~= 'no' then
break
out = 'List'
end
elseif grade == 'dab' or grade == 'disambig' or grade == 'disambiguation' or grade == 'disamb' then
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 gradens == 'na'11 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 181 ⟶ 92:
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
 
local getclass = function(args, title)
local class = '¬'
if args.QUALITY_SCALE == 'inline' then
class = args.class
elseif args.QUALITY_SCALE == 'subpage' then
iflocal classTemplate = mw.title.new(args.BANNER_NAME .. '/class').exists then
if mw.title.new(classTemplate).exists then
local frame = mw.getCurrentFrame()
class = frame:expandTemplate{title = args.BANNER_NAME..'/class'classTemplate, args = args}
end
else
args.FQS = (args.QUALITY_SCALE == 'extended') and 'yes' or 'no'
args[1] = args.class
class = p._main(args, title)
end
return class
end
 
p.qualityreadarticleclass = function(frameoptions, page) -- used by WPBM to check global qualityp._quality and compare with localModule:Banner parametershell
page = page or mw.title.getCurrentTitle().prefixedText
local local_class = getclass(frame.args)
local get_parameter_value = require("Module:Template parameter value").getValue
local success, result = get_parameter_value(page, cfg.WPBS_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 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 frame.args.QUALITY_CRITERIA ~= 'custom' then -- project uses standard scale and will inherit article class if needed
local article_class = framep.args.article_class or readarticleclass({ignore_subtemplates=true},title.prefixedText) -- checks parameter for testing purposes
article_class = article_class and p._main({article_class}, ignorenamespace=frame.args.ignorenamespace} or '¬' -- normalise if not falsetitle)
if (article_class == '¬') or (article_class == '') then -- article class does not exist, display quality class in project banner asshell normalexists
elseif if local_classarticle_class == '' then -- localno isarticle notclass specifieddefined
if local_class == '' then -- local class also does not exist, check whether any other class parameters are defined inside the shell
-- Need to pass bclasschecklist params through mask with article_class
local classparam = p.readarticleclass({ignore_blank=true, only_subtemplates=true},title.prefixedText)
prefix = 'H' -- hide quality class in project banner
if classparam == '' then -- no class parameters defined, display as globally unassessed
class = article_class
prefix = 'H' -- hide quality class in project banner
elseif local_class == article_class then -- article class and local class are the same
end
prefix = 'H' -- hide quality class in project banner
end
class = article_class
elseif (article_classlocal_class == 'NA') andor not isarticle(local_class) == article_class then -- articlelocal class andmatches localarticle class areor both non-articleis classesblank
prefix = 'H' -- hide quality class in project banner
class = article_class
else -- article class exists and differs from local class
elseif (article_class == 'NA') and not isarticle(local_class) then -- article class and local class are both non-article classes
prefix = 'X' -- X will indicate to meta banner that classes are different, so trigger a tracking category
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 (frame.args.noprefix and '' or prefix) .. class
end
 
p.quality = function(frame) -- used by WPBM to check global quality and compare with local parameter
return p._quality(frame.args)
end