Module:USRD Leaderboard explained

-- This module's function lookup table, used by the calling contextlocal p = local formatnum = require("Module:Formatnum")local format = mw.ustring.format

local projectList =

function p.wikiwork(frame)

-- Determine the WikiProject for which to grab stats. local topic = frame.args[1] local list = projectList[topic]

-- WP 1.0 category names follow the pattern "-Class articles". local cSuffix = "-Class " .. list[1] .. " articles"

-- Get the article counts for each handled class. local qFA = mw.site.stats.pagesInCategory("FA" .. cSuffix, "pages") local qA = mw.site.stats.pagesInCategory("A" .. cSuffix, "pages") local qGA = mw.site.stats.pagesInCategory("GA" .. cSuffix, "pages") local qB = mw.site.stats.pagesInCategory("B" .. cSuffix, "pages") local qC = mw.site.stats.pagesInCategory("C" .. cSuffix, "pages") local qStart = mw.site.stats.pagesInCategory("Start" .. cSuffix, "pages") local qStub = mw.site.stats.pagesInCategory("Stub" .. cSuffix, "pages")

-- Sum of all class article counts; i.e. all articles in scope of the WikiProject. local total = qFA + qA + qGA + qB + qC + qStart + qStub -- Total WikiWork; weighted average based on class of all articles. local totWW = ((qFA * 0) + qA + (qGA * 2) + (qB * 3) + (qC * 4) + (qStart * 5) + (qStub * 6)) local totalWW = formatnum.formatNum(totWW, 'en') -- Relative WikiWork; Total WikiWork รท total number of articles local relWW = (totWW / total) local relativeWW = formatnum.formatNum(relWW, 'en', 3) local link = tostring("" .. list[2] .. "") -- Formatted numbers for the table local fFA = formatnum.formatNum(qFA, 'en') local fA = formatnum.formatNum(qA, 'en') local fGA = formatnum.formatNum(qGA, 'en') local fB = formatnum.formatNum(qB, 'en') local fC = formatnum.formatNum(qC, 'en') local fStart = formatnum.formatNum(qStart, 'en') local fStub = formatnum.formatNum(qStub, 'en') local fTotal = formatnum.formatNum(total, 'en')

--Create the wikitext output and return it to the calling template. if list[3] then local format = [=[background-color: %s !important -- '''%s''' -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s]=] return mw.ustring.format(format, list[3], link, fFA, fA, fGA, fB, fC, fStart, fStub, fTotal, totalWW, relativeWW) else local format = [=[-- '''%s''' -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s -- %s]=] return mw.ustring.format(format, link, fFA, fA, fGA, fB, fC, fStart, fStub, fTotal, totalWW, relativeWW) end

end

return p