Ir para o conteúdo

Módulo:InfoboxImage: mudanças entre as edições

De Wiki TokuDrive
Importando predefinição/módulo da Wikipédia em português para manter layout
Importando predefinição/módulo da Wikipédia em português para manter layout
 
Linha 1: Linha 1:
-- Entradas (Inputs):
-- Inputs:
--    image / imagem - Pode ser o nome puro do arquivo (com ou sem o prefixo Ficheiro:/File:) ou um link de imagem totalmente formatado.
--    image - Can either be a bare filename (with or without the File:/Image: prefix) or a fully formatted image link
--    page / página - Página a ser exibida para imagens multipáginas (ex: arquivos DjVu).
--    page - page to display for multipage images (DjVu)
--    size / tamanho - Tamanho (largura) em que a imagem será exibida.
--    size - size to display the image
--    maxsize / tamanhomáx - Tamanho máximo limite para a exibição da imagem.
--    maxsize - maximum size for image
--    sizedefault / tamanhopadrão - Tamanho padrão a ser exibido caso o parâmetro de tamanho esteja em branco.
--    sizedefault - default size to display the image if size param is blank
--    alt - Texto alternativo (alt text) para acessibilidade da imagem.
--    alt - alt text for image
--    title / título - Texto de título/legenda interna para a imagem.
--    title - title text for image
--    border / borda - Define como "yes" (ou "sim") para adicionar uma borda ao redor da imagem.
--    border - set to yes if border
--    center / centro - Define como "yes" (ou "sim") se a imagem precisar ser centralizada.
--    center - set to yes, if the image has to be centered
--    upright - Parâmetro multiplicador de tamanho relativo (upright).
--    upright - upright image param
--    suppressplaceholder / suprimirsubstituto - Se definido como "yes" (ou "sim"), verifica se a imagem é um substituto padrão (placeholder) e a oculta.
--    suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it
--    link / ligação - Página da wiki para onde o usuário será direcionado ao clicar na imagem.
--    link - page to visit when clicking on image
--    class / classe - Classes HTML personalizadas a serem adicionadas à tag da imagem.
--    class - HTML classes to add to the image
-- Saídas (Outputs):
-- Outputs:
--    Imagem devidamente formatada em código MediaWiki.
--    Formatted image.
-- Mais detalhes disponíveis na página de documentação "Módulo:InfoboxImage/doc".
-- More details available at the "Module:InfoboxImage/doc" page


local i = {}
local i = {}


local defaultThumbnailSize = 220
-- List of placeholder images and tracking categories stored in [[Module:InfoboxImage/data]]
-- Other constants:
--  the system-wide default thumbnail size (in px)
local defaultThumbnailSize = 250


-- Carrega o módulo utilitário para tratamento de valores booleanos (sim/não, yes/no)
-- Mapeamento de traduções em português para inglês
local yesno = require('Módulo:Yesno')
local mapaParametros = {
    imagem = "image",
    ["página"] = "page",
    tamanho = "size",
    ["tamanhomáx"] = "maxsize",
    ["tamanhopadrão"] = "sizedefault",
    ["ligação"] = "link",
    ["título"] = "title",
    borda = "border",
    tempominiatura = "thumbtime",
    centro = "center",
    classe = "class",
    suprimirsubstituto = "suppressplaceholder"
}


-- Otimização: Cache dos nomes válidos para o Namespace de Arquivos/Ficheiros uma única vez
-- Função auxiliar interceptadora
local fileNamespaces = {}
local function normalizarArgumentos(argsOriginal)
do
    local args = {}
     local ns6 = mw.site.namespaces[6]
      
     -- Insere o nome local (Ficheiro), o canônico (File) e todos os aliases existentes
     -- Copia primeiro os parâmetros em inglês
     table.insert(fileNamespaces, mw.ustring.lower(ns6.name))
     for k, v in pairs(argsOriginal) do
     table.insert(fileNamespaces, mw.ustring.lower(ns6.canonicalName))
        args[k] = v
     for _, alias in ipairs(ns6.aliases) do
    end
         table.insert(fileNamespaces, mw.ustring.lower(alias))
   
     -- Traduz e insere os parâmetros em português se a chave em inglês estiver vazia
     for pt, en in pairs(mapaParametros) do
         if (args[en] == nil or args[en] == "") and argsOriginal[pt] then
            args[en] = argsOriginal[pt]
        end
    end
   
    -- Normaliza valores booleanos traduzidos
    if args.suppressplaceholder == "não" or args.suppressplaceholder == "nao" then
        args.suppressplaceholder = "no"
     end
     end
   
    return args
end
end


-- Função de categorização que consome o submódulo aplicando Lazy Loading (carregamento apenas quando necessário)
-- If page is not a user page, return tracking category. Else return empty.
local function trackingCat(catKey)
local function trackingCat(cat)
     local ns = mw.title.getCurrentTitle().nsText:lower()
     local ns = mw.title.getCurrentTitle().nsText:lower()
    if ns == 'user' or ns == 'user talk' then return "" end
     local categories = mw.loadData('Module:InfoboxImage/data').categories
   
     return (ns ~= 'user' and ns ~= 'user talk' and categories[cat]) or ""
     local categories = mw.loadData('Módulo:InfoboxImage/data').categories
     return categories[catKey] or ""
end
end


-- Remove os prefixos de namespace (ex: "Ficheiro:", "File:") do início de uma string
-- Determine whether image is a placeholder
local function stripNamespace(imageName)
function i.IsPlaceholder(image)
     imageName = mw.ustring.gsub(imageName, '^[ ]*(.-)[ ]*$', '%1') -- Trim original
    -- change underscores to spaces
     for _, name in ipairs(fileNamespaces) do
    image = mw.ustring.gsub(image, "_", " ");
        local prefixLen = mw.ustring.len(name) + 1
    assert(image ~= nil, 'mw.ustring.gsub(image, "_", " ") must not return nil')
         if mw.ustring.lower(mw.ustring.sub(imageName, 1, prefixLen)) == name .. ":" then
    -- if image starts with [[ then remove that and anything after |
             imageName = mw.ustring.sub(imageName, prefixLen + 1)
    if mw.ustring.sub(image,1,2) == "[[" then
        image = mw.ustring.sub(image,3);
        image = mw.ustring.gsub(image, "([^|]*)|.*", "%1");
        assert(image ~= nil, 'mw.ustring.gsub(image, "([^|]*)|.*", "%1") must not return nil')
    end
    -- Trim spaces
     image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
     assert(image ~= nil, "mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1') must not return nil")
    -- remove prefix if exists
    local allNames = mw.site.namespaces[6].aliases
    allNames[#allNames + 1] = mw.site.namespaces[6].name
    allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
    for i, name in ipairs(allNames) do
         if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
             image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
             break
             break
         end
         end
     end
     end
     return mw.ustring.gsub(imageName, '^[ ]*(.-)[ ]*$', '%1') -- Trim pós-remoção
     -- Trim spaces
end
    image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
    -- capitalise first letter
    image = mw.ustring.upper(mw.ustring.sub(image,1,1)) .. mw.ustring.sub(image,2);


function i.IsPlaceholder(image)
     local placeholder_image = mw.loadData('Module:InfoboxImage/data').placeholder_image
    image = mw.ustring.gsub(image, "_", " ")
     return placeholder_image[image]
    if mw.ustring.sub(image,1,2) == "[[" then
        image = mw.ustring.sub(image,3)
        image = mw.ustring.gsub(image, "([^|]*)|.*", "%1")
    end
   
    image = stripNamespace(image)
    image = mw.ustring.upper(mw.ustring.sub(image,1,1)) .. mw.ustring.sub(image,2)
 
    -- Carregamento tardio (Lazy Load) para otimização do parsing de tabelas de dados
     local placeholder_images = mw.loadData('Módulo:InfoboxImage/data').placeholder_image
     return placeholder_images[image] or false
end
end


Linha 77: Linha 108:
end
end


-- Esta função interna processa estritamente os argumentos normalizados
-- Main entry point
function i._InfoboxImage(args)
function i.InfoboxImage(frame)
     local image = args["image"]
    -- Intercepta e traduz os argumentos no ponto de entrada
     local args = normalizarArgumentos(frame.args)
      
      
     if isempty(image) then return "" end
     local image = args["image"];
    if image == " " then return image end
      
      
    if isempty(image) then
        return "";
    end
    if image == " " then
        return image;
    end
     if args["suppressplaceholder"] ~= "no" then
     if args["suppressplaceholder"] ~= "no" then
         if i.IsPlaceholder(image) == true then return "" end
         if i.IsPlaceholder(image) == true then
            return "";
        end
     end
     end
      
      
     if string.find(image, "^%[*https?:") then
     if string.find(image, "^%[*https?:") then
        -- Error category.
         return trackingCat("url_image_links")
         return trackingCat("url_image_links")
     end
     end


     if mw.ustring.sub(image,1,2) == "[[" then
     if mw.ustring.sub(image,1,2) == "[[" then
         local cat = ""
        -- search for thumbnail images and add to tracking cat if found
         local cat = "";
         if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then
         if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then
             cat = trackingCat("thumbnail_images")
             cat = trackingCat("thumbnail_images")
         end
         end
         return image .. cat
         return image .. cat;
     elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then
     elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then
         return image
         return image;
     elseif mw.ustring.sub(image,1,1) == "<" then
     elseif mw.ustring.sub(image,1,1) == "<" then
         return image
         return image;
     elseif mw.ustring.sub(image,1,8) == mw.ustring.char(127).."'\"`UNIQ" then
     elseif mw.ustring.sub(image,1,8) == mw.ustring.char(127).."'\"`UNIQ" then
         return image
        -- Found strip marker at begining, so pass don't process at all
         return image;
     else
     else
         local result = ""
         local result = "";
         local page = args["page"]
         local page = args["page"];
         local upright = args["upright"] or ""
         local upright = args["upright"] or ""
         local size = args["size"]
         local size = args["size"];
         local maxsize = args["maxsize"]
         local maxsize = args["maxsize"];
         local sizedefault = args["sizedefault"]
         local sizedefault = args["sizedefault"];
         local alt = args["alt"]
         local alt = args["alt"];
         local link = args["link"]
         local link = args["link"];
         local title = args["title"]
         local title = args["title"];
         local border = args["border"]
         local border = args["border"];
         local thumbtime = args["thumbtime"] or ""
         local thumbtime = args["thumbtime"] or "";
         local center = args["center"]
         local center = args["center"];
         local class = args["class"]
         local class = args["class"];
          
          
         image = stripNamespace(image)
         -- remove prefix if exists
        local allNames = mw.site.namespaces[6].aliases
        allNames[#allNames + 1] = mw.site.namespaces[6].name
        allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
        for i, name in ipairs(allNames) do
            if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
                image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
                break
            end
        end
          
          
         if not isempty(maxsize) then
         if not isempty(maxsize) then
            -- if no sizedefault nor upright, then set to maxsize
             if isempty(sizedefault) and isempty(upright) then
             if isempty(sizedefault) and isempty(upright) then
                 sizedefault = maxsize
                 sizedefault = maxsize
             end
             end
             local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*")) or 0
            -- check to see if size bigger than maxsize
             local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*")) or 0;
             if not isempty(size) then
             if not isempty(size) then
                 local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0
                 local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0;
                 if sizenumber > maxsizenumber and maxsizenumber > 0 then
                 if sizenumber > maxsizenumber and maxsizenumber > 0 then
                     size = maxsize
                     size = maxsize;
                 end
                 end
             end
             end
            -- check to see if upright bigger than maxsize (at default preferred size)
             if not isempty(upright) then
             if not isempty(upright) then
                 local uprightnumber = tonumber(upright) or (upright == "yes" and 0.75) or 0
                 local uprightnumber = tonumber(upright) or (upright == "yes" and 0.75) or 0
Linha 138: Linha 192:
                 end
                 end
             end
             end
        end
        -- add px to size if just a number
        if (tonumber(size) or 0) > 0 then
            size = size .. "px";
        end
        -- add px to sizedefault if just a number
        if (tonumber(sizedefault) or 0) > 0 then
            sizedefault = sizedefault .. "px";
         end
         end
          
          
        if (tonumber(size) or 0) > 0 then size = size .. "px" end
         result = "[[Ficheiro:" .. image;
        if (tonumber(sizedefault) or 0) > 0 then sizedefault = sizedefault .. "px" end
         if not isempty(page) then
       
            result = result .. "|page=" .. page;
         result = "[[Ficheiro:" .. image
         end
         if not isempty(page) then result = result .. "|page=" .. page end
          
         if not isempty(size) then
         if not isempty(size) then
             result = result .. "|" .. size
             result = result .. "|" .. size;
         elseif not isempty(sizedefault) and (isempty(upright) or upright == "1") then
         elseif not isempty(sizedefault) and isempty(upright) then
             result = result .. "|" .. sizedefault
             result = result .. "|" .. sizedefault;
         else
         else
             result = result .. "|frameless"
             result = result .. "|frameless";
        end
        if center == "yes" then
            result = result .. "|center"
         end
         end
       
        if center == "yes" then result = result .. "|center" end
       
        -- Validação Segura de Alt (Garante a checagem de palavras reservadas ANTES de embutir na string final)
         if not isempty(alt) then
         if not isempty(alt) then
             if alt ~= "thumbnail" and alt ~= "thumb" and alt ~= "frameless" and alt ~= "left" and alt ~= "center" and alt ~= "right" and alt ~= "upright" and alt ~= "border" and mw.ustring.match(alt, '^[0-9]*px$', 1) == nil then
             result = result .. "|alt=" .. alt;
                result = result .. "|alt=" .. alt
        end
            end
        if not isempty(link) then
            result = result .. "|link=" .. link;
        end
        if border == "yes" then
            result = result .. "|border";
         end
         end
       
        if not isempty(link) then result = result .. "|link=" .. link end
        if border == "yes" then result = result .. "|border" end
       
         if upright == "yes" then
         if upright == "yes" then
             result = result .. "|upright"
             result = result .. "|upright";
         elseif upright ~= "" then
         elseif upright ~= "" then
             result = result .. "|upright=" .. upright
             result = result .. "|upright=" .. upright;
        end
        if thumbtime ~= "" then
            result = result .. "|thumbtime=" .. thumbtime;
        end
        if not isempty(class) then
            result = result .. "|class=" .. class;
        end
        -- if alt value is a keyword then do not use as a description
        if alt == "thumbnail" or alt == "thumb" or alt == "frameless" or alt == "left" or alt == "center" or alt == "right" or alt == "upright" or alt == "border" or alt == "centro" or alt == "direita" or alt == "esquerda" or mw.ustring.match(alt or "", '^[0-9]*px$', 1) ~= nil then
            alt = nil;
         end
         end
        if thumbtime ~= "" then result = result .. "|thumbtime=" .. thumbtime end
        if not isempty(class) then result = result .. "|class=" .. class end
       
         if not isempty(title) then
         if not isempty(title) then
             if mw.ustring.match(mw.getCurrentFrame():preprocess(title), 'UNIQ%-%-templatestyles', 1) == nil then
            -- does title param contain any templatestyles? If yes then set to blank.
                 result = result .. "|" .. title
             if mw.ustring.match(frame:preprocess(title), 'UNIQ%-%-templatestyles', 1) ~= nil then
                 title = nil;
             end
             end
         end
         end
         result = result .. "]]"
        if not isempty(title) then
            result = result .. "|" .. title;
        end
         result = result .. "]]";
          
          
         return result
         return result;
    end
end
 
-- Porta de entrada oficial chamada pela Predefinição
function i.InfoboxImage(frame)
    local origArgs = frame.args
    local normalizedArgs = {}
   
    -- Mapeamento/Tradução dos parâmetros para o motor interno
    normalizedArgs["image"] = origArgs["image"] or origArgs["imagem"]
    normalizedArgs["page"] = origArgs["page"] or origArgs["página"]
    normalizedArgs["size"] = origArgs["size"] or origArgs["tamanho"]
    normalizedArgs["maxsize"] = origArgs["maxsize"] or origArgs["tamanhomáx"]
    normalizedArgs["sizedefault"] = origArgs["sizedefault"] or origArgs["tamanhopadrão"]
    normalizedArgs["alt"] = origArgs["alt"]
    normalizedArgs["link"] = origArgs["link"] or origArgs["ligação"]
    normalizedArgs["title"] = origArgs["title"] or origArgs["título"]
    normalizedArgs["thumbtime"] = origArgs["thumbtime"] or origArgs["tempominiatura"]
    normalizedArgs["class"] = origArgs["class"] or origArgs["classe"]
   
    -- Normalização robusta com Módulo:Yesno para flags booleanas
    local suppress = origArgs["suppressplaceholder"] or origArgs["suprimirsubstituto"]
    if yesno(suppress, true) then
        normalizedArgs["suppressplaceholder"] = "yes"
    else
        normalizedArgs["suppressplaceholder"] = "no"
    end
   
    if yesno(origArgs["border"] or origArgs["borda"]) then
        normalizedArgs["border"] = "yes"
    end
   
    -- Aceita 'sim', 'yes', 'centro' ou 'center'
    local centerArg = origArgs["center"] or origArgs["centro"]
    if yesno(centerArg) or centerArg == "centro" or centerArg == "center" then
        normalizedArgs["center"] = "yes"
     end
     end
    -- Normalização do upright (Trata se o usuário passar 'sim', mapeando para o padrão 'yes')
    local uprightArg = origArgs["upright"]
    if yesno(uprightArg) then
        normalizedArgs["upright"] = "yes"
    else
        normalizedArgs["upright"] = uprightArg or ""
    end
   
    return i._InfoboxImage(normalizedArgs)
end
end


return i
return i;

Edição atual tal como às 05h40min de 6 de setembro de 2026

-- Inputs: -- image - Can either be a bare filename (with or without the File:/Image: prefix) or a fully formatted image link -- page - page to display for multipage images (DjVu) -- size - size to display the image -- maxsize - maximum size for image -- sizedefault - default size to display the image if size param is blank -- alt - alt text for image -- title - title text for image -- border - set to yes if border -- center - set to yes, if the image has to be centered -- upright - upright image param -- suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it -- link - page to visit when clicking on image -- class - HTML classes to add to the image -- Outputs: -- Formatted image. -- More details available at the "Module:InfoboxImage/doc" page

local i = {}

-- List of placeholder images and tracking categories stored in Module:InfoboxImage/data -- Other constants: -- the system-wide default thumbnail size (in px) local defaultThumbnailSize = 250

-- Mapeamento de traduções em português para inglês local mapaParametros = {

   imagem = "image",
   ["página"] = "page",
   tamanho = "size",
   ["tamanhomáx"] = "maxsize",
   ["tamanhopadrão"] = "sizedefault",
   ["ligação"] = "link",
   ["título"] = "title",
   borda = "border",
   tempominiatura = "thumbtime",
   centro = "center",
   classe = "class",
   suprimirsubstituto = "suppressplaceholder"

}

-- Função auxiliar interceptadora local function normalizarArgumentos(argsOriginal)

   local args = {}
   
   -- Copia primeiro os parâmetros em inglês
   for k, v in pairs(argsOriginal) do
       args[k] = v
   end
   
   -- Traduz e insere os parâmetros em português se a chave em inglês estiver vazia
   for pt, en in pairs(mapaParametros) do
       if (args[en] == nil or args[en] == "") and argsOriginal[pt] then
           args[en] = argsOriginal[pt]
       end
   end
   
   -- Normaliza valores booleanos traduzidos
   if args.suppressplaceholder == "não" or args.suppressplaceholder == "nao" then
       args.suppressplaceholder = "no"
   end
   
   return args

end

-- If page is not a user page, return tracking category. Else return empty. local function trackingCat(cat)

   local ns = mw.title.getCurrentTitle().nsText:lower()
   local categories = mw.loadData('Module:InfoboxImage/data').categories
   return (ns ~= 'user' and ns ~= 'user talk' and categories[cat]) or ""

end

-- Determine whether image is a placeholder function i.IsPlaceholder(image)

   -- change underscores to spaces
   image = mw.ustring.gsub(image, "_", " ");
   assert(image ~= nil, 'mw.ustring.gsub(image, "_", " ") must not return nil')
   -- if image starts with [[then remove that and anything after |
   if mw.ustring.sub(image,1,2) == "[[" then
       image = mw.ustring.sub(image,3);
       image = mw.ustring.gsub(image, "([^|]*)|.*", "%1");
       assert(image ~= nil, 'mw.ustring.gsub(image, "([^|]*)|.*", "%1") must not return nil')
   end
   -- Trim spaces
   image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
   assert(image ~= nil, "mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1') must not return nil")
   -- remove prefix if exists
   local allNames = mw.site.namespaces[6].aliases
   allNames[#allNames + 1] = mw.site.namespaces[6].name
   allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
   for i, name in ipairs(allNames) do
       if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
           image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
           break
       end
   end
   -- Trim spaces
   image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
   -- capitalise first letter
   image = mw.ustring.upper(mw.ustring.sub(image,1,1)) .. mw.ustring.sub(image,2);
   local placeholder_image = mw.loadData('Module:InfoboxImage/data').placeholder_image
   return placeholder_image[image]

end

local function isempty(x)

   return (not x) or x == ""

end

-- Main entry point function i.InfoboxImage(frame)

   -- Intercepta e traduz os argumentos no ponto de entrada
   local args = normalizarArgumentos(frame.args)
   
   local image = args["image"];
   
   if isempty(image) then
       return "";
   end
   if image == " " then
       return image;
   end
   if args["suppressplaceholder"] ~= "no" then
       if i.IsPlaceholder(image) == true then
           return "";
       end
   end
   
   if string.find(image, "^%[*https?:") then
       -- Error category.
       return trackingCat("url_image_links")
   end
   if mw.ustring.sub(image,1,2) == "[[" then
       -- search for thumbnail images and add to tracking cat if found
       local cat = "";
       if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then
           cat = trackingCat("thumbnail_images")
       end
       return image .. cat;
   elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then
       return image;
   elseif mw.ustring.sub(image,1,1) == "<" then
       return image;
   elseif mw.ustring.sub(image,1,8) == mw.ustring.char(127).."'\"`UNIQ" then
       -- Found strip marker at begining, so pass don't process at all
       return image;
   else
       local result = "";
       local page = args["page"];
       local upright = args["upright"] or ""
       local size = args["size"];
       local maxsize = args["maxsize"];
       local sizedefault = args["sizedefault"];
       local alt = args["alt"];
       local link = args["link"];
       local title = args["title"];
       local border = args["border"];
       local thumbtime = args["thumbtime"] or "";
       local center = args["center"];
       local class = args["class"];
       
       -- remove prefix if exists
       local allNames = mw.site.namespaces[6].aliases
       allNames[#allNames + 1] = mw.site.namespaces[6].name
       allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
       for i, name in ipairs(allNames) do
           if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
               image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
               break
           end
       end
       
       if not isempty(maxsize) then
           -- if no sizedefault nor upright, then set to maxsize
           if isempty(sizedefault) and isempty(upright) then
               sizedefault = maxsize
           end
           -- check to see if size bigger than maxsize
           local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*")) or 0;
           if not isempty(size) then
               local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0;
               if sizenumber > maxsizenumber and maxsizenumber > 0 then
                   size = maxsize;
               end
           end
           -- check to see if upright bigger than maxsize (at default preferred size)
           if not isempty(upright) then
               local uprightnumber = tonumber(upright) or (upright == "yes" and 0.75) or 0
               if uprightnumber*defaultThumbnailSize > maxsizenumber and maxsizenumber > 0 then
                   upright = tostring(maxsizenumber/defaultThumbnailSize)
               end
           end
       end
       -- add px to size if just a number
       if (tonumber(size) or 0) > 0 then
           size = size .. "px";
       end
       -- add px to sizedefault if just a number
       if (tonumber(sizedefault) or 0) > 0 then
           sizedefault = sizedefault .. "px";
       end
       
       result = "[[Ficheiro:" .. image;
       if not isempty(page) then
           result = result .. "|page=" .. page;
       end
       if not isempty(size) then
           result = result .. "|" .. size;
       elseif not isempty(sizedefault) and isempty(upright) then
           result = result .. "|" .. sizedefault;
       else
           result = result .. "|frameless";
       end
       if center == "yes" then
           result = result .. "|center"
       end
       if not isempty(alt) then
           result = result .. "|alt=" .. alt;
       end
       if not isempty(link) then
           result = result .. "|link=" .. link;
       end
       if border == "yes" then
           result = result .. "|border";
       end
       if upright == "yes" then
           result = result .. "|upright";
       elseif upright ~= "" then
           result = result .. "|upright=" .. upright;
       end
       if thumbtime ~= "" then
           result = result .. "|thumbtime=" .. thumbtime;
       end
       if not isempty(class) then
           result = result .. "|class=" .. class;
       end
       -- if alt value is a keyword then do not use as a description
       if alt == "thumbnail" or alt == "thumb" or alt == "frameless" or alt == "left" or alt == "center" or alt == "right" or alt == "upright" or alt == "border" or alt == "centro" or alt == "direita" or alt == "esquerda" or mw.ustring.match(alt or "", '^[0-9]*px$', 1) ~= nil then
           alt = nil;
       end
       if not isempty(title) then
           -- does title param contain any templatestyles? If yes then set to blank.
           if mw.ustring.match(frame:preprocess(title), 'UNIQ%-%-templatestyles', 1) ~= nil then
               title = nil;
           end
       end
       if not isempty(title) then
           result = result .. "|" .. title;
       end
       result = result .. "]]";
       
       return result;
   end

end

return i;