Wiki Quadrinhos
Sem resumo de edição
Etiqueta: sourceedit
Sem resumo de edição
Etiqueta: sourceedit
Linha 66: Linha 66:
 
if not HF.isempty( args.Evento or args.Evento2 ) then
 
if not HF.isempty( args.Evento or args.Evento2 ) then
 
local Evento = mw.html.create('div'):addClass('comic-subtitle')
 
local Evento = mw.html.create('div'):addClass('comic-subtitle')
local EventText = string.format('Parte do [['..'%s]]', args.Evento )
+
local EventText = string.format('Parte do Evento [['..'%s]]', args.Evento )
 
if not HF.isempty(args.Evento2) then
 
if not HF.isempty(args.Evento2) then
EventText = EventText .. string.format(' eventos e [['..'%s]]', args.Evento2 )
+
EventText = EventText .. string.format(' e [['..'%s]]', args.Evento2 )
 
else
 
else
EventText = EventText .. ' evento'
+
EventText = EventText .. ' '
 
end
 
end
 
Evento:wikitext(EventText):done()
 
Evento:wikitext(EventText):done()
Linha 87: Linha 87:
 
function Infobox._EventCollate( args, vars )
 
function Infobox._EventCollate( args, vars )
 
if not HF.isempty( args.Evento or args.Evento2 or args.Evento3 ) then
 
if not HF.isempty( args.Evento or args.Evento2 or args.Evento3 ) then
local EventText = string.format('Parte do [['..'%s]]', args.Evento )
+
local EventText = string.format('Parte do Evento [['..'%s]]', args.Evento )
 
if not HF.isempty(args.Evento2) and HF.isempty(args.Evento3) then
 
if not HF.isempty(args.Evento2) and HF.isempty(args.Evento3) then
EventText = EventText .. string.format(' eventos e [['..'%s]]',
+
EventText = EventText .. string.format(' e [['..'%s]]',
 
args.Evento2 )
 
args.Evento2 )
 
elseif not HF.isempty(args.Evento2) and not HF.isempty(args.Evento3) then
 
elseif not HF.isempty(args.Evento2) and not HF.isempty(args.Evento3) then
EventText = EventText .. string.format('eventos , [['..'%s]], e [['..'%s]] ',
+
EventText = EventText .. string.format(' [['..'%s]], e [['..'%s]] ',
 
args.Evento2, args.Evento3 )
 
args.Evento2, args.Evento3 )
 
else
 
else
EventText = EventText .. ' evento'
+
EventText = EventText .. ' '
 
end
 
end
 
end
 
end

Edição das 20h34min de 2 de setembro de 2017

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

local Infobox = {}
 
----------------------------
-- Bibliotecas de funções --
----------------------------
-- significa High Frequency
local HF = require('Module:ComicsHF')
-- Parâmetros de invocação de Parses, abrange espaços em branco e remove espaços em branco
local getArgs = require('Dev:Arguments').getArgs
-- Funções comuns e centralizadas
local ComicsInfobox = require('Module:ComicsInfobox')
local MesParse = require("Module:Month")
local L = require('Dev:List')
local lang = mw.language.new('en')

-----------------------
-- Bibliotecas de dados --
-----------------------
-- Tabelas de dados para contribuintes comuns de pessoal
local StaffNames = require( 'Module:StaffCorrection' )

-- Uma vez que isso só deve ser avaliado uma vez por visualização de página, agora é global
_G.vars = { Pagename = mw.title.getCurrentTitle().text }

---------------------
-- Funções locais --
---------------------
local function invokeInt(funcName)
  -- Este invólucro permite a invocação de uma função interna a partir de um quadro.
	return function (frame)
		local args = getArgs(frame, { trim = true, removeBlanks = true })
		return Infobox[funcName](args, vars)
	end
end

Infobox.HeadTitle = invokeInt('_deriveHeadTitle')
Infobox.Eventos = invokeInt('_EventCollate')
Infobox.Imagem1 = invokeInt('_PrimaryCover')
Infobox.Imagem2 = invokeInt('_TextlessCover')
Infobox.ComicTitle = invokeInt('_deriveTitle')
Infobox.DigitalTitle = invokeInt('_deriveTitleDigital')
Infobox.DataDeLancamento = invokeInt('_dataDeLancamento')
Infobox.DataDePublicacao = invokeInt('_dataDePublicacao')

function Infobox._deriveHeadTitle( args, vars )
  local Title = mw.html.create('div'):addClass('comic-headtitle')
  local category = {}
  if not HF.isempty( args.HeadTitle ) then
    if string.lower( args.HeadTitle ) ~= 'none' then
       Title:tag('span'):addClass('comic-headtitle'):wikitext(args.HeadTitle):done()
     end
   end
  if not HF.isempty( args.StoryArc or args.StoryArc2 ) then
    local StoryArc = mw.html.create('div'):addClass('comic-subtitle')
    local ArcText = string.format('Parte do [['..'%s]]', args.StoryArc )
    table.insert( category, string.format( '[['..'Category:%s]]', args.StoryArc ))
    if not HF.isempty(args.StoryArc2) then
      ArcText = ArcText .. string.format(' e [['..'%s]] historia do arco', args.StoryArc2 )
      table.insert( category, string.format( '[['..'Categoria:%s]]', args.StoryArc2 ))
    else
      ArcText = ArcText .. ' historia do arco'
    end
    StoryArc:wikitext(ArcText):done()
    Title:node( StoryArc )
  end
  if not HF.isempty( args.Evento or args.Evento2 ) then
    local Evento = mw.html.create('div'):addClass('comic-subtitle')
    local EventText = string.format('Parte do Evento [['..'%s]]', args.Evento )
    if not HF.isempty(args.Evento2) then
      EventText = EventText .. string.format(' e [['..'%s]]', args.Evento2 )
    else
      EventText = EventText .. ' '
    end
    Evento:wikitext(EventText):done()
    Title:node( Evento )
  end
  if not HF.isempty( args.Storyline ) then
    local Storyline = mw.html.create('div'):addClass('comic-subtitle')
      :wikitext(string.format('Parte do [[%s]] arco.', args.Storyline )):done()
    table.insert( category, string.format( '[['..'Categoria'..':%s]]', args.Storyline ))
    Title:node( Storyline )
  end
  Title:tag('div'):addClass('comic-subtitle'):tag('br', { selfClosing = true }):done()
  return tostring(Title) .. table.concat( category )
end

function Infobox._EventCollate( args, vars )
    if not HF.isempty( args.Evento or args.Evento2 or args.Evento3 ) then
        local EventText = string.format('Parte do Evento [['..'%s]]', args.Evento )
        if not HF.isempty(args.Evento2) and HF.isempty(args.Evento3) then
            EventText = EventText .. string.format('  e [['..'%s]]',
                args.Evento2 )
        elseif not HF.isempty(args.Evento2) and not HF.isempty(args.Evento3) then
            EventText = EventText .. string.format(' [['..'%s]], e [['..'%s]] ',
                args.Evento2, args.Evento3 )
        else
            EventText = EventText .. ' '
        end
    end
end

function Infobox._StoryCollate( args, vars )
        
end

function Infobox._PrimaryCover( args, vars )
  local givenImagem = args.Imagem or args[1] or nil
  local fromPage = vars.Pagename .. '.jpg'
  local label = args.ImagemTexto or args[2] or 'Capa'
  if givenImagem and mw.title.new( givenImagem, 'File' ).exists == true then
    return givenImagem .. '|' .. label
  elseif fromPage and mw.title.new( fromPage, 'File' ).exists == true then
    return fromPage .. '|' .. label
  elseif givenImagem then
      return givenImagem .. '|' .. label
  else
      return nil
  end
end

function Infobox._TextlessCover( args, vars )
  local givenImagem = args.Imagem2 or args[1] or nil
  local fromPage = vars.Pagename .. ' Textless.jpg'
  local label = args.Imagem2Texto or args[2] or 'Sem Texto'
  if givenImagem and mw.title.new( givenImagem, 'File' ).exists == true then
    return givenImagem .. '|' .. label
  elseif fromPage and mw.title.new( fromPage, 'File' ).exists == true then
    return fromPage .. '|' .. label
  elseif givenImagem then
      return givenImagem .. '| '  .. label
      else
          return nil
  end
end

function Infobox._deriveTitle( args, vars )
  local Titulo, Volume, Edicao  = string.match( vars.Pagename, "(.*)%s*Vol%s*(%d)%s*(%d*)")
   Titulo = args.Titulo or Titulo or nil
   Volume = args.Volume or Volume or nil
   Edicao = args.Edicao or Edicao or nil
   if Titulo and Volume and Edicao then
       return string.format('[[%s'..' Vol %s]] # %s', Titulo, Volume, Edicao)
   elseif Titulo and Volume then
       return string.format('[[%s'..' Vol %s|%s]]', Titulo, Volume, Titulo)
   else
       return ''
   end
   
  end
  
function Infobox._deriveTitleDigital( args, vars )
  local Titulo, Volume, Capitulo  = string.match( vars.Pagename, "(.*)%s*Vol%s*(%d)%s*(%d*)%s*%(Digital%)")
   Titulo = args.Titulo or Titulo or nil
   Volume = args.Volume or Volume or nil
   Capitulo = args.Capitulo or Capitulo or nil
   if Titulo and Volume and Capitulo then
       return string.format('[[%s'..' Vol %s]] # %s', Titulo, Volume, Capitulo)
   elseif Titulo and Volume then
       return string.format('[[%s'..' Vol %s|%s]]', Titulo, Volume, Titulo)
   else
       return ''
   end
   
  end
function Infobox._dataDeLancamento( args, vars )
    local DataDeLancamento = args.DataDeLancamento or nil
    local Data, Semana, Ano, CategoryTitle
    if not DataDeLancamento then return '' end

    if string.match(DataDeLancamento, 'Semana') then
        Semana, Ano = string.match( DataDeLancamento, "Semana (.*),%s*(.*)")
        Semana = tonumber(Semana) - 3
        Data = lang:formatData( 'F j, Y', Ano..'-W'..Semana )
    else
        Semana = lang:formatData( 'W', DataDeLancamento)
        Ano = lang:formatData( 'Y', DataDeLancamento)
        Data = lang:formatData( 'F j, Y', DataDeLancamento)
    end

    CategoryTitle = string.format('Category:Semana %s, %s', Semana, Ano)

    if mw.title.new( CategoryTitle ) then
        return string.format('[[:%s|%s]]', CategoryTitle, Data)
    else
        return Data
    end
end

function Infobox._dataDePublicacao( args, vars )
	local links = {}
    local Mes, Ano = args.Mes or nil, args.Ano or nil
	local gMes = args.Mes -- O dado do mês de entrada
	local Temporada = args.Temporada or nil
	
	if Mes then
		if string.find( gMes, 'Atrasado' ) then
			Mes = string.match( gMes, "Atrasado (.*)" )
		elseif string.find( gMes, 'Cedo' ) then
			Mes = string.match( gMes, "Cedo (.*)" )
		elseif string.find( gMes, 'Meio' ) then
			Mes = string.match( gMes, "Meio (.*)" )
		elseif string.find( gMes, 'x' ) then
			Mes = string.match( gMes, "(.*)x" )
		else
	        Mes = MesParse._mes( { gMes } )
	    end

	    table.insert( links,
	        string.format( '[[:'..'Categoria:%s, %s|%s]]', Ano, Mes, Mes )
	    )
	    table.insert( links, ', ' )
    end
    
    if Temporada then
        local ParsedTemporada = MesParse._mes( Temporada )
        table.insert( links,
            string.format( '[[:'..'Categoria:%s, %s|%s]]', Ano, ParsedTemporada, PasedTemporada )
        )
        table.insert( links, ', ' )
    end
    
    table.insert( links,
		string.format( '[[:'..'Categoria:%s|%s]]', Ano, Ano )
	)

	return table.concat( links )
end

Infobox.CreditCheck = invokeInt('_CreditCheck')
Infobox.ContributorLink = invokeInt('_ContributorLink')
Infobox.Contributors = invokeInt('_Contributors')
Infobox.UContributors = invokeInt('_UContributors')
Infobox.StoryTitleHeader = invokeInt('_StoryTitleHeader')
Infobox.EdicaoAnterior = invokeInt('_EdicaoAnterior')
Infobox.ProximaEdicao = invokeInt('_ProximaEdicao')

function Infobox._CreditCheck( parameters )
    if string.match( parameters[1], 'redited') or
      string.match( parameters[1], 'NA') or
      string.match( string.lower(parameters[1]), 'N/A') then
        return 'Uncredited'
    elseif parameters[2] then --Cancelamento
        return ''
    elseif not parameters[2] then
        return Infobox._ContributorLink( 
			            { parameters[1],
			                role = parameters.role,
			                nocorrect = parameters.nocorrection }
			             )
    end
end

function Infobox._ContributorLink( args )
    local output = {}
    local role = args.role or args[2] or nil
    local correction
	table.insert( output, StaffNames:link( args[1] ) )
	if role then 
	    table.insert( output, StaffNames:cat_role( args[1], role ) ) 
	end
	return table.concat( output )
end

function Infobox._Contributors( parameters )
    -- Esta é uma função mágica que leva de 1 a infinito
    -- parâmetros e os reduz a tamanho. Faz links para contribuidores.
	local field = {
	    -- Se os parâmetros estiverem numerados, onde os números começam e finalizam?
	    min = tonumber(parameters['Contributors.min']),
	    max = tonumber(parameters['Contributors.max']),
	    -- Isso pode ser "Escritor" ou "Escritor1_"
	    prefix = parameters['Contributors.prefix'],
	    -- Se for especificado que eles contribuíram para certas páginas ...
	    pages = parameters['Contributors.pagesprefix'],
	    -- Se for especificado que eles contribuíram para certas páginas ...
	    --- 'horizontal' (padrão), 'marcado',
	    --- 'não marcado' (aka <br/>),
	    --- 'ordenado ', ou' horizontal_ordenado '
	    list = parameters['Contributors.list'] or 'horizontal',
	    role = parameters['Contributors.role'],
	    between = parameters['Contributors.between'],
	    nocreditcheck = parameters['Contributors.nocreditcheck'],
	    nocorrection = parameters['Contributors.nocorrection'],
	    canceled = parameters['Contributors.canceled'],
	    }
	local output = {}
	if field.min and field.max then
	    for i = field.min, field.max do
            local argcheck = field.prefix .. i
            local nextarg = field.prefix .. (i + 1)
            if field.pages then 
                pagestext = field.pages .. i
            end
            -- Em algum lugar aqui, precisa ser uma afirmação de que o parâmetro que você procura existe. Como "Escritor" vs "Escritor1_".
            if i == 1 and field.nocreditcheck ~= nil then
                Infobox._CreditCheck( { argcheck,
                    field.canceled,
			        role = field.role,
			        nocorrection = field.nocorrection 
                    })
            elseif i == 1 or parameters[argcheck] then
                local link = Infobox._ContributorLink(
			            { parameters[argcheck],
			                role = field.role,
			                nocorrect = field.nocorrection }
		            )
		        if pagestext and parameters[pagestext] then -- Valor existe
			        link = link .. ('&#32;<small>(pg. '..parameters[pagestext]..')</small>')
			    end
                table.insert( output, link )
			end
			
			-- se parâmetros [nextarg] e field.between então
			--	table.insert( output, field.between )
			-- end
		end
	    -- return table.concat( output )
	    return L.makeList( 'horizontal' , output )
	else
	    -- Um único parâmetro, hein?
	    -- Nós podemos simplesmente fazer uma coisa única.
	    local argcheck = field.prefix
	    if field.pages then pagestext = field.pages end
	    if field.nocreditcheck ~= nil then
                Infobox._CreditCheck( { argcheck,
                    field.canceled,
			        role = field.role,
			        nocorrection = field.nocorrection 
                    })
            elseif parameters[argcheck] then
                local link = Infobox._ContributorLink(
			            { parameters[argcheck],
			                role = field.role,
			                nocorrect = field.nocorrection }
		            )
		        if pagestext and parameters[pagestext] then -- Valor existe
			        link = link .. ('&#32;<small>(pg. '..parameters[pagestext]..')</small>')
			    end
        end
	end
end

function Infobox._ContributorsDigital( parameters )
    -- Esta é uma função mágica que leva de 1 a infinito
    -- parâmetros e os reduz a tamanho. Faz links para contribuidores.
	local field = {
	    -- Se os parâmetros estiverem numerados, onde os números começam e finalizam?
	    min = tonumber(parameters['Contributors.min']),
	    max = tonumber(parameters['Contributors.max']),
	    -- Isso pode ser "Escritor" ou "Escritor1_"
	    prefix = parameters['Contributors.prefix'],
	    -- Se for especificado que eles contribuíram para certas páginas ...
	    pages = parameters['Contributors.pagesprefix'],
	    -- Se a saída é uma lista, qual o tipo de lista?
	    --- 'horizontal' (padrão), 'marcado',
	    --- 'não marcado' (aka <br/>),
	    --- 'ordenado' ou 'horizontal_ordenado'
	    list = parameters['Contributors.list'] or 'horizontal',
	    role = parameters['Contributors.role'],
	    between = parameters['Contributors.between'],
	    nocreditcheck = parameters['Contributors.nocreditcheck'],
	    nocorrection = parameters['Contributors.nocorrection'],
	    canceled = parameters['Contributors.canceled'],
	    }
	local output = {}
	if field.min and field.max then
	    for i = field.min, field.max do
            local argcheck = field.prefix .. i
            local nextarg = field.prefix .. (i + 1)
            if field.pages then 
                pagestext = field.pages .. i
            end
            -- Em algum lugar aqui, precisa ser uma afirmação de que o parâmetro que você procura existe. Como "Escritor" vs "Escritor1_".
            if i == 1 and field.nocreditcheck ~= nil then
                Infobox._CreditCheck( { argcheck,
                    field.canceled,
			        role = field.role,
			        nocorrection = field.nocorrection 
                    })
            elseif i == 1 or parameters[argcheck] then
                local link = Infobox._ContributorLink(
			            { parameters[argcheck],
			                role = field.role,
			                nocorrect = field.nocorrection }
		            )
		        if pagestext and parameters[pagestext] then -- Valor existe
			        link = link .. ('&#32;<small>(pg. '..parameters[pagestext]..')</small>')
			    end
                table.insert( output, link )
			end
			
			-- se parâmetros [nextarg] e field.between então
			--	table.insert( output, field.between )
			-- end
		end
	    -- return table.concat( output )
	    return L.makeList( 'horizontal' , output )
	else
	    -- Um único parâmetro, hein?
	    -- Nós podemos simplesmente fazer uma coisa única.
	    local argcheck = field.prefix
	    if field.pages then pagestext = field.pages end
	    if field.nocreditcheck ~= nil then
                Infobox._CreditCheck( { argcheck,
                    field.canceled,
			        role = field.role,
			        nocorrection = field.nocorrection 
                    })
            elseif parameters[argcheck] then
                local link = Infobox._ContributorLink(
			            { parameters[argcheck],
			                role = field.role,
			                nocorrect = field.nocorrection }
		            )
		        if pagestext and parameters[pagestext] then -- Valor existe
			        link = link .. ('&#32;<small>(pg. '..parameters[pagestext]..')</small>')
			    end
        end
	end
end

function Infobox._StoryTitleHeader( args )
-- if " then [[{{FULLPAGENAME}}#Aparição em {{{TituloDaHistoria1}}}|{{{TituloDaHistoria1}}}]]
-- if!" then "[[{{FULLPAGENAME}}#Aparição em "{{{TituloDaHistoria1}}}"|{{{TituloDaHistoria1}}}]]"
    if args[1] then
        local story = args[1]
        if string.match( story, '"') then 
            return string.format( '[[%s#Aparição em %s|%s]]',
            mw.title.getCurrentTitle().prefixedText, story, story )
        else
            return string.format( '[[%s#Aparição em %s|"%s"]]',
            mw.title.getCurrentTitle().prefixedText, string.format( '"%s"', story ), story )
        end
        
    else
        return '&nbsp;'
    end
    
end

function Infobox._EdicaoAnterior( args )
    local Titulo, Volume, Edicao
    if args.EdicaoAnterior then
        Titulo, Volume, Edicao  = string.match( EdicaoAnterior, "(.*)%s*Vol%s*(%d)%s*(%d*)")
    else
        Titulo, Volume, Edicao  = string.match( vars.Pagename, "(.*)%s*Vol%s*(%d)%s*(%d*)")
    end
    
   Titulo = args.Titulo or Titulo or nil
   Volume = tonumber(args.Volume) or tonumber(Volume) or nil
   Edicao = tonumber(args.Edicao) or tonumber(Edicao) or nil
   
   if (Volume == 1 and Edicao == 1) or (Volume == nil and Edicao == nil) then
       -- novo título, sem anterior
       return ''
   elseif Edicao > 1 and Volume ~= 1 then
       -- mesmo volume, nova edição
       Edicao = Edicao - 1
       return string.format('[[%s Vol %s %s|%s Vol %s # %s]]', Titulo, Volume, Edicao, Titulo, Volume, Edicao )
   elseif Edicao > 1 and Volume == 1 then
       -- mesmo primeiro volume, novo edição
       Edicao = Edicao - 1
       return string.format('[[%s Vol %s %s|%s # %s]]', Titulo, Volume, Edicao, Titulo, Edicao )
   elseif Volume > 1 and Edicao == 1 then
       -- primeira edição de um novo volume, consulta o último volume
       Volume = Volume - 1
       return string.format('[[%s Vol %s]]', Titulo, Volume)
   else
       -- nenhum outro caso de uso
       return ''
   end
end

function Infobox._ProximaEdicao( args )
    local Titulo, Volume, Edicao
    if args.ProximaEdicao then
        Titulo, Volume, Edicao  = string.match( ProximaEdicao, "(.*)%s*Vol%s*(%d)%s*(%d*)")
    else
        Titulo, Volume, Edicao  = string.match( vars.Pagename, "(.*)%s*Vol%s*(%d)%s*(%d*)")
    end
    
   Titulo = args.Titulo or Titulo or nil
   Volume = tonumber(args.Volume) or tonumber(Volume) or nil
   Edicao = tonumber(args.Edicao) or tonumber(Edicao) or nil
   
   if Volume == nil and Edicao == nil then
       -- novo título, sem anterior
       return ''
   else
    ProximaEdicao = string.format('%s Vol %s %s', Titulo, Volume, Edicao + 1 )
    ProximoVolume = string.format('%s Vol %s', Titulo, Volume + 1 )
   end
   
   if mw.title.new( ProximaEdicao ).exists == true then
       if Volume == 1 then 
           return string.format('[['..'%s|%s # %s]]', ProximaEdicao, Titulo, Edicao + 1)
       else 
           return string.format('[['..'%s|%s Vol %s # %s]]', ProximaEdicao, Titulo, Volume, Edicao + 1)
       end
   elseif mw.title.new( ProximoVolume ).exists == true then
       return string.format('[['..'%s Vol %s]]', Titulo, Volume + 1 )
   else
       return ''
   end
end

return Infobox