Module:Filestrip

-- -- Lua module that changes file links in infoboxes -- to proper infobox gallery items local p = {}

local REGEX = '%s-%[+[^:]+:([^|%]]*)[^%]]-%]+%s-'

local function replacer(captures) local s = '' if p.count > 0 then s = ' (' .. p.count .. ')\n' end s = s .. captures .. '|' .. p.caption p.count = p.count + 1 return s end

local function replacer2(capture) p.num = p.num - 1 if p.num ~= 0 then return '' else return capture end end

function p.strip(frame) local file = mw.text.trim(frame.args[1] or '') p.caption = frame.args[2] or '' p.count = 0 local newfile = file:gsub(REGEX, replacer) if p.count > 1 then -- add last number newfile = newfile .. ' (' .. p.count .. ')' end return newfile end

function p.imagenum(frame) local file = mw.text.trim(frame.args[1] or '') p.num = tonumber(frame.args[2] or '1') local newfile, count = file:gsub(REGEX, replacer2) if p.num > 1 and count == 0 then return '' end return newfile end

return p