Module:Class mask: Difference between revisions
Content deleted Content added
better match for behaviour of Template:Class mask |
fix redirect detection |
||
Line 2: | Line 2: | ||
local function getDocWarning(title) |
local function getDocWarning(title) |
||
if title.namespace == 10 and title.subpageText == 'class' then |
|||
⚫ | |||
title = 'Class mask/doc warning' |
|||
} |
|||
⚫ | |||
end |
end |
||
Line 40: | Line 35: | ||
return nil |
return nil |
||
end |
end |
||
if title.isRedirect then |
if title.subjectPageTitle.isRedirect then |
||
return resolveExtraGrade('redirect',args) |
return resolveExtraGrade('redirect',args) |
||
end |
end |
||
Line 152: | Line 147: | ||
function p._main(args, title) |
function p._main(args, title) |
||
title = title or mw.title.getCurrentTitle() |
title = title or mw.title.getCurrentTitle() |
||
local |
local out = '' |
||
if title.namespace == 10 and title.subpageText == 'class' then |
|||
⚫ | |||
return docWarning .. grade |
|||
⚫ | |||
out = out .. (getGrade(args, title) or '') |
|||
return out |
|||
end |
end |
||
Revision as of 23:16, 31 March 2023
This Lua module is used on approximately 397,000 pages, or roughly 1% of all pages. To avoid major disruption and server load, any changes should be tested in the module's 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.
local p = {}
local function getDocWarning(title)
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 resolveDefaultGrade(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
return talkDefault
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)
else
return 'NA'
end
end
local function getGrade(args, title)
local grade = args[1]
grade = grade and grade:match('^%s*(.-)%s*$'):lower()
local ret
if not grade or grade == '¬' then -- undefined
ret = '¬'
-- Ucfirst
elseif grade == 'start' or grade == 'stub' or grade == 'list' then
if args[grade] ~= 'no' then
ret = ucfirst(grade)
end
-- 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' 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 ret
end
function p._main(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
function p.main(frame)
local args = frame.args or frame:getParent().args
return p._main(args)
end
return p