Module:Class mask/sandbox: Difference between revisions

Content deleted Content added
No edit summary
Tags: Reverted Mobile edit Mobile web edit Advanced mobile edit
fix?
 
(124 intermediate revisions by 6 users not shown)
Line 1:
local p = {}
 
local cfg = mw.loadData('Module:WikiProject banner/config')
local function ucfirst(s)
 
local isarticle = function(class)
local article = true
for _, v in ipairs(cfg.quality.non_article_classes) do
if class == v then -- class matches one of the non-article classes
article = false
break
end
end
return article
end
 
local ucfirst = function(s)
-- Returns the given string with the first character in upper case.
-- Should not be used with non-ascii strings.
Line 7 ⟶ 20:
end
 
local resolveFQSgrade = function(grade, args)
local function isTruthyBParam(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 function resolveFQSgrade(grade, args)
if (args[grade] or args.FQS) == 'yes' then
return ucfirst(grade)
Line 20 ⟶ 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)
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()
if title.subjectPageTitle.isRedirect then
out = resolveFQSgrade('redirect', args)
elseif ns == 1 then -- Talk
if require('Module:Disambiguation').isDisambiguation(title.subjectPageTitle:getContent()) then
out = resolveFQSgrade('disambig', args)
else
if grade == 'start' or grade == 'stub' then -- Ucfirst
if args[grade] ~= 'no' then
out = ucfirst(grade)
end
elseif grade == 'b' or grade == 'c' or grade == 'fa' or grade == 'fl' or grade == 'a' or grade == 'ga' then -- Upper-case
if args[grade] ~= 'no' then
out = grade:upper()
end
elseif args[grade:upper()] then -- Upper-case syntax
out = args[grade:upper()]
elseif args[grade:lower()] == 'yes' then -- Lower-case syntax
out = 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
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
if grade == 'fm' and (args.fm or args.FQS) == 'yes' then
out = 'FM'
else
out = resolveFQSgrade('file', args)
end
elseif ns == 15 then -- Category talk
out = resolveFQSgrade('category', args)
elseif ns == 101 then -- Portal talk
out = resolveFQSgrade('portal', args)
elseif ns == 11 or ns == 829 then -- Template talk
out = resolveFQSgrade('template', args)
elseif ns == 5 then -- Wikipedia talk
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
out = 'NA'
end
end
return out
end
 
p.main = function(frame)
local function resolveDefaultGrade(args, title, talkDefault)
local getArgs = require('Module:Arguments').getArgs
if args.ignorenamespace then
local args = getArgs(frame, {
return nil
removeBlanks = false,
end
wrappers = 'Template:Class mask'
if title.subjectPageTitle.isRedirect then
})
return resolveExtraGrade('redirect',args)
return p._main(args)
end
end
local ns = title.namespace
 
if ns==1 then -- Talk
local getclass = function(args, title)
if require('Module:Disambiguation').isDisambiguation(title.subjectPageTitle:getContent()) then
local class = '¬'
return resolveFQSgrade('disambig',args)
if args.QUALITY_SCALE == 'inline' then
else
class = args.class
return talkDefault
elseif args.QUALITY_SCALE == 'subpage' then
local classTemplate = args.BANNER_NAME .. '/class'
if mw.title.new(classTemplate).exists then
local frame = mw.getCurrentFrame()
class = frame:expandTemplate{title = classTemplate, args = args}
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 then -- Template talk
return resolveFQSgrade('template', args)
elseif ns==829 then -- Module 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)
else
args.FQS = (args.QUALITY_SCALE == 'extended') and 'yes' or 'no'
local SD = require "Module:SimpleDebug"
args[1] = args.class
if not ns then
class = p._main(args, title)
return 'Error'
else
return 'NA'
end
end
return class
end
 
p.readarticleclass = function(options, page) -- used by p._quality and Module:Banner shell
local function getGrade(args, title)
page = page or mw.title.getCurrentTitle().prefixedText
local grade = args[1]
local get_parameter_value = require("Module:Template parameter value").getValue
grade = grade and grade:match('^%s*(.-)%s*$'):lower()
local success, result = get_parameter_value(page, cfg.WPBS_redirects, "class", options)
local ret
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)
if not grade or grade == '¬' then -- undefined
local title = args.page and mw.title.new(args.page) or mw.title.getCurrentTitle()
ret = '¬'
local local_class = getclass(args, title)
 
local prefix, class = 'Y', local_class
-- Ucfirst
if local_class=='¬' then
elseif grade == 'start' or grade == 'stub' or grade == 'list' then
ifclass args[grade] ~= 'no¬' then
elseif args.QUALITY_CRITERIA ~= 'custom' then -- project uses standard scale and will inherit article class if needed
ret = ucfirst(grade)
local article_class = p.readarticleclass({ignore_subtemplates=true},title.prefixedText)
end
article_class = article_class and p._main({article_class}, title)
 
if article_class then -- banner shell exists
-- B
if article_class == '' then -- no article class defined
elseif grade == 'b' then
if local_class == '' then -- local class also does not exist, check whether any other class parameters are defined inside the shell
local bParams = {'b1', 'b2', 'b3', 'b4', 'b5', 'b6'}
local classparam = p.readarticleclass({ignore_blank=true, only_subtemplates=true},title.prefixedText)
local isExtended = false
if classparam == '' then -- no class parameters defined, display as globally unassessed
for _, param in ipairs(bParams) do
prefix = 'H' -- hide quality class in project banner
if args[param] then
end
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
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
ret = isB and 'B' or 'C'
elseif args.b ~= 'no' then
ret = 'B'
end
 
-- Upper-case
elseif grade == 'fa' or grade == 'fl' or grade == 'a' or grade == 'ga' or grade == 'c' then
if args[grade] ~= 'no' then
ret = grade:upper()
end
elseif grade == 'na' then
if args.forceNA == 'yes' then
ret = resolveDefaultGrade(args, title, 'NA')
else
ret = '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 == '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 (args.noprefix and '' or prefix) .. class
 
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()
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
 
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame,{removeBlanks=false, wrappers='Template:Class mask'})
return p._main(args)
end