Module:WDL
Appearance
![]() | This Lua module is used on approximately 13,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Usage
This module implements the {{WDL}} and {{WDLtot}} templates. Please see the template pages for usage instructions.
Tracking/maintenance category
- Category:WDL error (11)
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p._total(frame, played, won, drawn, lost, category)
if played == '-' or played == '—' then
return '—'
elseif not played then
if not won and not drawn and not lost then
return ''
end
return frame:expandTemplate{title = 'Number table sorting', args = { (won or 0) + (drawn or 0) + (lost or 0) }}
elseif tonumber(played) ~= won + drawn + lost then
return '<span class="error" style="font-size:100%">' .. frame:expandTemplate{title = 'abbr', args = { 'error', 'GP not equal to W + D + L' }} .. (category or '') .. '</span>'
else
return frame:expandTemplate{title = 'Number table sorting', args = { played }}
end
end
function p.total(frame)
local args = getArgs(frame)
return p._total(frame, args[1], args[2], args[3], args[4], args.category)
end
function p.main(frame)
local args = getArgs(frame)
local tableprefix = '| style="text-align:' .. (args.align or 'center') .. '" |'
local retval = tableprefix .. p._total(frame, args[1], args[2], args[3], args[4], args.demospace and '' or '[[Category:WDL error]]') .. '\n'
retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args[2] }} .. '\n'
retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args[3] }} .. '\n'
retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args[4] }} .. '\n'
if args['for'] then
retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args['for'] }} .. '\n'
end
if args.against then
retval = retval .. tableprefix .. frame:expandTemplate{title = 'Number table sorting', args = { args.against }} .. '\n'
end
if args.diff == 'yes' then
if tonumber(args['for']) and tonumber(args.against) then
retval = retval .. tableprefix .. (args['for'] >= args.against and '+' or '') .. (args['for'] - args.against) .. '\n'
else
retval = retval .. tableprefix .. '<span style="display:none">!</span>—\n'
end
end
return retval .. tableprefix .. frame:expandTemplate{title = 'WDL/pct', args = { args[1] or '', args[2] or '', args[3] or '', args[4] or '', args.decimals or '' }} .. '\n'
end
return p