-- This module implements .
require('strict')local yesno = require('Module:Yesno')
---------------------------------------------------------------------------------- CriticalResponse class-- The main class.--------------------------------------------------------------------------------
local CriticalResponse =
function CriticalResponse.cellspan(SeasonEntries, SeasonEntries_ordered, key, cell, multipart) local spanlength = 1 for i = cell+1, #SeasonEntries_ordered do local entry = SeasonEntries[SeasonEntries_ordered[i]] -- Split season, then regular season if entry.startA then if not entry[key..'A'] then spanlength = spanlength + 1 else break end if not entry[key..'B'] then spanlength = spanlength + 1 else break end else if not entry[key] and (not entry.special and multipart) then spanlength = spanlength + 1 else break end end end return spanlengthend
-- Sorting functionfunction CriticalResponse.series_sort(op1, op2) local n1,s1 = string.match(op1,"(%d+)(%a*)") local n2,s2 = string.match(op2,"(%d+)(%a*)") local n1N,n2N = tonumber(n1),tonumber(n2)
if n1N
-- Function to add either text or to cellfunction CriticalResponse.season_cell(text, frame) local cell if string.find(text or , 'table-na', 0, true) ~= nil then local findpipe = string.find(text, ' | ', 0, true) if findpipe ~= nil then cell = CriticalResponse.series_attributes(frame:expandTemplate) else cell = CriticalResponse.series_attributes(frame:expandTemplate) end else cell = mw.html.create('td'):wikitext(text) end return cellend
-- Allow usages of cellsfunction CriticalResponse.series_attributes(infoParam) local entries = local infoCell = mw.html.create('td') local attrMatch = '([%a-]*)="([^"]*)"' while true do local a,b = string.match(infoParam,attrMatch) if a
nil then break end infoCell:attr(a,b) infoParam = string.gsub(infoParam,attrMatch,,1) end
infoParam = string.gsub(infoParam,'%s*|%s*',,1) infoCell:wikitext(infoParam) return infoCellend
function CriticalResponse.new(frame, args) args = args or local initialArticle = args['1'] or local categories = local title = mw.title.getCurrentTitle local hide_rotten_tomatoes = yesno(args.hide_rotten_tomatoes) local hide_metacritic = yesno(args.hide_metacritic) local show_cinemascore = yesno(args.show_cinemascore) local hide_season = yesno(args.hide_season) local series_name = tostring(title):gsub("%s%((.-)%)","")
-- Create critical response table local root = mw.html.create((args.multiseries or not args.series) and 'table' or ) local cellPadding = '0 8px' local basePadding = '0.2em 0.4em' root :addClass('wikitable') :addClass('plainrowheaders') :css('text-align', 'center') -- Remove float if multiple series if not args.multiseries then root:css('float', 'right') root:css('clear', 'right') root:css('margin', '10px') end -- Sortable if args.sortable or args.multiseries then root:addClass('sortable'); end -- Width if args.width then root:css('width', args.width) end
-- Caption if not args.series then local formatted_caption if args.caption then formatted_caption = args.caption elseif args.title and args.multiseries then formatted_caption = 'Critical response of ' .. args.title elseif args.title then formatted_caption = 'Critical response of ' .. args.title .. '' else formatted_caption = 'Critical response of ' .. series_name .. '' end if args.show_caption then -- Visible caption option root:tag('caption'):wikitext(formatted_caption) elseif formatted_caption then -- If a visible caption isn't defined, then default to the screenreader-only caption root:tag('caption'):wikitext(frame:expandTemplate) end end
-- Extract seasons info and place into a 3D array local SeasonEntries = local SeasonCount = 0 for k,v in pairs(args) do local str, num, str2 = string.match(k, '([^%d]*)(%d*)(%a*)') if num ~= then -- Special local special = false if string.sub(str2,1,1)
-- Order table by season number local SeasonEntries_ordered = for k in pairs(SeasonEntries) do table.insert(SeasonEntries_ordered, k) end table.sort(SeasonEntries_ordered,CriticalResponse.series_sort) local firstRow = args.multiseries and or SeasonEntries[SeasonEntries_ordered[1]]
-- Headers do if args.multiseries or not args.series then local headerRow = root:tag('tr') headerRow :css('text-align', 'center') -- Multiple series header if args.multiseries then headerRow:tag('th') :attr('scope', 'col') :css('padding', cellPadding) :wikitext('Title') end -- Season header if not hide_season then headerRow:tag('th') :attr('scope', 'col') :css('min-width', '50px') :css('padding', cellPadding) :addClass('unsortable') :wikitext(args.seriesT or args.seasonT or 'Season') end
-- Rotten Tomatoes header if not hide_rotten_tomatoes then headerRow:tag('th') :attr('scope', 'col') :wikitext('Rotten Tomatoes') end
-- Metacritic header if not hide_metacritic then headerRow:tag('th') :attr('scope', 'col') :wikitext('Metacritic') end -- CinemaScore header if show_cinemascore then headerRow:tag('th') :attr('scope', 'col') :wikitext('CinemaScore') end end end
-- Season rows do if args.multiseries then -- Multi series individual entries if args.multiseries ~= "y" then root:node(args.multiseries) end else -- One row entries, only categorized in the mainspace if SeasonCount
string.byte('A')-1 then k = end -- New season row local seasonRow = (entry['rotten_tomatoes' .. k] or entry['metacritic' .. k] or entry['cinemascore' .. k]) and root:tag('tr') or mw.html.create('tr') -- Series name for group overviews if X
or k
or k
return (args.dontclose and mw.ustring.gsub(tostring(root), "", "") or tostring(root)) .. categoriesend
---------------------------------------------------------------------------------- Exports--------------------------------------------------------------------------------
local p =
function p.main(frame) local args = require('Module:Arguments').getArgs(frame,) return CriticalResponse.new(frame, args)end
return p