Revision as of 12:15, 8 August 2020 view sourceKoavf (talk | contribs)Extended confirmed users2,174,994 edits Undid revision 971123583 by Alex 21 (talk) No consensus at Template talk:Episode tableTag: Undo← Previous edit | Revision as of 04:42, 9 August 2020 view source Alex 21 (talk | contribs)Extended confirmed users, Page movers, File movers, Pending changes reviewers, Template editors139,301 edits Restore; revert was not part of BRD as explained in discussion, and no support has been provided for not including this update.Tag: Manual revertNext edit → | ||
Line 75: | Line 75: | ||
end | end | ||
function EpisodeTable.new(args) | function EpisodeTable.new(frame,args) | ||
args = args or {} | args = args or {} | ||
local categories = '' | local categories = '' | ||
Line 104: | Line 104: | ||
-- Caption | -- Caption | ||
if args.caption then | if args.caption then | ||
root:tag('caption'):wikitext(args.caption) | root:tag('caption'):wikitext(frame:expandTemplate{title='sronly',args={args.caption}}) | ||
end | end | ||
Line 186: | Line 187: | ||
wrappers = 'Template:Episode table' | wrappers = 'Template:Episode table' | ||
}) | }) | ||
return EpisodeTable.new(args) | return EpisodeTable.new(frame,args) | ||
end | end | ||
Line 196: | Line 197: | ||
args.dontclose = true | args.dontclose = true | ||
args.episodes = nil | args.episodes = nil | ||
return EpisodeTable.new(args) | return EpisodeTable.new(frame,args) | ||
end | end | ||
Revision as of 04:42, 9 August 2020
Module documentation[view] [edit] [history] [purge]This Lua module is used on approximately 21,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 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. |
This module depends on the following other modules: |
This module uses TemplateStyles: |
Usage
Creates one of three usages related to {{Episode table}} with the parameters defined in the documentation of the template:
A standard episode table with
{{#invoke:Episode table|main}}
A row for a parted season with
{{#invoke:Episode table|part}}
A white background for references used in the header row of episode tables with
{{#invoke:Episode table|ref}}
Tracking categories
- Category:Articles using Template:Episode table with a visible caption (271)
- Category:Articles using Template:Episode table with invalid colour combination (3)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
-- This module implements {{Episode table}} and {{Episode table/part}}. local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' ) -------------------------------------------------------------------------------- -- EpisodeTable class -- The main class. -------------------------------------------------------------------------------- local contrast_ratio = require('Module:Color contrast')._ratio local EpisodeTable = {} function EpisodeTable.cell(background, width, text, reference) local cell = mw.html.create('th') -- Cell cell:attr('scope','col') :css('background',background or '#CCCCFF') :css('width',width ~= '' and width .. '%' or nil) :wikitext(text) -- Reference if reference and reference ~= '' then cell:wikitext(" " .. EpisodeTable.reference(reference, background)) end return cell end function EpisodeTable.reference(reference, background) local link1_cr = contrast_ratio{'#0645AD', background or '#CCCCFF', = 0} local link2_cr = contrast_ratio{'#0B0080', background or '#CCCCFF', = 0} local refspan = mw.html.create('span') :wikitext(reference) if link1_cr < 7 or link2_cr < 7 then refspan :css('background-color','white') :css('padding','1px') :css('display','inline-block') :css('line-height','50%') end return tostring(refspan) end function EpisodeTable.abbr(text,title) local abbr = mw.html.create('abbr') :attr('title',title) :wikitext(text) return tostring(abbr) end function EpisodeTable.part(frame,args) local row = mw.html.create('tr') local black_cr = contrast_ratio{args.c, 'black', = 0} local white_cr = contrast_ratio{'white', args.c, = 0} local displaytext = (not args.nopart and 'Part ' or '') .. (args.p or '') local plainText = require('Module:Plain text')._main local displayTextAnchor = plainText(displaytext) row:tag('td') :attr('colspan', 13) :attr('id', displayTextAnchor) :css('text-align', 'center') :css('background-color', args.c) :css('color', black_cr > white_cr and 'black' or 'white') :wikitext("'''" .. displaytext .. "'''" .. (args.r and " " .. EpisodeTable.reference(args.r, args.c) or '')) return tostring(row) end function EpisodeTable.new(frame,args) args = args or {} local categories = '' local background = (args.background and args.background ~= '' and args.background ~= '#') and args.background or nil -- Add # to background if necessary if background ~= nil and HTMLcolor == nil then background = '#'..(mw.ustring.match(background, '^*(*)*$') or '') end -- Default widths noted by local consensus local defaultwidths = {}; defaultwidths.overall = 5; defaultwidths.season = 5; defaultwidths.series = 5; defaultwidths.prodcode = 7; defaultwidths.viewers = 10; -- Create episode table local root = mw.html.create('table') root :addClass('wikitable') :addClass('plainrowheaders') :addClass('wikiepisodetable') :css('width', args.total_width and string.gsub(args.total_width,'%%','') .. '%' or '100%') -- Caption if args.caption then root:tag('caption'):wikitext(frame:expandTemplate{title='sronly',args={args.caption}}) end -- Colour contrast; add to category only if it's in the mainspace local title = mw.title.getCurrentTitle() local black_cr = contrast_ratio{background, 'black', = 0} local white_cr = contrast_ratio{'white', background, = 0} if title.namespace == 0 and (args.background and args.background ~= '' and args.background ~= '#') and black_cr < 7 and white_cr < 7 then categories = categories .. ']' end -- Main row local mainRow = root:tag('tr') mainRow :css('color', background and (black_cr > white_cr and 'black' or 'white') or 'black') :css('text-align', 'center') -- Cells do local used_season = false local country = args.country ~= '' and args.country ~= nil local viewers = (country and args.country or '') .. ' ' .. (country and 'v' or 'V') .. 'iewers' .. ((not args.viewers_type or args.viewers_type ~= '') and '<br />(' .. (args.viewers_type or 'millions') .. ')' or '') local cellNames = { {'overall','EpisodeNumber',EpisodeTable.abbr('No.','Number') .. ((args.season or args.series or args.EpisodeNumber2 or args.EpisodeNumber2Series or args.forceoverall) and '<br />overall' or '')}, {'season','EpisodeNumber2',EpisodeTable.abbr('No.','Number') .. ' in<br />season'}, {'series','EpisodeNumber2Series',EpisodeTable.abbr('No.','Number') .. ' in<br />series'}, {'title','Title','Title'}, {'aux1','Aux1',''}, {'director','DirectedBy','Directed by'}, {'writer','WrittenBy','Written by'}, {'aux2','Aux2',''}, {'aux3','Aux3',''}, {'airdate','OriginalAirDate','Original ' .. (args.released and 'release' or 'air') .. ' date'}, {'altdate','AltDate',''}, {'guests','Guests','Guest(s)'}, {'musicalguests','MusicalGuests','Musical/entertainment guest(s)'}, {'prodcode','ProdCode',EpisodeTable.abbr('Prod.','Production') .. '<br />code'}, {'viewers','Viewers',viewers}, {'aux4','Aux4',''} } for k,v in pairs(cellNames) do local thisCell = args] or args] if thisCell and (v ~= 'series' or (v == 'series' and used_season == false)) then if v == 'season' then used_season = true end if (k <= 3 and thisCell == '') then thisCell = '5' end if (thisCell == '' and defaultwidths]) then thisCell = defaultwidths] end local thisCellT = args .. 'T'] or args .. 'T'] local thisCellR = args .. 'R'] or args .. 'R'] mainRow:node(EpisodeTable.cell(background, thisCell, thisCellT or v, thisCellR)) end end -- Episodes if args.episodes then if args.anchor then args.episodes = string.gsub(args.episodes, "(id=\")(ep%w+\")", "%1" .. args.anchor .. "%2") end root:node(args.episodes) end end return (args.dontclose and mw.ustring.gsub(tostring(root), "</table>", "") or tostring(root)) .. categories end -------------------------------------------------------------------------------- -- Exports -------------------------------------------------------------------------------- local p = {} function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { removeBlanks = false, wrappers = 'Template:Episode table' }) return EpisodeTable.new(frame,args) end function p.top(frame) local args = require('Module:Arguments').getArgs(frame, { removeBlanks = false, wrappers = {'Template:Episode table top', 'Template:Episode table/top'} }) args.dontclose = true args.episodes = nil return EpisodeTable.new(frame,args) end function p.part(frame) local args = require('Module:Arguments').getArgs(frame, { removeBlanks = false, wrappers = 'Template:Episode table/part' }) return EpisodeTable.part(frame,args) end function p.ref(frame) local args = require('Module:Arguments').getArgs(frame, { removeBlanks = false, }) return EpisodeTable.reference(args.r,args.b) end function p.bottom() return "</table>" end return pCategories: