Module:Class mask: Difference between revisions

Content deleted Content added
add FQS and extra grades
add defaults for different namespaces and fix some if-else logic bugs
Line 39:
if args[grade] == 'yes' then
return ucfirst(grade)
else
return 'NA'
end
end
 
local function resolveDefaultGrade(args, title)
local ns = title.namespace
if ns == 7 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 == 5 then -- Wikipedia talk
return resolveFQSgrade('project', args)
elseif ns == 119 then -- Draft talk
return resolveFQSgrade('draft', args)
elseif ns == 109 then -- Book talk
return resolveExtraGrade('book', args)
else
return 'NA'
Line 46 ⟶ 67:
local function getGrade(args, title)
local grade = args[1]
-- We use string.lower here as it's faster and none of the standard grades
-- have non-Ascii characters.
grade = grade and trim(grade):lower()
 
Line 55 ⟶ 78:
 
-- Ucfirst
-- We put these first as they are probably the most common grades on the
elseif (grade == 'start' or grade == 'stub' or grade == 'list')
-- site. The other grades are also roughly in order of prevalence.
and args[grade] ~= 'no'
elseif (grade == 'start' or grade == 'stub' or grade == 'list') then
then
andif args[grade] ~= 'no' then
ret = ucfirst(grade)
end
 
-- B
Line 84 ⟶ 109:
 
-- Upper-case
elseif (grade == 'fa' or grade == 'fl' or grade == 'a' or grade == 'ga' or grade == 'c') then
andif args[grade] ~= 'no' then
ret = grade:upper()
then
end
ret = grade:upper()
 
-- NA
elseif grade == 'na' then
if args.forceNA == 'yes' then
ret = resolveDefaultGrade(args, title)
else
ret = 'NA'
end
 
-- File
Line 125 ⟶ 158:
end
 
else
-- We can't guarantee that we will only have Ascii grades anymore, so
-- normalize the grade again using mw.ustring where necessary.
local trimmedGrade = trim(args[1])
 
-- Upper-case syntax
ret = args[mw.ustring.upper(trimmedGrade)]
 
-- Lower-case syntax
if not ret then
local normalizedGrade = mw.ustring.lower(grade)
if args[normalizedGrade] == 'yes' then
lang = mw.language.getContentLanguage()
ret = lang:ucfirst(normalizedGrade)
end
end
 
-- Defaults
if not ret then
ret = resolveDefaultGrade(args, title)
end
end