Module:Class mask
Appearance
![]() | This Lua module is used on approximately 327,000 pages, or roughly 1% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
This module implements {{class mask}}. See the template page for documentation.
Quality function
This "quality" function implements the logic needed for Wikipedia:Village pump (proposals)/Archive 198#Project-independent quality assessments.
The module takes a project-defined class |class=
and a banner-defined class (tested via |article_class=
) and normalises the output. The result is prefixed by a letter as follows:
- H: the project class is not defined, or it is defined and equals the article class. In this case WPBannerMeta will hide the display of the quality assessment (categorisation will still happen as usual).
- X: the project class and article class differ, so the tracking category Category:Articles with conflicting quality ratings will be populated.
- Y: the project class is defined and the article class is undefined or invalid. The quality assessment is displayed as usual in the project banner.
This function is tested at Module talk:Class mask/testcases2.
-- This module implements [[Template:Class mask]].
local lang -- Lazily load a language object
local p = {}
local function getDocWarning(title)
if title.namespace == 10 and title.subpageText == 'class' then
return mw.getCurrentFrame():expandTemplate{
title = 'Class mask/doc warning'
}
end
end
local function trim(s)
return s:match('^%s*(.-)%s*$')
end
local function ucfirst(s)
-- Returns the given string with the first character in upper case.
-- Should not be used with non-ascii strings.
return s:sub(1, 1):upper() .. s:sub(2, -1)
end
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)
else
return 'NA'
end
end
local function resolveExtraGrade(grade, args)
if args[grade] == 'yes' then
return ucfirst(grade)
else
return 'NA'
end
end
local function getGrade(args, title)
local grade = args[1]
grade = grade and trim(grade):lower()
local ret
-- Undefined
if not grade or grade == '¬' then
ret = '¬'
-- Ucfirst
elseif (grade == 'start' or grade == 'stub' or grade == 'list')
and args[grade] ~= 'no'
then
ret = ucfirst(grade)
-- 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
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')
and args[grade] ~= 'no'
then
ret = grade:upper()
-- File
elseif grade == 'file' or grade == 'image' or grade == 'img' then
ret = resolveFQSgrade('file', args)
-- Category
elseif grade == 'category' or grade == 'cat' or grade == 'categ' then
ret = resolveFQSgrade('category', args)
-- Disambguation
elseif grade == 'dab' or grade == 'disambig' or grade == 'disambiguation' or grade == 'disamb' then
ret = resolveFQSgrade('disambig', args)
-- Redirect
elseif grade == 'redirect' or grade == 'red' or grade == 'redir' then
ret = resolveExtraGrade('redirect', args)
-- Portal, Project and Draft
elseif grade == 'portal' or grade == 'project' or grade == 'draft' then
ret = resolveFQSgrade(grade, args)
-- Template
elseif grade == 'template' or grade == 'temp' or grade == 'tpl' or grade == 'templ' then
ret = resolveFQSgrade('template', args)
-- Book
elseif grade == 'book' then
ret = resolveExtraGrade('book', args)
-- FM
elseif grade == 'fm' then
if args.fm == 'yes' then
ret = 'FM'
else
ret = resolveFQSgrade('file', args)
end
end
return ret
end
function p._main(args, title)
title = title or mw.title.getCurrentTitle()
local docWarning = getDocWarning(title) or ''
local grade = getGrade(args, title) or ''
return docWarning .. grade
end
function p.main(frame)
return p._main(frame:getParent().args)
end
return p