Module:Class mask/sandbox: Difference between revisions

Content deleted Content added
3 more local functions
add new quality function from Module:WikiProject quality assessment
Line 38:
end
 
local function ucfirst = function(s)
-- Returns the given string with the first character in upper case.
-- Should not be used with non-ascii strings.
Line 44:
end
 
local function 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 function resolveFQSgrade = function(grade, args)
if (args[grade] or args.FQS) == 'yes' then
return ucfirst(grade)
Line 57:
end
 
local function resolveExtraGrade = function(grade, args)
if args[grade] == 'yes' then
return ucfirst(grade)
Line 65:
end
 
local function resolveDefaultGrade = function(args, title, talkDefault)
if args.ignorenamespace then
return nil
Line 98:
end
 
local function getGrade = function(args, title)
local grade = args[1]
grade = grade and grade:match('^%s*(.-)%s*$'):lower()
Line 183:
end
end
 
return ret
end
 
function p._main = function(args, title)
title = title or mw.title.getCurrentTitle()
local out = ''
Line 197 ⟶ 196:
end
 
function 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
 
p.quality = function(frame)
local local_class = getclass(frame.args)
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 = frame.args.article_class or readarticleclass() -- checks parameter for testing purposes
article_class = article_class and class_mask{article_class, ignorenamespace=frame.args.ignorenamespace} or '¬' -- normalise if not false
if (article_class == '¬') or (article_class == '') then -- article class does not exist, display quality class in project banner as normal
elseif (local_class == '') or (local_class == article_class) then -- article class and local class are the same, or local is not specified
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
return (frame.args.noprefix and '' or prefix) .. class
end