Jump to content

Module:Episode table

Permanently protected module
From Wikipedia, the free encyclopedia

-- This module implements {{Episode table}} and {{Episode table/part}}.localHTMLcolor=mw.loadData('Module:Color contrast/colors')---------------------------------------------------------------------------------- EpisodeTable class-- The main class.--------------------------------------------------------------------------------localcontrast_ratio=require('Module:Color contrast')._ratiolocalEpisodeTable={}functionEpisodeTable.cell(background,width,text,reference,textColor)localcell=mw.html.create('th')-- Widthlocalcell_widthifwidth=='auto'thencell_width='auto'elseiftonumber(width)~=nilthencell_width=width..'%'elsecell_width=nilend-- Cellcell:attr('scope','col'):css('background',backgroundor'#CCCCFF'):css('width',cell_width):css('color',textColor):wikitext(text)-- Referenceifreferenceandreference~=''thencell:wikitext("&#8202;"..EpisodeTable.reference(reference,background))endreturncellendfunctionEpisodeTable.reference(reference,background)locallink1_cr=contrast_ratio{'#0645AD',backgroundor'#CCCCFF',['error']=0}locallink2_cr=contrast_ratio{'#0B0080',backgroundor'#CCCCFF',['error']=0}localrefspan=mw.html.create('span'):wikitext(reference)iflink1_cr<7orlink2_cr<7thenrefspan:css('color','black'):css('background-color','white'):css('padding','1px'):css('display','inline-block'):css('line-height','50%')endreturntostring(refspan)endfunctionEpisodeTable.abbr(text,title)localabbr=mw.html.create('abbr'):attr('title',title):wikitext(text)returntostring(abbr)endfunctionEpisodeTable.part(frame,args)localrow=mw.html.create('tr')if(args.c==nilorargs.c=='')thenargs.c='#CCCCFF'endlocalblack_cr=contrast_ratio{args.cor'#CCCCFF','black',['error']=0}localwhite_cr=contrast_ratio{'white',args.cor'#CCCCFF',['error']=0}localpartTypes={{'act','Act'},{'chapter','Chapter'},{'part','Part'},{'volume','Volume'},{'week','Week'},}localdisplaytext=''localisAnyPartSet=falsefork,vinpairs(partTypes)doifargs[v[1]]thenisAnyPartSet=truedisplaytext=v[2]..' '..args[v[1]]endendifargs.subtitlethendisplaytext=displaytext..((isAnyPartSetand': 'or'')..args.subtitle)endlocalplainText=require('Module:Plain text')._mainlocaldisplayTextAnchor=plainText(displaytext)row:tag('td'):attr('colspan',13):attr('id',args.idordisplayTextAnchor):css('text-align','center'):css('background-color',args.cor'#CCCCFF'):css('color',black_cr>white_crand'black'or'white'):wikitext((args.noboldanddisplaytextor"'''"..displaytext.."'''")..(args.rand"&#8202;"..EpisodeTable.reference(args.r,args.c)or''))returntostring(row)endfunctionEpisodeTable.new(frame,args)args=argsor{}localcategories=''localbackground=(args.backgroundandargs.background~=''andargs.background~='#')andargs.backgroundornil-- Add # to background if necessaryifbackground~=nilandHTMLcolor[background]==nilthenbackground='#'..(mw.ustring.match(background,'^[%s#]*([a-fA-F0-9]*)[%s]*$')or'')end-- Default widths noted by local consensuslocaldefaultwidths={};defaultwidths.overall=5;defaultwidths.overall2=5;defaultwidths.season=5;defaultwidths.series=5;defaultwidths.prodcode=7;defaultwidths.viewers=10;-- Create episode tablelocalroot=mw.html.create('table')-- Table widthlocaltable_width=string.gsub(args.total_widthor'','%%','')ifargs.total_width=='auto'orargs.total_width==''thentable_width='auto'elseiftonumber(table_width)~=nilthentable_width=table_width..'%'elsetable_width='100%'endroot:addClass('wikitable'):addClass('plainrowheaders'):addClass('wikiepisodetable'):css('width',table_width)-- Captionifargs.show_captionthen-- Visible caption option, with a tracking categoryroot:tag('caption'):wikitext(args.caption)categories=categories..'[[Category:Articles using Template:Episode table with a visible caption]]'elseifargs.captionthen-- If a visible caption isn't defined, then default to the screenreader-only captionroot:tag('caption'):wikitext(frame:expandTemplate{title='Screen reader-only',args={args.caption}})end-- Colour contrast; add to category only if it's in the mainspacelocaltitle=mw.title.getCurrentTitle()localblack_cr=contrast_ratio{background,'black',['error']=0}localwhite_cr=contrast_ratio{'white',background,['error']=0}iftitle.namespace==0and(args.backgroundandargs.background~=''andargs.background~='#')andblack_cr<7andwhite_cr<7thencategories=categories..'[[Category:Articles using Template:Episode table with invalid colour combination]]'end-- Main rowlocaltextColor=backgroundand(black_cr>white_crand'black'or'white')or'black'localmainRow=root:tag('tr')mainRow:css('color',textColor):css('text-align','center')-- Cellsdolocalused_season=falselocalcountry=args.country~=''andargs.country~=nillocalviewers=(countryandargs.countryor'')..' '..(countryand'v'or'V')..'iewers'..((notargs.viewers_typeorargs.viewers_type~='')and'<br />('..(args.viewers_typeor'millions')..')'or'')localcellNames={{'overall','EpisodeNumber',EpisodeTable.abbr('No.','Number')..((args.seasonorargs.seriesorargs.EpisodeNumber2orargs.EpisodeNumber2Seriesorargs.forceoverall)and'<br />'..(args.overall_typeor'overall')or'')},{'overall2','*',''},{'season','EpisodeNumber2',EpisodeTable.abbr('No.','Number')..' in<br />'..(args.season_typeor'season')},{'series','EpisodeNumber2Series',EpisodeTable.abbr('No.','Number')..' in<br />'..(args.series_typeor'series')},{'title','Title','Title'},{'aux1','Aux1',''},{'director','DirectedBy','Directed by'},{'writer','WrittenBy','Written by'},{'aux2','Aux2',''},{'aux3','Aux3',''},{'airdate','OriginalAirDate','Original release 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',''}}fork,vinpairs(cellNames)dolocalthisCell=args[v[1]]orargs[v[2]]ifthisCelland(v[1]~='series'or(v[1]=='series'andused_season==false))thenifv[1]=='season'thenused_season=trueendif(k<=3andthisCell=='')thenthisCell='5'endif(thisCell==''anddefaultwidths[v[1]])thenthisCell=defaultwidths[v[1]]endlocalthisCellT=args[v[1]..'T']orargs[v[2]..'T']localthisCellR=args[v[1]..'R']orargs[v[2]..'R']mainRow:node(EpisodeTable.cell(background,thisCell,thisCellTorv[3],thisCellR,textColor))endend-- Episodesifargs.episodesthenifargs.anchorthenargs.episodes=string.gsub(args.episodes,"(id=\")(ep%w+\")","%1"..args.anchor.."%2")endroot:node(args.episodes)endendlocaltemplateStyles=mw.getCurrentFrame():extensionTag{name='templatestyles',args={src='Module:Episode table/styles.css'}}return(((args.dontcloseor'')~='')andmw.ustring.gsub(tostring(root),"</table>","")ortostring(root))..categories..templateStylesend---------------------------------------------------------------------------------- Exports--------------------------------------------------------------------------------localp={}functionp.main(frame)localargs=require('Module:Arguments').getArgs(frame,{removeBlanks=false,wrappers='Template:Episode table'})localcheck=require('Module:Check for unknown parameters')._checklocaltracking=''localtitle=mw.title.getCurrentTitle()iftitle.namespace==0thentracking=check({['unknown']='[[Category:Pages using episode table with unknown parameters|_VALUE_'..title.text..']]',['preview']='Page using [[Template:Episode table]] with unknown parameter "_VALUE_"',['showblankpositional']='y','airdate','airdateR','airdateT','altdate','AltDate','altdateR','AltDateR','altdateT','AltDateT','anchor','aux1','Aux1','aux1R','Aux1R','aux1T','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)endreturnEpisodeTable.new(frame,args)..trackingendfunctionp.part(frame)localargs=require('Module:Arguments').getArgs(frame,{removeBlanks=false,wrappers='Template:Episode table/part'})returnEpisodeTable.part(frame,args)endfunctionp.ref(frame)localargs=require('Module:Arguments').getArgs(frame,{removeBlanks=false,})returnEpisodeTable.reference(args.r,args.b)endreturnp
close