Module:Class mask/sandbox: Difference between revisions

Content deleted Content added
not needed
rv to prev
Line 1:
-- This module implements [[Template:Class mask]].
 
local p = {}
 
Line 7 ⟶ 9:
}
end
end
 
local function trim(s)
return s:match('^%s*(.-)%s*$')
end
 
Line 39 ⟶ 45:
if args.ignorenamespace then
return nil
end
if title.isRedirect then
return resolveExtraGrade('redirect',args)
end
local ns = title.namespace
if ns ==0 1 then -- Talk
return talkDefault
elseif ns ==6 or ns==7107 then -- File talk
return resolveFQSgrade('file', args)
elseif ns ==14 15 then -- Category talk
return resolveFQSgrade('category', args)
elseif ns ==100 101 then -- Portal talk
return resolveFQSgrade('portal', args)
elseif ns ==10 or ns==82811 then -- Template talk
return resolveFQSgrade('template', args)
elseif ns ==4 5 then -- Wikipedia talk
return resolveFQSgrade('project', args)
elseif ns ==118 119 then -- Draft talk
return resolveFQSgrade('draft', args)
elseif gradens == ''109 then -- blankBook talk
return resolveExtraGrade('redirectbook', args)
else
return 'NA'
Line 67 ⟶ 72:
-- We use string.lower here as it's faster than mw.ustring.lower and none
-- of the standard grades have non-Ascii characters.
grade = grade and trim(grade:match('^%s*(.-)%s*$'):lower()
 
local ret
 
-- Undefined
if not grade or grade == '¬' then -- undefined
ret = '¬'
elseif grade == '' then -- blank
 
-- Ucfirst
Line 143 ⟶ 148:
elseif grade == 'template' or grade == 'temp' or grade == 'tpl' or grade == 'templ' then
ret = resolveFQSgrade('template', args)
 
-- Book
if elseif args[grade:lower()] == 'yesbook' then
ret = resolveExtraGrade('book', args)
 
-- FM
Line 153 ⟶ 162:
 
else
-- We can't guarantee that we will only have Ascii grades any more, so
-- normalize the grade again using mw.ustring where necessary.
local trimmedGrade = trim(args[1])
 
-- Upper-case syntax
ret = args[grade:mw.ustring.upper(trimmedGrade)]
 
-- Lower-case syntax
if not ret then
local normalizedGrade = mw.ustring.lower(grade)
if args[grade:lower()] == 'yes' then
if args[normalizedGrade] == 'yes' then
ret = mw.language.getContentLanguage():ucfirst(grade:lower()normalizedGrade)
end
end
end
 
-- Defaults
if not ret then
ret = resolveDefaultGrade(args, title)
end
end
 
Line 173 ⟶ 187:
 
function p._main(args, title)
title = title or mw.title.getCurrentTitle().subjectPageTitle
local docWarning = getDocWarning(title) or ''
local grade = getGrade(args, title) or ''
Line 180 ⟶ 194:
 
function p.main(frame)
localreturn args = framep.args or _main(frame:getParent().args)
return p._main(args)
end