Editing Module:Expanded infobox image
Jump to navigation
Jump to search
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 3: | Line 3: | ||
local value = mw.text.trim(frame.args[1] or '') | local value = mw.text.trim(frame.args[1] or '') | ||
if value == '' then return '' end | if value == '' then return '' end | ||
local width = tonumber(frame.args.width) or 300 | |||
if value:find( | if width < 1 or width > 2000 then width = 300 end | ||
return | local expanded = mw.text.unstrip(value) | ||
if expanded:find('class="gallery', 1, true) then | |||
local tabs = {} | |||
for box in expanded:gmatch('<li class="gallerybox"(.-)</li>') do | |||
local url = box:match('href="([^"]+)"') | |||
local label = box:match('<div class="gallerytext">(.-)</div>') | |||
local file = url and mw.uri.decode(url):match('/[Ff]ile:(.+)') | |||
if not file then return value end | |||
file = mw.text.decode(file):gsub('_', ' ') | |||
label = mw.text.trim(mw.text.decode((label or ''):gsub('<[^>]+>', ''))) | |||
label = label:gsub('[\r\n=|]', ' ') | |||
if label == '' then label = 'Image ' .. (#tabs + 1) end | |||
tabs[#tabs + 1] = label .. '=\n[[File:' .. file .. '|' .. math.floor(width) .. 'px]]' | |||
end | |||
if #tabs > 1 then | |||
return '<div class="expanded-profile-image-tabs">' .. frame:extensionTag('tabber', table.concat(tabs, '\n|-|\n')) .. '</div>' | |||
end | |||
end | end | ||
if value:find(string.char(127), 1, true) or value:find('[[', 1, true) or value:find('<', 1, true) then return value end | |||
value = value:gsub('^[Ff][Ii][Ll][Ee]:', ''):gsub('^[Ii][Mm][Aa][Gg][Ee]:', '') | value = value:gsub('^[Ff][Ii][Ll][Ee]:', ''):gsub('^[Ii][Mm][Aa][Gg][Ee]:', '') | ||
if mw.text.trim(value) == '' then return '' end | if mw.text.trim(value) == '' then return '' end | ||
return '[[File:' .. value .. '|' .. math.floor(width) .. 'px]]' | return '[[File:' .. value .. '|' .. math.floor(width) .. 'px]]' | ||
end | end | ||
return p | return p | ||