Marvel Wiki
Advertisement
Marvel Wiki
5 135
páginas

A documentação para este módulo pode ser criada em Módulo:NomePadronizado/doc

local p = {}
local h = require("Módulo:HF")
local getArgs = require('Dev:Arguments').getArgs
---- //*** Funções para transformar nomes de páginas de quadrinhos/episódios no formato desejável ***// ----

--------------------------------------------------------------------------------------------------
-- retorna a edição transformada / número do episódio que pode ser usado para classificar em categorias como números, em vez de texto, incluindo edições "ponto de partida" e edições "-1" / "negativas"
function p.lua_padded_edicao(edicao)
	local menos = '5'
	local ponto_de_partida = '00'
	local i = ''
	local j = ''
	local output = ''
	local s1 = ''
	local s2 = ''
	
	if not h.isempty(edicao)
		then
			if edicao == '½'
				then edicao = '0.5'
			end
			
			if string.find(edicao, '%d+: ') ~= nil
				then edicao = string.match(edicao, '(%d+): ')
			end
			
			s1, s2 = string.match( string.lower(edicao), '(%d+)(%l)')--'(%d+)(%D+)')
			if not h.isempty( s2 ) --and s2 ~= '.'
				then edicao = s1..'.'..s2
			end
			
			if string.match(edicao, '^%-*%d', 1) ~= nil --verifique se a edição começa com um número (incluindo números negativos como -1)
				then
					-- -1 edicoes
					j = string.find(edicao,"-",1,true)
					if not h.isempty(j)
						then
							i = string.sub(edicao,2,#edicao)
							j = string.find(i,".",1,true)
							if not h.isempty(j) 
								then menos = 5 - #string.sub(i,1,j-1)
								else menos = 5 - #i
							end
						else
							i = edicao
					end
	
					-- edições de ponto de partida
					j = string.find(i,".",1,true) 
					if not h.isempty(j)
						then
							ponto_de_partida = string.sub(i,j+1,#i)
							if tonumber(ponto_de_partida) == nil
								then ponto_de_partida = '99' -- para edições com letras depois. em vez de apenas números (por exemplo, O Espetacular Homem-Aranha Vol 5 #16.HU)
							end
							ponto_de_partida = string.rep("0", 2-#ponto_de_partida)..ponto_de_partida
							i = string.sub(i,1,j-1)
					end
	
					output = menos..string.rep("0", 6-#i)..i..ponto_de_partida
				else -- edição não é um número
					output = edicao --'999999999'
			end
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
-- returns transformed volume/season number that can be used for sorting in categories as numbers, instead of text
function p.lua_padded_volume(volume)
	local output = ''
	
	if not h.isempty(volume)
		then output = string.rep("0", 6-#volume)..volume
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
-- returns transformed titulo, with replaced characters like ":" or "/" that can be used for names of files (for example, covers)
function p.lua_titulo_para_arquivos(titulo)
	local output = titulo
	
	output = string.gsub(output,'/',' ')
	output = string.gsub(output,':','')
	output = string.gsub(output,'&','&')
	output = string.gsub(output,''',"'") 

	return output
end


--------------------------------------------------------------------------------------------------
-- divida o nome da página dos quadrinhos/episódios em partes - título, volume/temporada, edição/episódio.
---- Também retorna o volume transformado / número da temporada e número da edição / episódio que pode ser usado para classificar as categorias como números, em vez de texto, incluindo edições de "ponto um" e edições "-1"/"negativas"
---- Também retorna o título transformado, com caracteres substituídos como ":" ou "/" que podem ser usados para nomes de arquivos (por exemplo, capas)
function p.lua_get_titulo_volume_edicao(pagename, pagetype)
	local titulo = ''
	local volume = ''
	local edicao = ''
	local padded_edicao = ''
	local padded_volume = ''
	local titulo_para_arquivos = ''
	local remainder_edicao = ''
	local clean_edicao = ''
	local link_parte1 = ''
	local link_parte2 = ''
	local design = require("Módulo:Design")
	local j
	local k
	local s
	
	if h.isempty(pagetype)
		then pagetype = 'Vol'
	end
	
	j,k = string.find(pagename, ' '..pagetype..' %d+ ')
	if not h.isempty(j)
		then
			titulo = string.sub(pagename, 1, j-1)
			edicao = string.gsub(string.sub(pagename, k+1, #pagename), '#', '')
			j,k,volume = string.find(pagename, ' '..pagetype..' (%d+) ')
		else
			j,k = string.find(pagename, ' #')
			if h.isempty(j)
				then
					j,k = string.find(pagename, ' '..pagetype..' %d+')
					if not h.isempty(j)
						then
							titulo = string.sub(pagename, 1, j-1)
							volume = string.sub(pagename, j+#pagetype+2, k)
						else return ''
					end
				else
					titulo = string.sub(pagename, 1, j-1)
					edicao = string.sub(pagename, k+1, #pagename)
					volume = '1'
			end
	end
	
	if not h.isempty(edicao) and tonumber(edicao) == nil
		then clean_edicao, remainder_edicao = string.match(edicao, '(%d+)(%D+)')
	end
	
	if not h.isempty(titulo)
		then
			if not h.isempty(edicao)
				then
					if pagetype == 'Temporada'
						then link_parte2 = 'E'..string.rep('0', 2-#edicao)..edicao
						else
							link_parte1, link_parte2 = string.match(edicao, '(%d+): (.+)')
							if h.isempty(link_parte2)
								then link_parte2 = ' #'..edicao
								else link_parte2 = design.span(': '..link_parte2).italic
							end
					end
					link_parte1 = titulo..' '..pagetype..' '..volume..' '..edicao
				else
					link_parte1 = titulo..' '..pagetype..' '..volume
			end
			if pagetype == 'Temporada'
				then
					s = string.gsub(titulo, ' %([Ss]érie% de TV)', '')
					s = string.gsub(s, ' %([Ss]érie [Aa]nimada%)', '')
					link_parte2 = design.span(s).italic..' S'..volume..link_parte2
				else
					if volume == '1'
						then link_parte2 = design.span(titulo).italic..link_parte2
						else link_parte2 = design.span(titulo).italic..' ('..pagetype..'. '..volume..')'..link_parte2
					end
			end
	end

	padded_volume = p.lua_padded_volume(volume)
	padded_edicao = p.lua_padded_edicao(edicao)
	titulo_para_arquivos = p.lua_titulo_para_arquivos(titulo)
	return {  ['titulo'] = titulo, 
			  ['volume'] = volume,
			  ['Edição'] = edicao,
			  ['clean_edicao'] = clean_edicao or '',
			  ['remainder_edicao'] = remainder_edicao or '',
			  ['padded_volume'] = padded_volume,
			  ['padded_edicao'] = padded_edicao,
			  ['filename'] = {
				  ['titulo'] = titulo_para_arquivos,
				  ['semedicao'] = titulo_para_arquivos..' '..pagetype..' '..volume,
				  ['all'] = titulo_para_arquivos..' '..pagetype..' '..volume..' '..edicao,
			  },
			  ['classificacarnome'] = {
				  ['titulo'] = p.lua_remove_the(titulo),
				  ['semedicao'] = p.lua_remove_the(titulo)..' '..pagetype..' '..padded_volume,
				  ['all'] = p.lua_remove_the(titulo)..' '..pagetype..' '..padded_volume..' '.. padded_edicao,
			  },
			  ['link'] = {
				  ['part1'] = link_parte1,
				  ['part2'] = link_parte2,
				  ['all'] = h.Link(link_parte1, link_parte2),
			  },
			  ['semedicao'] = titulo..' '..pagetype..' '..volume,
			  ['all'] = titulo..' '..pagetype..' '..volume..' '..edicao,
			}
end

--------------------------------------------------------------------------------------------------
-- removes "The " from the start of pagename
function p.lua_remove_the(pagename)
	if not h.isempty(pagename) and string.lower( string.sub(pagename, 1, 4) ) == 'the '
		then pagename = string.sub(pagename, 5, #pagename)
	end
	return pagename
end


function p.remove_the(frame)
	local args = getArgs(frame)
	return p.lua_remove_the(args[1])
end


--------------------------------------------------------------------------------------------------
-- padronização automática de nomes de quadrinhos
function p.lua_nome_padronizado_de_quadrinhos(pagename)
	local info = {}
	local output = pagename

	if not h.isempty(pagename)
		then 
			info = p.lua_get_titulo_volume_edicao(pagename, 'Vol')
			if not h.isempty(info.titulo)
				then output = info.all
			end
	end
	
	return output
end


function p.nome_padronizado_de_quadrinhos(frame)
	local args = getArgs(frame)
	return p.lua_nome_padronizado_de_quadrinhos(args[1])
end


--------------------------------------------------------------------------------------------------
-- automatic standardization of episodes names
function p.lua_standardized_episode_name(pagename)
	local info = {}
	local output = pagename

	if not h.isempty(pagename)
		then 
			info = p.lua_get_titulo_volume_edicao(pagename, 'Temporada')
			if not h.isempty(info.titulo)
				then output = info.all
			end
	end
	
	return output
end


function p.standardized_episode_name(frame)
	local args = getArgs(frame)
	return p.lua_standardized_episode_name(args[1])
end


--------------------------------------------------------------------------------------------------
-- returns link after standardization of its name
function p.lua_link_padronizado(pagename, pagetype, text)
	local design = require("Módulo:Design")
	local link = ''
	local edicao = ''
	local info = {}
	local output = ''
	
	if not h.isempty(pagename)
		then
			if string.find(pagename, '%]%].+') ~= nil
				then return pagename
				else pagename = h.break_link(pagename, 1)
			end
			if h.isempty(pagetype)
				then pagetype = require("Módulo:TipoDePágina").get_tipo_de_pagina(pagename)
			end
			if not h.isempty(pagetype)
				then
					if pagetype == 'Quadrinho' or pagetype == 'Volume' or pagetype == 'Episódio' 
						then
							if pagetype == 'Quadrinho' or pagetype == 'Volume'
								then pagetype = 'Vol'
								else pagetype = 'Temporada'
							end

							info = p.lua_get_titulo_volume_edicao(pagename, pagetype)
							if not h.isempty(text)
								then output = h.Link(info.link.part1, text)
								else output = info.link.all
							end
						elseif pagetype == 'Film' or pagetype == 'Video Game' or pagetype == 'Series' or pagetype == 'Novel'
							then
								link = pagename
								text = string.gsub(pagename, ' %(.+%)', '')
								output = h.Link(link, design.span(text).italic)
						else output = h.Link(pagename)
					end
				else output = h.Link(pagename)
			end
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
function p.comics_link(frame)
	local args = getArgs(frame)
	local arg1 = args[1]
	local output
	
	if not h.isempty(arg1)
		then
			if h.in_list({'-', '--', '---', '—', '—'}, arg1)
				then output = '—'
				else output = p.lua_link_padronizado(arg1, 'Quadrinho', args[2])
			end
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
-- returns name transformed into format for sorting 
---- removes "The" from the begining
---- for comics/episodes changes volume/season and edicao/episode into numbers, instead of text
function p.lua_nome_padronizado_para_classificacao(pagename, pagetype)
	local info = {}
	local output = pagename

	if not h.isempty(pagename) and not h.isempty(pagetype)
		then
			if pagetype == 'Quadrinho' or pagetype == 'Episódio'
				then
					if pagetype == 'Quadrinho'
						then pagetype = 'Vol'
						else pagetype = 'Temporada'
					end
					info = p.lua_get_titulo_volume_edicao(pagename,pagetype)
					if not h.isempty(info.titulo)
						then output = info.classificarnome.all
					end
				elseif pagetype == 'Filme' or pagetype == 'Vídeo Game' or pagetype == 'Novel'
					then output = p.lua_remove_the(pagename)
			end
	end
	
	return output
end


function p.nome_de_quadrinhos_para_classificacao(frame)
	local args = getArgs(frame)
	return p.lua_nome_padronizado_para_classificacao(args[1], 'Quadrinho')
end


--------------------------------------------------------------------------------------------------
-- função para classificar personagens, equipes, itens, etc. por número de realidade
function p.nome_por_classificacao(frame)
	local args = getArgs(frame)
	local modulo_realidade = require('Módulo:Realidade')
	local output = p.lua_remove_the(args[1])
	
	return modulo_realidade.classificar_pela_realidade({output})
end

--------------------------------------------------------------------------------------------------
function p.lua_get_parte(pagename,pagetype,parte)
	local output = ''
	local info = {}
	
	if not h.isempty(pagename) and not h.isempty(pagetype)
		then 
			if pagetype == 'Quadrinho' or pagetype == 'Episódio'
				then
					if pagetype == 'Quadrinho'
						then pagetype = 'Vol'
						else pagetype = 'Temporada'
					end
					
					info = p.lua_get_titulo_volume_edicao(pagename,pagetype)
					if not h.isempty(titulo)
						then 
							if parte == 'Título'
								then output = info.titulo
								elseif parte == 'Volume'
									then output = info.volume
									elseif parte == 'Edição'
										then output = info.edicao
							end
					end
			end
	end
	
	return output
end


function p.get_parte(frame)
	local args = getArgs(frame)
	return p.lua_get_parte(args[1], args[2], args[3])
end


function p.get_titulo_e_volume(frame)
	local args = getArgs(frame)
	local pagename = args[1]
	local info = {}
	local output = ''
	
	if not h.isempty(pagename)
		then 
			info = p.lua_get_titulo_volume_edicao(pagename, 'Vol')
			output = info.titulo .. ' Vol ' .. info.volume
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
function p.lua_cid(pagename)
	local m_date = require("Módulo:Date")
	local design = require("Módulo:Design")
	local data_de_lancamento = ''
	local month = ''
	local year = ''
	local page_content = ''
	local info
	local link
	local div = mw.html.create( 'div' ):attr( 'align', 'center' ):done()
	local output = ''
	
	if not h.isempty(pagename)
		then
			output = p.lua_link_padronizado(pagename, 'Quadrinho')
			output = design.span(output).bold
			page_content = h.get_content(p.lua_get_titulo_volume_edicao(pagename, 'Vol').all)
			data_de_lancamento = h.get_field_value(page_content, 'DataDeLançamento')
			if not h.isempty(data_de_lancamento)
				then
					info = m_date.lua_get_release_date_info(release_date)
					link = h.Link(info.week.text, info.no_day)
				else
					year = h.get_field_value(page_content, 'Mês')
					month = h.get_field_value(page_content, 'Ano')
					info = m_date.lua_get_publication_date_info(year, month, false)
					link = string.gsub(info.link, '%]%], %[%[:Categoria:%d+|', ', ')
			end

			if not h.isempty(link)
				then output = output..'<br>('..link..')'
			end

			output = tostring( div:wikitext(output) )
	end

	return output
end


function p.cid(frame)
	local args = getArgs(frame)
	return p.lua_cid(args[1])
end

--------------------------------------------------------------------------------------------------
-- substitui "#" por "Vol" ou "Temporada"
function p.lua_substitua_o_sinal_numerico(pagename, pagetype)
	local output = ''
	
	if not h.isempty(pagename) 
		then
			if h.isempty(pagetype) 
				then pagetype = ''
			end
			
			if string.find(pagename, '#') ~= nil 
				then
					if string.find(pagename, ' Vol ') ~= nil or string.find(pagename, ' Temporada ') ~= nil
						then output = string.gsub(pagename, '#', '')
						elseif pagetype == 'Quadrinho' or h.exists( string.gsub(pagename, '#', 'Vol 1 ') )
							then output = string.gsub(pagename, '#', 'Vol 1 ')
						elseif pagetype == 'Episódio' or h.exists( string.gsub(pagename, '#', 'Temporada 1 ') )
							then output = string.gsub(pagename, '#', 'Temporada 1 ')
					end
				else
					output = pagename
			end
	end
	
	return output		
end

--------------------------------------------------------------------------------------------------
function p.lua_get_data_de_lancamento(pagename, pagetype)
	local m_date = require("Módulo:Date")
	local page_content = ''
	local data_de_lancamento = ''
	local ano = ''
	local mes = ''
	local dia = ''
	local output = ''

	if not h.isempty(pagename)
		then
			pagename = p.lua_substitua_o_sinal_numerico(pagename, pagetype)
			if h.isempty(pagetype)
				then pagetype = require("Módulo:TipoDePágina").get_tipo_de_pagina(pagename)
			end
			page_content = h.get_content(pagename)
			if page_content ~= ''
				then
					if pagetype == 'Quadrinho'
						then
							data_de_lancamento = h.get_field_value(page_content, 'DataDeLançamento')
							if not h.isempty(data_de_lancamento)
								then
									info = m_date.lua_get_release_date_info(data_de_lancamento)
									output = h.Link(info.week.text, info.sem_dia)
								else
									mes = h.get_field_value(page_content, 'Mês')
									ano = h.get_field_value(page_content, 'Ano')
									info = m_date.lua_get_publication_date_info(ano, mes, false)
									output = string.gsub(info.link, '%]%], %[%[:Categoria:%d+|', ', ')
							end
						elseif pagetype == 'Episódio'
							then 
								ano = h.get_field_value(page_content, 'Ano')
								mes = h.get_field_value(page_content, 'Mês')
								dia = h.get_field_value(page_content, 'Dia')
								if not h.isempty(ano) and not h.isempty(mes) and not h.isempty(dia)
									then 
										mes = m_date.get_month_name({mes})
										output = h.LinkToCategory(ano..', '..mes, mes..' '..dia..', '..ano)
								end
						elseif pagetype == 'Filme' or pagetype == 'Vídeo Game' or pagetype == 'Novel'
							then output = h.get_field_value(page_content, 'Data de Lançamento')
					end
			end
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
function p.lua_get_link_e_data_de_lancamento(pagename, pagetype, text, data_de_lancamento)
	local output = ''
	
	if not h.isempty(pagename)
		then
			pagename = p.lua_substitua_o_sinal_numerico(pagename, pagetype)
			if h.isempty(pagetype)
				then pagetype = require("Módulo:TipoDePágina").get_tipo_de_pagina(pagename)
			end
			output = p.lua_link_padronizado(pagename, pagetype, text)
			if h.isempty(data_de_lancamento)
				then data_de_lancamento = p.lua_get_data_de_lancamento(pagename, pagetype)
			end
			if not h.isempty(data_de_lancamento)
				then output = output..'<br>('..data_de_lancamento..')'
			end
			
			output = output..'<br>'
	end
	
	return output, data_de_lancamento
end

--------------------------------------------------------------------------------------------------
-- used in Template:Sl
function p.get_link(frame)
	local args = getArgs(frame)
	local pagename = args[1]
	local text = args[2]
	local pagetype = args['tipo']
	local output = ''
	
	if not h.isempty(pagename)
		then
			pagename = p.lua_substitua_o_sinal_numerico(pagename, pagetype)
			if h.isempty(pagetype)
				then pagetype = require("Módulo:TipoDePágina").get_tipo_de_pagina(pagename)
			end
			output = p.lua_link_padronizado(pagename, pagetype, text)
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
-- usado na Predefinição:Sld
function p.get_link_e_data_de_lancamento(frame)
	local args = getArgs(frame)
	local pagename = args[1]
	local text = args[2]
	local pagetype = args['tipo']
	local data_de_lancamento = args['data']
	
	local output = p.lua_get_link_e_data_de_lancamento(pagename, pagetype, text, data_de_lancamento)

	return output
end


--------------------------------------------------------------------------------------------------
-- retorna o link para o episódio, mas substitui o texto pelo título do episódio
-- usado na Predefinição:Elt
function p.get_link_para_episodio_com_titulo(frame)
	local args = getArgs(frame)
	local pagename = args[1]
	local text
	local pagetype = 'Episódio'
	local output = ''
	
	if not h.isempty(pagename)
		then
			pagename = p.lua_substitua_o_sinal_numerico(pagename, pagetype)
			text = p.lue_get_titulo_do_episodio(pagename)
			if text == pagename
				then output = p.lua_link_padronizado(pagename, pagetype)
				else output = p.lua_link_padronizado(pagename, pagetype, text)
			end
	end
	
	return output
end


--------------------------------------------------------------------------------------------------
-- used in Template:Eltd
function p.get_link_e_data_de_lancamento_to_episode_com_titulo(frame)
	local args = getArgs(frame)
	local pagename = args[1]
	local text
	local data_de_lancamento = args['data']
	local pagetype = 'Episódio'
	local output = ''

	if not h.isempty(pagename)
		then
			pagename = p.lua_substitua_o_sinal_numerico(pagename, pagetype)
			text = p.lue_get_titulo_do_episodio(pagename)
			if text == pagename
				then output = p.lua_link_padronizado(pagename, pagetype)
				else output = p.lua_link_padronizado(pagename, pagetype, text)
			end
			if h.isempty(data_de_lancamento)
				then data_de_lancamento = p.lua_get_data_de_lancamento(pagename, pagetype)
			end
			if not h.isempty(data_de_lancamento)
				then output = output..'<br>('..data_de_lancamento..')'
			end
	end
	
	return output 
end

--------------------------------------------------------------------------------------------------
function p.lue_get_titulo_do_episodio(pagename)
	local page_content = ''
	local output = ''
	
	if not h.isempty(pagename)
		then
			pagename = p.lua_substitua_o_sinal_numerico(pagename, 'Episódio')
			page_content = h.get_content(pagename)
			if page_content ~= ''
				then output = h.get_field_value(page_content, 'TituloDoEpisodio')
			end
			
			if output ~= ''
				then output = '"'..output..'"'
				else output = pagename
			end
	end
	
	return output
end

return p
Advertisement