Module:Media table section
Appearance
| This Lua module is used on many 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 ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| Editing of this module by new or unregistered users is currently disabled. See the protection policy and protection log for more details. If you cannot edit this module and you wish to make a change, you can submit an edit request, discuss changes on the talk page, request unprotection, log in, or create an account. |
| This module depends on the following other modules: |
Usage
Creates the usages related to {{Media table section}} with the parameters defined in the documentation of the template:
A row for a parted media table with
{{#invoke:Media table section|part}}
-- This module implements {{Media table section}}.
local MediaTable = {}
local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' )
local contrast_ratio = require('Module:Color contrast')._ratio
function MediaTable.part(args)
local row = mw.html.create('tr')
if (args.c == 'header-blue' or args.c == nil or args.c == '') then args.c = '#CCCCFF' end
if (args.c == 'header-grey' or args.c == 'header-gray') then args.c = '#EAECF0' end
-- Add # to color if necessary
if args.c ~= nil and HTMLcolor[args.c] == nil then
args.c = '#'..(mw.ustring.match(args.c, '^[%s#]*([a-fA-F0-9]*)[%s]*$') or '')
end
local black_cr = contrast_ratio{args.c or '#CCCCFF', 'black', ['error'] = 0}
local white_cr = contrast_ratio{'white', args.c or '#CCCCFF', ['error'] = 0}
local partTypes = {
{'act','Act'},
{'chapter','Chapter'},
{'part','Part'},
{'volume','Volume'},
{'week','Week'},
}
local displaytext = ''
local isAnyPartSet = false
for k,v in pairs(partTypes) do
if args[v[1]] then
isAnyPartSet = true
displaytext = v[2] .. ' ' .. args[v[1]]
end
end
if args.subtitle then
displaytext = displaytext .. ((isAnyPartSet and ': ' or '') .. args.subtitle)
end
local plainText = require('Module:Plain text')._main
local displayTextAnchor = plainText(displaytext)
row:tag('td')
:attr('colspan', 13)
:attr('id', args.id or displayTextAnchor)
:css('text-align', 'center')
:css('background-color', args.c or '#CCCCFF')
:css('color', black_cr > white_cr and 'black' or 'white')
:wikitext((args.nobold and displaytext or "'''" .. displaytext .. "'''") .. (args.r and " " .. MediaTable.reference(args.r, args.c) or ''))
return tostring(row)
end
function MediaTable.reference(reference, background)
local link1_cr = contrast_ratio{'#0645AD', background or '#CCCCFF', ['error'] = 0}
local link2_cr = contrast_ratio{'#0B0080', background or '#CCCCFF', ['error'] = 0}
local refspan = mw.html.create('span')
:wikitext(reference)
if link1_cr < 7 or link2_cr < 7 then
refspan
:css('color','black')
:css('background-color','white')
:css('padding','1px')
:css('display','inline-block')
:css('line-height','50%')
end
return tostring(refspan)
end
--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------
local p = {}
function p.part(frame)
local args = require('Module:Arguments').getArgs(frame, {
removeBlanks = false,
wrappers = 'Template:Media table section'
})
return MediaTable.part(args)
end
return p