Module:Class mask: Difference between revisions

Content deleted Content added
add support for help-class, add functions from Module:WikiProject quality assessment
Tag: Reverted
Undid revision 1151975130 by MSGJ (talk)
Line 1:
local p = {}
 
local function ucfirst = function(s)
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(nonarticleclasses) 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 27 ⟶ 7:
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 40 ⟶ 20:
end
 
local function resolveExtraGrade = function(grade, args)
if args[grade] == 'yes' then
return ucfirst(grade)
Line 48 ⟶ 28:
end
 
local function resolveDefaultGrade = function(args, title, talkDefault)
if args.ignorenamespace then
return nil
Line 74 ⟶ 54:
elseif ns==119 then -- Draft talk
return resolveFQSgrade('draft', args)
elseif ns==13 then -- Help talk
return resolveExtraGrade('help', args)
else
return 'NA'
Line 81 ⟶ 59:
end
 
local function getGrade = function(args, title)
local grade = args[1]
grade = grade and grade:match('^%s*(.-)%s*$'):lower()
Line 137 ⟶ 115:
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)
Line 166 ⟶ 142:
end
end
 
return ret
end
 
function p.class_mask = function_main(args, title)
title = title or mw.title.getCurrentTitle()
local out = ''
Line 179 ⟶ 156:
end
 
function p.main = function(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame,{removeBlanks=false, wrappers='Template:Class mask'})
return p.class_mask_main(args)
end
 
local getclass = function(args)
local class = '¬'
if args.QUALITY_SCALE == 'inline' then
class = args.class
elseif args.QUALITY_SCALE == 'subpage' then
if mw.title.new(args.BANNER_NAME..'/class').exists then
local frame = mw.getCurrentFrame()
class = frame:expandTemplate{title = args.BANNER_NAME..'/class', args = args}
end
else
args.FQS = (args.QUALITY_SCALE == 'extended') and 'yes' or 'no'
args[1] = args.class
class = p.class_mask(args)
end
return class
end
 
p.quality = function(frame) -- used by WPBM to check global quality and compare with local parameter
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 p.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