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 or class=='' then -- no fallbacks for non-article classes or the absence of a class
return class
local check_suffix = function(oldsuffix)▼
▲ local cat = mw.title.new(cfg.quality.assessment_category:format(class, category .. ' ' .. (oldsuffix and 'articles' or 'pages')))
▲ return cat.exists and #cat:getContent()>0 -- check if category exists and is not blank
fallback_suffix = 'pages'
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 not class_works(new_class) then
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')
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
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 fallback_suffix then
category = category .. ' ' .. fallback_suffix
elseif not article and mw.title.new('Category:' .. category .. ' pages').exists then
category = category .. ' pages'
else
category = category .. ' articles'
|