Module:WikiProject assessment progression and Module:WikiProject assessment progression/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
imported>Legoktm
Replace Module:No globals with require( "strict" )
 
imported>Aluxosm
Improve the 'no project' error message
 
Line 12: Line 12:


local function categoryCount(category, project)
local function categoryCount(category, project)
return mw.site.stats.pagesInCategory(
local success, count = pcall(function()
string.format('%s %s articles', category, project),
return mw.site.stats.pagesInCategory(
'pages'
string.format('%s %s articles', category, project),
)
'pages'
)
end)
 
if success then return count end
 
    mw.log('Error retreiving category')
return 0
end
end


Line 24: Line 31:


local function percentComplete(sum, total)
local function percentComplete(sum, total)
if total == 0 then return '0' end
return tostring(round(100 * sum / total))
return tostring(round(100 * sum / total))
end
end
Line 54: Line 62:
function p._main(args)
function p._main(args)
local project = arg_or_default(args, "project", nil)
local project = arg_or_default(args, "project", nil)
mw.addWarning('No project defined for [[Template:WikiProject assessment progression]]')
if not project then return 0 end
local classCount = countCategoryArticles(classes, project)
local classCount = countCategoryArticles(classes, project)
local total = calculateProjectTotal(project)
local total = calculateProjectTotal(project)