American Horror Story Wiki
Advertisement
American Horror Story Wiki


Documentation


-- @module Infobox
-- @class deprecated
-- @release archive
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 CharCat = data.CharacterCategories
local EpisCat = data.EpisodeCategories
local CastCat = data.CastCategories
local LocaCat = data.LocationCategories
local CN = data.Categories

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

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 {{Infobox/Character}}
    local args = getArgs(frame, { trim = true, removeBlanks = true })
	return Infobox._character_footer( args )
end

function Infobox._character_footer( field ) -- Called by {{Infobox character}}
    local cat = {}
    local links = { class = 'hwrap plainlinks' }
    local _SK = field['SORTKEY'] and ('|' .. field['SORTKEY']) or ''
    local maincharacter = false
    local suppcharacter = false
   -- TODO: Define Main Characters only in HF/data
    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['Story']) and HF.isempty(field['NOCAT']) then
        table.insert( cat, HF.Category('Characters', field['SORTKEY']))
        local stories = HF.explode(';', HF.trim(field['Story']))
        for i,story in pairs(stories) do
            story = HF.trim(story)
            if SC[story] then
                _SC = SC[story]
   -- TODO: Fix links for multistory characters
                table.insert( links, 
                    HF.LinkToCategory( CharCat[story], ("%s Characters"):format(story) )
                )
                table.insert( cat, HF.Category( SN[story], field['SORTKEY'] ) )
                table.insert( cat, HF.Category( CharCat[story], field['SORTKEY'] ) )
   -- TODO: Define Main Characters only in HF/data
                if (maincharacter and not HF.isempty(field['MTO'])) then
                    table.insert( cat, 
                        HF.Category( CharCat[story] and CharCat[story] .. '/Main', field['MTO'] )
                    )
                elseif suppcharacter and not maincharacter then
                    table.insert( cat,
                        HF.Category( CharCat[story] and CharCat[story] .. '/Supporting', 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, 
                    HF.LinkToCategory( CharCat[story], ('%s Characters'):format(story) )
                )
            end
        end
    else
        table.insert( links, HF.LinkToCategory('Characters', 'Characters') )
    end
    
    if field['CATS'] then
        local explicitcats = HF.explode(';', field['CATS'])
        for i,expcat in pairs(explicitcats) do
            expcat = mw.text.trim(expcat)
   -- TODO: Define Main Characters only in HF/data
            if string.match( expcat , 'S([%d%u%.]+)_(%d+)' ) then
                local ms, mso = string.match( expcat , 'S([%d%u%.]+)_(%d+)' )
                table.insert( cat, 
                    HF.Category( CharCat[ms] and CharCat[ms]..'/Main' or nil, mso or '' )
                )
                maincharacter = true
            end
            if CN[expcat] then 
                table.insert( cat, HF.Category( CN[expcat] ) )
            end
        end
    end

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

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

function Infobox._episode_footer( field )-- Called by {{Infobox episode}}
	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, HF.Category( SN[story], field['SORTKEY'] ) )
		    table.insert( cat, HF.Category( EpisCat[story], field['SORTKEY'] ) )
		    table.insert( cat, HF.Category( EpisCat[story] and EpisCat[story]..'/By Broadcast', 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 {{Infobox/Cast}}
    local args = getArgs(frame, { trim = true, removeBlanks = true })
	return Infobox._cast_footer( args )
end

function Infobox._cast_footer( field ) -- Called by {{Infobox cast|nocat=nocat}}
	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']) or field['NOCAT'] == "No") then
		table.insert( cat, HF.Category('Cast', field['SORTKEY']) )
		if not HF.isempty(field['S1']) then table.insert( cat, HF.Category( CastCat['Murder House'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S2']) then table.insert( cat, HF.Category( CastCat['Asylum'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S3']) then table.insert( cat, HF.Category( CastCat['Coven'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S4']) then table.insert( cat, HF.Category( CastCat['Freak Show'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S5']) then table.insert( cat, HF.Category( CastCat['Hotel'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S6']) then table.insert( cat, HF.Category( CastCat['Roanoke'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S7']) then table.insert( cat, HF.Category( CastCat['Cult'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S8']) then table.insert( cat, HF.Category( CastCat['Apocalypse'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S9']) then table.insert( cat, HF.Category( CastCat['1984'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S10']) then table.insert( cat, HF.Category( CastCat['Double Feature'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S11']) then table.insert( cat, HF.Category( CastCat['NYC'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['S12']) then table.insert( cat, HF.Category( CastCat['Delicate'], field['SORTKEY'] ) ) end
		if not HF.isempty(field['SS']) then table.insert( cat, HF.Category( CastCat['American Horror Stories'], field['SORTKEY'] ) ) end
	end
	table.insert( links, HF.LinkToCategory( '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 {{Infobox/Location}}
    local args = getArgs(frame, { trim = true, removeBlanks = true })
	return Infobox._location_footer( args )
end

function Infobox._location_footer( field ) -- Called by {{Infobox location}}
	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, HF.LinkToCategory( LocaCat[story], story..' Locations' ) )
	    	        table.insert( cat, HF.Category( SN[story] and story, field['SORTKEY'] ) )
	    	        table.insert( cat, HF.Category( LocaCat[story], field['SORTKEY'] ) )
	    	    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 {{Infobox character/mini}} and {{Infobox location/mini}}
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, HF.LinkToCategory( SN[story], SN[story] )..' ' )
	       end
	   end
	end
	return table.concat(links)
end

-- Called by {{R from character mini}}
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, HF.Category( SN[args['story']], args['sortkey'] ) )
		table.insert( cat, HF.Category( CharCat[SN[args['story']]], args['sortkey'] ) )
	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, HF.Category( CharCat[SN[args['story']]] and CharCat[SN[args['story']]]..'/Supporting', 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 {{R from location mini}}
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, HF.Category( SN[args['story']], args['sortkey']) )
		table.insert( cat, HF.Category( LocaCat[SN[args['story']]], args['sortkey'] ) )
	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
Advertisement