Marvel Database

Due to recent developments, please be aware that the use of large language model or generative AIs in writing article content is strictly forbidden. This caveat has now been added to the Manual of Style and Blocking Policy.

READ MORE

Marvel Database
Advertisement

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

local p = {}
local h = require("Module:HF")


--------------------------------------------------------------------------------------------------
-- returns namespace of the page
function p.get_namespace(pagename)
	local title
	local output = ''
	
	if not h.isempty(pagename)
		then
			pagename = string.gsub(pagename,'&','&')
			pagename = string.gsub(pagename,''',"'") 
			title = mw.title.new(pagename)
			if title.namespace == 0
				then 
					if title.exists
						then return "Main"
					end
				else return title.nsText
			end
			if title.exists 
				then return "Main"
				elseif h.exists('File:'..pagename)
					then return "File"
					elseif h.exists('Category:'..pagename)
						then return "Category"
						else return ''
			end
	end
	title = nil
	return output
end


--------------------------------------------------------------------------------------------------
-- returns type of page based on the name of its main template (workd only for templates in 'Marvel Database' namespace.
function p.get_page_type(pagename)
	local namespace = p.get_namespace(pagename)
	local content = ''
	local s_match = '{{Marvel Database:(.-) Template'
	local output = namespace

	if namespace == 'Main'
		then
			content = h.get_content(pagename)
			if not h.isempty(content)
				then 
					output = string.match(content, s_match) 
					if not h.isempty(output)
						then 
							output = mw.text.trim(output)
						    if output == 'Handbook'
								then output = 'Comic'
							end
						else output = 'Unknown'
					end
			end
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
-- returns 'true' if page is a disambiguation
function p.disambiguation(pagename)
	local content = ''
	local i
	local j
	local k
	local output = false
	local n = 0
	
	if h.exists(pagename)
		then
			content = h.get_content(pagename)
			i = string.find(content, 'DisambiguationFull')
			j = string.find(content, 'Disambiguation')
			k = string.find(content, 'Disambig')
			if i ~= nil
				then 
					output = true
					n = 1
				elseif j ~= nil
					then output = true
						n = 2
				elseif k ~= nil
					then 
						output = true
						n = 3
			end
	end
	
	return output, n
end


--------------------------------------------------------------------------------------------------
-- returns main page of a disambiguation
function p.get_disambiguation_main(pagename)
	local content = ''
	local i
	local j
	local output = ''
	
	i, j = p.disambiguation(pagename)
	
	if i
		then
			content = h.get_content(pagename)
			if j == 1 -- Template:DisambiguationFull
				then output = h.get_field_value(content, 'main')
				elseif j == 2 -- Template:Disambiguation
					then output = h.get_field_value(content, 'Main Character')
					elseif j == 3 -- Template:Disambig
						then output = h.get_field_value(content, 'MainPage')
			end
			output = h.break_link(output, 1)
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
--Check if "page" is redirect or not
function p.redirect(page)
	local output = false
	
	if not h.isempty(page)
		then output = mw.title.new(page).isRedirect
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
--return target of redirect
function p.get_redirect_target(page)
	local content = ''
	local output = ''
	
	if not h.isempty(page) and p.redirect(page)
		then 
			content = h.get_content(page)
			output = mw.ustring.gsub(content, "^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)%]%]", "%1") or
				mw.ustring.gsub(content,"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)|[^%[%]]-%]%]", "%1")
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
--Check if "page" is handbook or not
---- used in Module:Reality Template
function p.handbook(frame, pagename)
	local standard = require("Module:StandardizedName")
	local getArgs = require('Dev:Arguments').getArgs 
	local args = getArgs(frame)
	local issue_info = standard.lua_get_title_volume_issue(pagename, 'Vol')
	local list_of_handbooks = '{{#dpl:|category = Handbooks|namespace = |mode = userformat|listseparators = ,%PAGE%,@@@}}'
	list_of_handbooks = mw.text.split( frame:preprocess(list_of_handbooks), '@@@' )
	
	return h.in_list(list_of_handbooks, issue_info.noissue)
end

return p
Advertisement