Module:Episode table: Difference between revisions

Content deleted Content added
fix wrapper
Add regexp
 
(40 intermediate revisions by 6 users not shown)
Line 11:
local EpisodeTable = {}
 
function EpisodeTable.cell(background, width, text, reference, textColor)
local cell = mw.html.create('th')
-- Width
local cell_width
if width == 'auto' then
cell_width = 'auto'
elseif tonumber(width) ~= nil then
cell_width = width .. '%'
else
cell_width = nil
end
-- Cell
cell:attr('scope','col')
:css('background',background or '#CCCCFF')
:css('width',width ~= '' and width .. '%' or nilcell_width)
:css('color',textColor)
:wikitext(text)
Line 37 ⟶ 48:
if link1_cr < 7 or link2_cr < 7 then
refspan
:css('color','black')
:css('background-color','white')
:css('padding','1px')
Line 56 ⟶ 68:
local row = mw.html.create('tr')
if (args.c == nil or args.c == '') then args.c = '#CCCCFF' end
local black_cr = contrast_ratio{args.c, 'black', ['error'] = 0}
local white_cr = contrast_ratio{'white', args.c, ['error'] = 0}
local displaytextblack_cr = (not contrast_ratio{args.nopartc andor 'Part#CCCCFF', 'black', or ['error')] ..= (args.p or '')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)
Line 66 ⟶ 99:
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 "&#8202;" .. EpisodeTable.reference(args.r, args.c) or ''))
return tostring(row)
end
 
function EpisodeTable.new(frame,args)
args = args or {}
local categories = ''
Line 88 ⟶ 121:
local defaultwidths = {};
defaultwidths.overall = 5;
defaultwidths.overall2 = 5;
defaultwidths.season = 5;
defaultwidths.series = 5;
Line 95 ⟶ 129:
-- Create episode table
local root = mw.html.create('table')
-- Table width
local table_width = string.gsub(args.total_width or '','%%','')
if args.total_width == 'auto' or args.total_width == '' then
table_width = 'auto'
elseif tonumber(table_width) ~= nil then
table_width = table_width .. '%'
else
table_width = '100%'
end
root
Line 100 ⟶ 144:
:addClass('plainrowheaders')
:addClass('wikiepisodetable')
:css('width', table_width)
:css('width', args.total_width and string.gsub(args.total_width,'%%','') .. '%' or '100%')
-- Caption
if args.captionshow_caption then
-- Visible caption option, with a tracking category
root:tag('caption'):wikitext(args.caption)
categories = categories .. '[[Category:Articles using Template:Episode table with a visible caption]]'
elseif args.caption then
-- If a visible caption isn't defined, then default to the screenreader-only caption
root:tag('caption'):wikitext(frame:expandTemplate{title='Screen reader-only',args={args.caption}})
end
Line 117 ⟶ 166:
-- Main row
local textColor = background and (black_cr > white_cr and 'black' or 'white') or 'black'
local mainRow = root:tag('tr')
mainRow
:css('color', textColor)
:css('color', background and (black_cr > white_cr and 'black' or 'white') or 'black')
:css('text-align', 'center')
Line 131 ⟶ 181:
local cellNames = {
{'overall','EpisodeNumber',EpisodeTable.abbr('No.','Number') ..
((args.season or args.series or args.EpisodeNumber2 or args.EpisodeNumber2Series or args.forceoverall) and '<br />'..(args.overall_type or 'overall') or '')},
{'overall2','*',''},
{'season','EpisodeNumber2',EpisodeTable.abbr('No.','Number') .. ' in<br />'..(args.season_type or 'season')},
{'series','EpisodeNumber2Series',EpisodeTable.abbr('No.','Number') .. ' in<br />'..(args.series_type or 'series')},
{'title','Title','Title'},
{'aux1','Aux1',''},
Line 140 ⟶ 191:
{'aux2','Aux2',''},
{'aux3','Aux3',''},
{'airdate','OriginalAirDate','Original ' .. (args.released and 'release' or 'air') .. ' date'},
{'altdate','AltDate',''},
{'guests','Guests','Guest(s)'},
Line 158 ⟶ 209:
local thisCellT = args[v[1] .. 'T'] or args[v[2] .. 'T']
local thisCellR = args[v[1] .. 'R'] or args[v[2] .. 'R']
mainRow:node(EpisodeTable.cell(background, thisCell, thisCellT or v[3], thisCellR, textColor))
end
end
Line 172 ⟶ 223:
end
 
return (args.dontclose and mw.ustring.gsub(tostring(root), "</table>", "") or tostring(root)) .. categories
 
local templateStyles = mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'Module:Episode table/styles.css' }
}
return (((args.dontclose or '') ~= '') and mw.ustring.gsub(tostring(root), "</table>", "") or tostring(root)) .. categories .. templateStyles
end
 
Line 186 ⟶ 242:
wrappers = 'Template:Episode table'
})
local check = require('Module:Check for unknown parameters')._check
return EpisodeTable.new(args)
local tracking = ''
end
local title = mw.title.getCurrentTitle()
 
if title.namespace == 0 then
function p.top(frame)
tracking = check({
local args = require('Module:Arguments').getArgs(frame, {
['unknown']='[[Category:Pages using episode table with unknown parameters|_VALUE_'..title.text..']]',
removeBlanks = false,
wrappers ['preview']= 'Page using [[Template:Episode table]] with unknown parameter top"_VALUE_"',
['showblankpositional']='y',
})
['regexp1']='[%w_]+NULL',
args.dontclose = true
'airdate', 'airdateR', 'airdateT', 'altdate', 'AltDate', 'altdateR', 'AltDateR',
args.episodes = nil
'altdateT', 'AltDateT', 'anchor', 'aux1', 'Aux1', 'aux1R', 'Aux1R', 'aux1T',
return EpisodeTable.new(args)
'Aux1T', 'aux2', 'Aux2', 'aux2R', 'Aux2R', 'aux2T', 'Aux2T', 'aux3', 'Aux3',
'aux3R', 'Aux3R', 'aux3T', 'Aux3T', 'aux4', 'Aux4', 'aux4R', 'Aux4R', 'aux4T',
'Aux4T', 'b', 'background', 'c', 'caption', 'country', 'DirectedBy', 'DirectedByR',
'DirectedByT', 'director', 'directorR', 'directorT', 'dontclose', 'EpisodeNumber',
'EpisodeNumber2', 'EpisodeNumber2R', 'EpisodeNumber2Series', 'EpisodeNumber2SeriesR',
'EpisodeNumber2SeriesT', 'EpisodeNumber2T', 'EpisodeNumberR', 'EpisodeNumberT',
'episodes', 'forceoverall', 'guests', 'Guests', 'guestsR', 'GuestsR', 'guestsT',
'GuestsT', 'id', 'musicalguests', 'MusicalGuests', 'musicalguestsR', 'MusicalGuestsR',
'musicalguestsT', 'MusicalGuestsT', 'OriginalAirDate', 'OriginalAirDateR',
'OriginalAirDateT', 'overall', 'overall_type', 'overall2', 'overall2R',
'overall2T', 'overallR', 'overallT', 'prodcode', 'ProdCode', 'prodcodeR',
'ProdCodeR', 'prodcodeT', 'ProdCodeT', 'r', 'season', 'season_type', 'seasonR',
'seasonT', 'series', 'series_type', 'seriesR', 'seriesT', 'show_caption',
'subtitle', 'title', 'Title', 'titleR', 'TitleR', 'titleT', 'TitleT', 'total_width',
'viewers', 'Viewers', 'viewers_type', 'viewersR', 'ViewersR', 'viewersT',
'ViewersT', 'writer', 'writerR', 'writerT', 'WrittenBy', 'WrittenByR', 'WrittenByT'
}, args)
end
return EpisodeTable.new(frame,args) .. tracking
end
 
Line 212 ⟶ 287:
})
return EpisodeTable.reference(args.r,args.b)
end
 
function p.bottom()
return "</table>"
end