Revision as of 03:31, 23 May 2018 by en>Centrist16(Created page with "-- This module implements {{Episode table}} and {{Episode table/part}}. local HTMLcolor = mw.loadData( 'Module:Color contrast/colors' ) -------------------------------------...")
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
Creates one of three usages related to {{Episode table}} with the parameters defined in the documentation of the template:
-- 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)localcell=mw.html.create('th')-- Cellcell:attr('scope','col'):css('background',backgroundor'#CCCCFF'):css('width',width~=''andwidth..'%'ornil):wikitext(text)-- Referenceifreferencethencell:wikitext(" "..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('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')localblack_cr=contrast_ratio{args[2],'black',['error']=0}localwhite_cr=contrast_ratio{'white',args[2],['error']=0}localdisplaytext=(notargs.nopartand'Part 'or'')..(args[1]or'')row:tag('td'):attr('colspan',13):css('text-align','center'):css('background-color',args[2]):css('color',black_cr>white_crand'black'or'white'):wikitext("'''"..frame:expandTemplate({title='Visible anchor',args={displaytext}}).."'''"..(args.ror''))returntostring(row)endfunctionEpisodeTable.new(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-- Create episode tablelocalroot=mw.html.create('table')root:addClass('wikitable'):addClass('plainrowheaders'):addClass('wikiepisodetable'):css('width',args.total_widthandstring.gsub(args.total_width,'%%','')..'%'or'100%')-- Captionifargs.captionthenroot:tag('caption'):wikitext(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 rowlocalmainRow=root:tag('tr')mainRow:css('color',backgroundand(black_cr>white_crand'black'or'white')or'black'):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 />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.releasedand'release'or'air')..' date'},{'altdate','AltDate',''},{'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'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))endend-- Episodesroot:node(args.episodes)endreturntostring(root)..categoriesend---------------------------------------------------------------------------------- Exports--------------------------------------------------------------------------------localp={}functionp.main(frame)localargs=require('Module:Arguments').getArgs(frame,{removeBlanks=false,wrappers='Template:Episode table'})returnEpisodeTable.new(args)endfunctionp.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