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 ) return field['CommonName'] and string.format('%s; %s', field['CommonName'], field['Value']) or field['Value'] 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 = field['SORTKEY'] and ('|' .. field['SORTKEY']) or '' 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 field['CATS'] then local explicitcats = HF.explode(';', field['CATS']) for i,expcat in pairs(explicitcats) do           expcat = mw.text.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] or , mso or )                ) maincharacter = true end if CN[expcat] then table.insert( cat, HF.Category( CN[expcat] ) ) end end end if not HF.isempty(field['Story']) and HF.isempty(field['NOCAT']) then table.insert( cat, HF.Category('Characters', field['SORTKEY'])) 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, HF.LinkToCategory('Characters', '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, HF.Category('Episodes', field['SORTKEY']) ) 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, HF.LinkToCategory('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, HF.Category('Cast', field['SORTKEY']) ) 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']) then table.insert( cat, string.format('%s/Cast%s',SC['Roanoke'],_SK) ) end if not HF.isempty(field['S7']) then table.insert( cat, string.format('%s/Cast%s',SC['Cult'],_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, HF.Category('Locations', field['SORTKEY']) ) 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, HF.LinkToCategory('Locations', 'Locations')..' ' ) table.insert( cat, HF.Category('Locations', field['SORTKEY']) ) else table.insert( links, HF.LinkToCategory('Locations', '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, HF.Category('Characters', args['sortkey']) ) 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, HF.Category(CN[catname], args['sortkey']) ) end end end table.insert( cat, HF.Category('Redirects from character references', args['sortkey']) ) 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, HF.Category('Locations', args['sortkey'])) 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, HF.Category(CN[catname], args['sortkey'])) end end end table.insert( cat, HF.Category('Redirects from location references', args['sortkey'])) return CH{main = table.concat( cat )} end return Infobox