Module:Backlog table
Appearance
This module depends on the following other modules: |
Implements {{backlog table}}.
--[=[
Implements [[Template:Backlog table]]
]=]
require('strict')
local p = {} --p stands for package
local getArgs = require('Module:Arguments').getArgs
local function backlog_status(cat)
if not cat then
return nil
end
local count = mw.site.stats.pagesInCategory(cat, 'all')
local frame = mw.getCurrentFrame()
if count < 20 then
return frame:expandTemplate {
['title'] = 'done',
['args'] = {}
}
elseif count < 50 then
return frame:expandTemplate {
['title'] = 'doing',
['args'] = {'No backlog'}
}
else
return frame:expandTemplate {
['title'] = 'not done'
}
end
end
local function backlog_button(cat)
return '<span class="submit ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">[[:Category:' .. cat .. '|' .. cat .. ']]</span></span>'
end
local function backlog_tr(cat)
if not cat then
return nil
end
local link = backlog_button(cat)
local status = backlog_status(cat)
return '<tr><td>' .. link .. '</td><td>' .. status .. '</td></tr>'
end
function p._backlog_table(args)
local table_open = '<table class="wikitable" style="float:right;">'
local frame = mw.getCurrentFrame()
local purge = frame:expandTemplate {
['title'] = 'purge',
['args'] = {}
}
local caption = '<caption>Backlog status (' .. purge .. ')'..'</caption>'
local header_row = '<tr><th>Category</th><th>Current status</th></tr>'
local row_table = {}
for k, v in pairs(args) do
row_table[k] = backlog_tr(v)
end
local rows = table.concat(row_table)
return table_open .. caption .. header_row .. rows .. '</table>'
end
function p.backlog_table(frame)
return p._backlog_table(getArgs(frame))
end
return p