Module:Infobox/AHSW

local Infobox = {}

-- Modules and functions used inside this Module local HF = require('Module:HF') local CH = require('Module:Category handler').main local L = require('Module:List') local Icon = require('Module:Icon')._icon local getArgs = require('Module:Arguments').getArgs local imdb_title = require('Module:IMDb')._imdb_title local LF = require('Module:Infobox/links') local language = mw.language.new('en')

-- Data tables, which have to be parsed locally (ie. can't have a "data." prefix) local data = mw.loadData( 'Module:HF/data' ) local SL = data.SeasonLinks local SC = data.StoryCategories local SN = data.StoryNames local CN = data.Categories

-- Functions called from InfoboxBuilder, and must be local Infobox.IMDBname = require('Module:IMDb').IMDBname Infobox.formatDate = HF.formatDate Infobox.list = HF.list

function Infobox.explode( sep, text ) local sep, fields = sep or "::", {} local pattern = string.format('([^%s]+)', sep) text:gsub(pattern, function(c) fields[#fields+1] = c end) return fields end

function Infobox.definition( frame ) local args = getArgs(frame, { trim = true, removeBlanks = true }) return Infobox._definition( args ) end

function Infobox._definition( field ) if not HF.isempty(field['CommonName']) then return string.format('%s; %s', field['CommonName'], field['Value']) else return field['Value'] end end

function Infobox.character_footer( frame ) -- Called by    local args = getArgs(frame, { trim = true, removeBlanks = true }) return Infobox._character_footer( args ) end

function Infobox._character_footer( field ) -- Called by    local cat = {} local links = { class = 'hwrap plainlinks' } local _SK = '' local maincharacter = false local suppcharacter = false if not HF.isempty(field['MTO']) then maincharacter = true end if not HF.isempty(field['Episodes']) and HF.episodeCount( field['Episodes'] ) > 1 then suppcharacter = true end if not HF.isempty(field['SORTKEY']) then _SK = '|' .. field['SORTKEY'] end if field['CATS'] then local explicitcats = HF.explode(';', field['CATS']) for i,expcat in pairs(explicitcats) do           expcat = HF.trim(expcat) if string.match( expcat, 'S([%d%u%.]+)_(%d+)' ) then local ms, mso = string.match( expcat, 'S([%d%u%.]+)_(%d+)' ) table.insert( cat,                    string.format( '%s', SC[ms], mso )                ) maincharacter = true end if CN[expcat] then table.insert( cat,                    string.format( '%s:%s', 'Category', CN[expcat] )                ) end end end

if not HF.isempty(field['Story']) and HF.isempty(field['NOCAT']) then table.insert( cat, string.format('%s:%s%s', 'Category', 'Characters', _SK )) local stories = HF.explode(';', field['Story']) for i,story in pairs(stories) do           story = HF.trim(story) if SC[story] then _SC = SC[story] table.insert( links,                    string.format('%s Characters', _SC, story)                 ) table.insert( cat, string.format('%s%s', _SC, _SK) ) table.insert( cat, string.format('%s/Characters%s', _SC, _SK) ) if (maincharacter and not HF.isempty(field['MTO'])) then table.insert( cat,                        string.format( '%s', _SC, field['MTO'] )                   ) elseif suppcharacter and not maincharacter then table.insert( cat,                       string.format( '%s', _SC, HF.episodeCount(field['Episodes']) )                   ) end end end elseif not HF.isempty(field['Story']) then local stories = HF.explode(';', field['Story']) for i,story in pairs(stories) do           story = HF.trim(story) if SC[story] then table.insert( links,                    string.format( '%s Characters', SC[story], story )               ) end end else table.insert( links, 'Characters' ) end

return L.makeList( 'horizontal', links ) .. CH{main = table.concat( cat )} end

function Infobox.episode_footer( frame ) -- Called by    local args = getArgs(frame, { trim = true, removeBlanks = true }) return Infobox._episode_footer( args ) end

function Infobox._episode_footer( field )-- Called by 	local cat = {} local links = { class = 'hwrap plainlinks' } local _SK = '' if not HF.isempty(field['SORTKEY']) then _SK = '|' .. field['SORTKEY'] end if field['Story'] then table.insert( cat, '' ) local story = SN[field['Story']] local _SC = SC[story] or '' if not HF.isempty(field['IMDb']) then table.insert( links, imdb_title{id = field['IMDb'], title='IMDb'} ) end if SL[story] then for i, link in ipairs( HF.explode(';', SL[story]) ) do 		       table.insert( links, link ) end table.insert( cat, .._SC.._SK.. ) table.insert( cat, .._SC..'/Episodes'.._SK.. ) table.insert( cat, ..field['Episode'].. ) end else table.insert( links, string.format('%s','Category','Episodes','Episodes') ) end return L.makeList( 'horizontal', links ) .. CH{main = table.concat( cat )} end

function Infobox.cast_footer( frame ) -- Called by    local args = getArgs(frame, { trim = true, removeBlanks = true }) return Infobox._cast_footer( args ) end

function Infobox._cast_footer( field ) -- Called by 	local cat = {} local links = { class = 'hwrap plainlinks' } local _SK = '' if not HF.isempty(field['SORTKEY']) then _SK = '|' .. field['SORTKEY'] end if HF.isempty(field['NOCAT']) then table.insert( cat, string.format('%s:%s%s','Category','Cast',_SK) ) if not HF.isempty(field['S1']) then table.insert( cat, string.format('%s/Cast%s',SC['Murder House'],_SK) ) end if not HF.isempty(field['S2']) then table.insert( cat, string.format('%s/Cast%s',SC['Asylum'],_SK) ) end if not HF.isempty(field['S3']) then table.insert( cat, string.format('%s/Cast%s',SC['Coven'],_SK) ) end if not HF.isempty(field['S4']) then table.insert( cat, string.format('%s/Cast%s',SC['Freak Show'],_SK) ) end if not HF.isempty(field['S5']) then table.insert( cat, string.format('%s/Cast%s',SC['Hotel'],_SK) ) end if not HF.isempty(field['S6.1']) then table.insert( cat, string.format('%s/Cast%s',SC['6.1'],_SK) ) end end table.insert( links, string.format('%s','Category','Cast','Cast') ) if not HF.isempty(field['Wikipedia']) then table.insert( links, LF._wikipedia( { field['Wikipedia'] } ) ) end if not HF.isempty(field['IMDb']) then table.insert( links, LF._imdbname( { field['IMDb'] } ) ) end if not HF.isempty(field['Facebook']) then table.insert( links, LF._facebook( { field['Facebook'] } ) ) end if not HF.isempty(field['FacebookPage']) then table.insert( links, LF._facebook( { pageid = field['FacebookPage'] } ) ) end if not HF.isempty(field['Twitter']) then table.insert( links, LF._twitter( { field['Twitter'] } ) ) end --	 if not HF.isempty(field.Tumblr) then table.insert( links, LF._tumblr( { id = field.Tumblr } ) ) end --	 if not HF.isempty(field.Instagram) then table.insert( links, LF._instagram( { id = field.Instagram } ) ) end return L.makeList( 'horizontal', links ) .. CH{main = table.concat( cat )} end

function Infobox.location_footer( frame ) -- Called by    local args = getArgs(frame, { trim = true, removeBlanks = true }) return Infobox._location_footer( args ) end

function Infobox._location_footer( field ) -- Called by 	local cat = {} local links = {} local _SK = '' if not HF.isempty(field['SORTKEY']) then _SK = '|' .. field['SORTKEY'] end if HF.isempty(field['NOCAT']) and not HF.isempty(field['Story']) then local stories = HF.explode(';', field['Story']) for i,story in pairs(stories) do	   	    table.insert( cat, '' ) if SC[story] then _SC = SC[story] table.insert( links, ''..story..' Locations ' ) table.insert( cat, .._SC.._SK.. ) table.insert( cat, .._SC..'/Locations'.._SK.. ) end end elseif HF.isempty(field['NOCAT']) and HF.isempty(field['Story']) then table.insert( links, 'Locations ' ) table.insert( cat, '' ) else table.insert( links, 'Locations ' ) end return table.concat(links) .. CH{main = table.concat( cat )} end

function Infobox.mini_footer( frame ) local args = getArgs( frame ) return Infobox._mini_footer( args ) end

-- Called by and function Infobox._mini_footer( field, vars ) local links = {} if not HF.isempty(field['Story']) then local stories = HF.explode(';', field['Story']) for i,story in pairs(stories) do	      if SC[story] then _SC = SC[story] table.insert( links, ''..story..' ' ) end end end return table.concat(links) end

-- Called by function Infobox.charactermini_categorize( frame ) local args = getArgs( frame ) return Infobox._charactermini_categorize( args ) end

function Infobox._charactermini_categorize( args ) local cat = {} --	assert( SN[args.story], "The value for story is invalid.") local _SC = SC[SN[args['story']]] local _SK = '' if not HF.isempty(args['sortkey']) then _SK = '|' .. args['sortkey'] end table.insert( cat, '' ) if _SC then table.insert( cat, .._SC.._SK.. ) table.insert( cat, .._SC..'/Characters'.._SK.. ) end local EC = HF.episodeCount(args['appearances']) or 1 if not HF.isempty(args['appearances']) and EC > 2 then local EC = HF.episodeCount(args['appearances']) table.insert( cat, ..EC.. ) end if not HF.isempty(args['categories']) then for i, catname in ipairs( HF.explode(';', args['categories']) ) do			if CN[catname] then table.insert( cat, '' ) end end end table.insert( cat, '' ) return CH{main = table.concat( cat )} end

-- Called by function Infobox.locationmini_categorize( frame ) local args = getArgs( frame ) return Infobox._locationmini_categorize( args ) end

function Infobox._locationmini_categorize( args ) local cat = {} local _SC = SC[SN[args['story']]] local _SK = '' if not HF.isempty(args['sortkey']) then _SK = '|' .. args['sortkey'] end table.insert( cat, '' ) if _SC then table.insert( cat, .._SC.._SK.. ) table.insert( cat, .._SC..'/Locations'.._SK.. ) end if not HF.isempty(args['categories']) then for i, catname in ipairs( HF.explode(';', args['categories']) ) do			if CN[catname] then table.insert( cat, '' ) end end end table.insert( cat, '' ) return CH{main = table.concat( cat )} end

return Infobox