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

De Wiki Gla
Ir para navegação Ir para pesquisar
m
m
Linha 16: Linha 16:


   local item = mw.html.create('div'):addClass('notice-item')
   local item = mw.html.create('div'):addClass('notice-item')
    :css('display','flex'):css('align-items','flex-start')
  -- layout and visuals are handled by stylesheet in MainPageChangelog.html
    :css('background','#fff'):css('border','1px solid #ddd')
    :css('border-radius','6px'):css('margin-bottom','10px')
    :css('padding','8px 10px'):css('box-sizing','border-box')
    :css('border-left','5px solid var(--notice-color, #f5b700)')


   if has(color) then item:css('--notice-color', color) end
   if has(color) then item:css('--notice-color', color) end
  -- handle icon first so it appears before the content (left side in flex layout)
  if has(icon) then
    -- Accept either a filename like "Bigexppot.png" (MediaWiki File:) or a full URL.
    local icon_wikitext = ''
    local lowered = string.lower(icon)
    if not string.find(lowered, '://', 1, true) and not string.find(icon, 'File:', 1, true) and not string.find(icon, 'Image:', 1, true) then
      -- treat as a filename -> prepend File:
      icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon]]', mw.text.trim(icon), mw.text.trim(title))
    else
      -- raw URL or explicit File: -> use as-is (for URLs we'll build an <img> tag so external URLs still work)
      if string.find(lowered, '://', 1, true) then
        -- external URL -> plain img tag via wikitext
        icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon" />', mw.text.trim(icon), mw.text.trim(title))
      else
        -- already has File: or Image: prefix -> wrap as wikitext (in case File:Name is provided)
        icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon]]', mw.text.trim(icon), mw.text.trim(title))
      end
    end
    -- add the icon as wikitext so MediaWiki resolves local files correctly
    item:wikitext(icon_wikitext)
  end


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


   if has(title) then
   if has(title) then
    local holder = content:tag('span'):addClass('notice-title')
  local holder = content:tag('span'):addClass('notice-title')
      :css('display','block'):css('margin','0')
     if has(link) then
     if has(link) then
       holder:wikitext('[' .. link .. ' ' .. title .. ']')  -- wikitexto -> <a>
       holder:wikitext('[' .. link .. ' ' .. title .. ']')  -- wikitexto -> <a>
Linha 38: Linha 55:
   if has(date) then
   if has(date) then
     content:tag('div'):addClass('notice-date')
     content:tag('div'):addClass('notice-date')
      :css('font-size','0.9em'):css('color','#888'):css('margin','-5px 0')
       :wikitext(date)
       :wikitext(date)
   end
   end
Linha 44: Linha 60:
   if has(desc) then
   if has(desc) then
     content:tag('p'):addClass('notice-desc')
     content:tag('p'):addClass('notice-desc')
      :css('color','#555'):css('line-height','1.3'):css('margin','0')
       :wikitext(desc)
       :wikitext(desc)
   end
   end


   if has(icon) then
   -- icon already handled above (so it appears before content)
    item:tag('img'):addClass('notice-icon')
      :attr('src', icon):attr('alt', title)
      :css('object-fit','contain'):css('flex-shrink','0')
  end


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

Edição das 20h06min de 2 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

function p.item(frame)
  local parent = frame:getParent()
  local a = parent and parent.args or frame.args

  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)

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

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

  -- handle icon first so it appears before the content (left side in flex layout)
  if has(icon) then
    -- Accept either a filename like "Bigexppot.png" (MediaWiki File:) or a full URL.
    local icon_wikitext = ''
    local lowered = string.lower(icon)
    if not string.find(lowered, '://', 1, true) and not string.find(icon, 'File:', 1, true) and not string.find(icon, 'Image:', 1, true) then
      -- treat as a filename -> prepend File:
      icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon]]', mw.text.trim(icon), mw.text.trim(title))
    else
      -- raw URL or explicit File: -> use as-is (for URLs we'll build an <img> tag so external URLs still work)
      if string.find(lowered, '://', 1, true) then
        -- external URL -> plain img tag via wikitext
        icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon" />', mw.text.trim(icon), mw.text.trim(title))
      else
        -- already has File: or Image: prefix -> wrap as wikitext (in case File:Name is provided)
        icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon]]', mw.text.trim(icon), mw.text.trim(title))
      end
    end
    -- add the icon as wikitext so MediaWiki resolves local files correctly
    item:wikitext(icon_wikitext)
  end

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

  if has(title) then
  local holder = content:tag('span'):addClass('notice-title')
    if has(link) then
      holder:wikitext('[' .. link .. ' ' .. title .. ']')  -- wikitexto -> <a>
    else
      holder:wikitext(title)
    end
  end

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

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

  -- icon already handled above (so it appears before content)

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

return p