Mudanças entre as edições de "Módulo:Changelog"

De Wiki Gla
Ir para navegação Ir para pesquisar
m
Etiqueta: Reversão manual
m
Linha 4: Linha 4:
local function has(s) return N(s) ~= '' end
local function has(s) return N(s) ~= '' end


-- Uso: {{#invoke:Changelog|item|title=...|description=...|date=...|link=...|icon=...|color=#FCE5CD}}
function p.item(frame)
function p.item(frame)
   local parent = frame:getParent()
   local parent = frame:getParent()
   local a = parent and parent.args or frame.args
   local a = (parent and parent.args) or frame.args or {}


   local title = N(a.title)
   local title = N(a.title)
Linha 15: Linha 16:
   local color = N(a.color)
   local color = N(a.color)


   local item = mw.html.create('div'):addClass('notice-item')
  -- Raiz do item
  -- layout and visuals are handled by stylesheet in MainPageChangelog.html
   local item = mw.html.create('div')
    :addClass('notice-item')


   if has(color) then item:css('--notice-color', color) end
   if has(color) then
    item:css('--notice-color', color)
  end


   local overlay_icon_wikitext = nil
   -- Pré-monta wikitext dos ícones (inline e overlay)
   local inline_icon_wikitext = nil
   local overlay_icon_wikitext, inline_icon_wikitext
   if has(icon) then
   if has(icon) then
     local lowered = string.lower(icon)
     local lower = icon:lower()
     local filename_like = not string.find(lowered, '://', 1, true) and not string.find(icon, 'File:', 1, true) and not string.find(icon, 'Image:', 1, true)
     local is_url = lower:find('://', 1, true) ~= nil
     if filename_like then
    local is_prefixed = lower:match('^file:') or lower:match('^image:')
       overlay_icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--overlay]]', mw.text.trim(icon), mw.text.trim(title))
 
       inline_icon_wikitext  = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--inline]]', mw.text.trim(icon), mw.text.trim(title))
     if not is_url and not is_prefixed then
      -- Nome de arquivo "puro" (ex.: Attr_PVE.png)
       overlay_icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--overlay|link=]]', icon, title)
       inline_icon_wikitext  = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--inline|link=]]', icon, title)
    elseif is_url then
      -- URL externa
      overlay_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--overlay" />', icon, title)
      inline_icon_wikitext  = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--inline" />',  icon, title)
     else
     else
       if string.find(lowered, '://', 1, true) then
       -- Já veio com File:/Image:
        overlay_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--overlay" />', mw.text.trim(icon), mw.text.trim(title))
       overlay_icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon notice-icon--overlay|link=]]', icon, title)
        inline_icon_wikitext  = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--inline" />', mw.text.trim(icon), mw.text.trim(title))
      inline_icon_wikitext  = string.format('[[%s|alt=%s|class=notice-icon notice-icon--inline|link=]]', icon, title)
       else
        overlay_icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon notice-icon--overlay]]', mw.text.trim(icon), mw.text.trim(title))
        inline_icon_wikitext  = string.format('[[%s|alt=%s|class=notice-icon notice-icon--inline]]', mw.text.trim(icon), mw.text.trim(title))
      end
     end
     end
   end
   end


   local content = item:tag('div'):addClass('notice-content'):css('flex','1')
  -- Conteúdo principal
   local content = item:tag('div'):addClass('notice-content'):css('flex', '1')


   -- Header: left (icon + title) and right (date) so date can be flush-right
   -- Header (ícone inline + título + data)
   if has(title) or has(date) then
   local header = content:tag('div'):addClass('notice-header')
    local header = content:tag('div'):addClass('notice-header')
  local left   = header:tag('div'):addClass('notice-left')
    local left = header:tag('div'):addClass('notice-header-left')
    local right = header:tag('div'):addClass('notice-header-right')


    -- inline icon (visible only on small screens) goes in left before text
  if inline_icon_wikitext then
    if inline_icon_wikitext then
    left:wikitext(inline_icon_wikitext)
      left:wikitext(inline_icon_wikitext)
  end
    end


    if has(title) then
  if has(title) then
      local holder = left:tag('span'):addClass('notice-title')
    local holder = left:tag('span'):addClass('notice-title')
      if has(link) then
    if has(link) then
         holder:wikitext('[' .. link .. ' ' .. title .. ']')
      holder:tag('a')
      else
         :attr('href', link)
         holder:wikitext(title)
        :attr('target', '_blank')
       end
        :attr('rel', 'noopener noreferrer')
         :wikitext(title)
    else
       holder:wikitext(title)
     end
     end
  end


    if has(date) then
  if has(date) then
      right:tag('span'):addClass('notice-date'):wikitext(date)
    left:tag('div'):addClass('notice-date'):wikitext(date)
    end
   end
   end


   if has(desc) then
   if has(desc) then
     content:tag('p'):addClass('notice-desc')
     content:tag('p'):addClass('notice-desc'):wikitext(desc)
      :wikitext(desc)
   end
   end


   -- render overlay icon (absolute) so it doesn't alter layout
   -- Ícone overlay (se o CSS usar posição absoluta)
   if overlay_icon_wikitext then
   if overlay_icon_wikitext then
     item:wikitext(overlay_icon_wikitext)
     item:wikitext(overlay_icon_wikitext)
   end
   end


   return tostring(item) -- já sai como HTML + wikitexto parseável
   return tostring(item)
end
end


return p
return p

Edição das 14h11min de 10 de setembro de 2025

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

local p = {}

local function N(s) return s and mw.text.trim(tostring(s)) or '' end
local function has(s) return N(s) ~= '' end

-- Uso: {{#invoke:Changelog|item|title=...|description=...|date=...|link=...|icon=...|color=#FCE5CD}}
function p.item(frame)
  local parent = frame:getParent()
  local a = (parent and parent.args) or frame.args or {}

  local title = N(a.title)
  local link  = N(a.link)
  local date  = N(a.date)
  local desc  = N(a.description)
  local icon  = N(a.icon)
  local color = N(a.color)

  -- Raiz do item
  local item = mw.html.create('div')
    :addClass('notice-item')

  if has(color) then
    item:css('--notice-color', color)
  end

  -- Pré-monta wikitext dos ícones (inline e overlay)
  local overlay_icon_wikitext, inline_icon_wikitext
  if has(icon) then
    local lower = icon:lower()
    local is_url = lower:find('://', 1, true) ~= nil
    local is_prefixed = lower:match('^file:') or lower:match('^image:')

    if not is_url and not is_prefixed then
      -- Nome de arquivo "puro" (ex.: Attr_PVE.png)
      overlay_icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--overlay|link=]]', icon, title)
      inline_icon_wikitext  = string.format('[[File:%s|alt=%s|class=notice-icon notice-icon--inline|link=]]',  icon, title)
    elseif is_url then
      -- URL externa
      overlay_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--overlay" />', icon, title)
      inline_icon_wikitext  = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--inline" />',  icon, title)
    else
      -- Já veio com File:/Image:
      overlay_icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon notice-icon--overlay|link=]]', icon, title)
      inline_icon_wikitext  = string.format('[[%s|alt=%s|class=notice-icon notice-icon--inline|link=]]',  icon, title)
    end
  end

  -- Conteúdo principal
  local content = item:tag('div'):addClass('notice-content'):css('flex', '1')

  -- Header (ícone inline + título + data)
  local header = content:tag('div'):addClass('notice-header')
  local left   = header:tag('div'):addClass('notice-left')

  if inline_icon_wikitext then
    left:wikitext(inline_icon_wikitext)
  end

  if has(title) then
    local holder = left:tag('span'):addClass('notice-title')
    if has(link) then
      holder:tag('a')
        :attr('href', link)
        :attr('target', '_blank')
        :attr('rel', 'noopener noreferrer')
        :wikitext(title)
    else
      holder:wikitext(title)
    end
  end

  if has(date) then
    left:tag('div'):addClass('notice-date'):wikitext(date)
  end

  if has(desc) then
    content:tag('p'):addClass('notice-desc'):wikitext(desc)
  end

  -- Ícone overlay (se o CSS usar posição absoluta)
  if overlay_icon_wikitext then
    item:wikitext(overlay_icon_wikitext)
  end

  return tostring(item)
end

return p