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

De Wiki Gla
Ir para navegação Ir para pesquisar
m
m
Linha 20: Linha 20:
   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)
   local overlay_icon_wikitext = nil
  local inline_icon_wikitext = nil
   if has(icon) then
   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)
     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
     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)
       -- treat as a filename -> prepend File:
    if filename_like then
       icon_wikitext = string.format('[[File:%s|alt=%s|class=notice-icon]]', mw.text.trim(icon), mw.text.trim(title))
       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))
     else
     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
       if string.find(lowered, '://', 1, true) then
         -- external URL -> plain img tag via wikitext
         overlay_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--overlay" />', mw.text.trim(icon), mw.text.trim(title))
         icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon" />', mw.text.trim(icon), mw.text.trim(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))
       else
       else
         -- already has File: or Image: prefix -> wrap as wikitext (in case File:Name is provided)
         overlay_icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon notice-icon--overlay]]', mw.text.trim(icon), mw.text.trim(title))
         icon_wikitext = string.format('[[%s|alt=%s|class=notice-icon]]', 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
    -- add the icon as wikitext so MediaWiki resolves local files correctly
    item:wikitext(icon_wikitext)
   end
   end


Linha 49: Linha 46:
     local left = header:tag('div'):addClass('notice-header-left')
     local left = header:tag('div'):addClass('notice-header-left')
     local right = header:tag('div'):addClass('notice-header-right')
     local right = header:tag('div'):addClass('notice-header-right')
    -- inline icon (visible only on small screens) goes in header-left before text
    if inline_icon_wikitext then
      left:wikitext(inline_icon_wikitext)
    end


     if has(title) then
     if has(title) then

Edição das 20h27min 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

  local overlay_icon_wikitext = nil
  local inline_icon_wikitext = nil
  if has(icon) then
    local lowered = string.lower(icon)
    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)
    if filename_like then
      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))
    else
      if string.find(lowered, '://', 1, true) then
        overlay_icon_wikitext = string.format('<img src="%s" alt="%s" class="notice-icon notice-icon--overlay" />', mw.text.trim(icon), mw.text.trim(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))
      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

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

  -- Header row: title (left) and date (right)
  if has(title) or has(date) then
    local header = content:tag('div'):addClass('notice-header')
    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 header-left before text
    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:wikitext('[' .. link .. ' ' .. title .. ']')
      else
        holder:wikitext(title)
      end
    end

    if has(date) then
      right:tag('span'):addClass('notice-date'):wikitext(date)
    end
  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