Module:WikiProject banner/sandbox: Difference between revisions

Content deleted Content added
move helper function inward
avoid repeatedly checking the existence of categories
Line 322:
assessment_link = nil
end
 
-- if this is non-nil, this is the suffix which must be used with the class check_fallbacks returned
local fallback_suffix = nil
-- returns the most specific class for which the given category exists
-- FM is unusual: FM > File > NA
-- all other non-article classes: Category > NA, Redirect > NA, etc.
-- performance note: this is expensive whenever BOTH article is false AND class is nonempty
local check_fallbacks = function(class, category)
fallback_suffix = nil
if article then -- no fallbacks for articles
if article or class=='' then -- no fallbacks for non-article classes or the absence of a class
return class
end
else -- check fallbacks for non-article classes
local new_class = class
-- temporary transition code
local category_exists = function(class, new_suffix_style)
local cat = mw.title.new(cfg.quality.assessment_category:format(class, category .. ' ' .. (oldsuffixnew_suffix_style and 'articlespages' or 'pagesarticles')))
local check_suffix = function(oldsuffix)
return cat.exists and #cat:getContent()>0 -- check if category exists and is not blank
local cat = mw.title.new(cfg.quality.assessment_category:format(class, category .. ' ' .. (oldsuffix and 'articles' or 'pages')))
end
return cat.exists and #cat:getContent()>0 -- check if category exists and is not blank
local check_suffixclass_works = function(oldsuffixclass)
end
if not category_exists(new_classclass, true) then -- try preferred suffix
return check_suffix(false) or check_suffix(true)
fallback_suffix = 'pages'
return new_classtrue
elseif category_exists(class, false) then -- fall back to old suffix
fallback_suffix = 'articles'
return true
else
return false
end
if class=='FM' and not category_exists('FM') then
new_class = 'File' -- fall back to File-class if FM category does not exist
end
if not category_exists(new_class) then
new_class = 'NA' -- use NA for non-article pages if category does not exist
end
return new_class
end
if class=='FM' and not category_existsclass_works('FM') then
new_class = 'File' -- fall back to File-class if FM-class category does notdoesn't existwork
end
if not class_works(new_class) then
new_class = 'NA' -- use NA for non-article pages if categoryclass does notdoesn't existwork
end
return new_class
end
 
local class = raw_args.class
if class then -- banner gives quality ratings
Line 395 ⟶ 411:
show = true -- show quality class in project banner
elseif article_class=='FM' then
class = check_fallbacks(article_class, assessment_cat) -- TODO performance?
check_redundant()
elseif not article and class~='FM' then -- article class and local class are both non-article classes
Line 407 ⟶ 423:
end
local category = (class=='' and 'Unassessed' or class..'-Class') .. ' ' .. assessment_cat -- .. ' ' .. (article and 'articles' or 'pages')
category = category .. ' pages' -- use "pages" for non-articles if the category exists: temporary transition code
if not article and mw.title.new('Category:' .. category .. ' pages').exists then
if fallback_suffix then
category = category .. ' pages' -- use "pages" for non-articles if the category exists: temporary transition code
category = category .. ' ' .. fallback_suffix
ifelseif not article and mw.title.new('Category:' .. category .. ' pages').exists then
category = category .. ' pages'
else
category = category .. ' articles'
Line 618 ⟶ 637:
local tf_class = check_fallbacks(class, tf_assessment_cat)
local category = (tf_class=='' and 'Unassessed' or tf_class..'-Class') .. ' ' .. tf_assessment_cat
if-- notuse article"pages" andfor mw.title.new('Category:'non-articles ..if the category ..exists: 'temporary pages').existstransition thencode
if fallback_suffix then
category = category .. ' pages' -- use "pages" for non-articles if the category exists: temporary transition code
category = category .. ' ' .. fallback_suffix
elseif not article and mw.title.new('Category:' .. category .. ' pages').exists then
category = category .. ' pages'
else
category = category .. ' articles'