Marvel Database
Advertisement
Marvel Database

Documentation for this module may be created at Module:Members/doc

local p = {}
local h = require("Module:HF")
local module_reality = require("Module:Reality")
local standard = require("Module:StandardizedName")
local getArgs = require('Dev:Arguments').getArgs

--------------------------------------------------------------------------------
-- used in Template:Member of
function p.main(frame)
	local pagename = mw.title.getCurrentTitle().text
	local args = getArgs(frame)
	local team = args[1]
	local team_name = args[2]
	local reality_info1
	local name2

	_, reality_info1 = module_reality.lua_get_name_and_reality(pagename)
	name2, _ = module_reality.lua_get_name_and_reality(team)
	
	if h.isempty(team_name)
		then 
			if string.find(team, '(Earth', 1, true) ~= nil
				then team_name = name2
				else team_name = team
			end
	end
	
	if string.find(team, '(Earth', 1, true) == nil and reality_info1 ~= ''
		then team = team..' ('..reality_info1.name..')'
	end

	return h.Link(team, team_name)..h.Category(team..'/Members')
end


--------------------------------------------------------------------------------
-- used in Template:Members Category
function p.members_category(frame)
	local design = require('Module:Design')
	local baseText = mw.title.getCurrentTitle().baseText
	local subpageText = mw.title.getCurrentTitle().subpageText
	local page_type = require('Module:PageType').get_page_type(baseText)
	local name
	local reality_info
	local category = ''
	local message = ''
	local output = '{{DEFAULTSORT:'..standard.name_for_sorting({baseText})..subpageText..'|noerror}}'
	
	name, reality_info = module_reality.lua_get_name_and_reality(baseText)

	if subpageText == 'Members'
		then
			message = design.messagebox({'Members of the '..h.Link(baseText, baseText)..'.'})
			category = h.Category(name..' members')
			if reality_info ~= ''
				then 
					if page_type == 'Organization'
						then category = category..h.Category(reality_info.name..'/Organizations', sort_name)
						else category = category..h.Category(reality_info.name..'/Teams', sort_name)
					end
			end
			output = output..message..category
		elseif string.find(baseText, ' members') ~= nil
			then
				message = string.gsub(baseText, ' members', '')
				message = design.messagebox({'Members of the '..h.Link(message)..' from various realities.'})
				category = h.Category('Member Lists')
				output = output..message..category
	end
	
	return frame:preprocess(output)
end

return p