Module:Wide image
Appearance
![]() | This module depends on the following other modules: |
Implements {{wide image}} and {{panorama}}
-- This module implements [[template:wide image]]
local p = {}
local function getwidth(s, w)
w = mw.ustring.gsub(w or '0', '^%s*(%d+)%s*[Pp][Xx]*%s*$', '%1')
w = tonumber(w) or 0
if w > 0 then
return w
end
local file = s and mw.title.new('File:' .. mw.uri.decode(mw.ustring.gsub(s,'%|.*$',''), 'WIKI'))
file = file and file.file or {width = 0}
w = tonumber(file.width) or 0
return w
end
local function getimage(s, w, a, c, rtl)
if c == 'thumb' or c == 'thumbnail' or c == 'frame' or c == 'border' then
c = s
elseif rtl and c ~= '' then
c = '‪' .. c .. '‬'
end
return '[[File:' .. (s or '') .. '|' .. (w or '') .. '|alt=' .. (a or '')
.. '|' .. mw.text.unstrip(c or '') .. ']]'
end
function wideimage(args)
if args[1] then
local r = mw.html.create('div')
local float = args[5] or ''
local iwidth = getwidth(args[1] or '', args[2] or '0')
local rtl = args['dir'] and args['dir'] == 'rtl' or nil
local noborder = args['border'] and args['border'] == 'no' or nil
if noborder then
if float == 'left' then
r:addClass('floatleft')
elseif float == 'right' then
r:addClass('floatright')
elseif float == 'none' then
r:addClass('floatnone')
else -- center is default
r:addClass('floatnone')
r:css('margin', '0 auto')
r:css('overflow', 'hidden')
end
else
r:addClass('thumb')
if float == 'left' then
r:addClass('tleft')
elseif float == 'right' then
r:addClass('tright')
elseif float == 'none' then
r:addClass('tnone')
else -- center is default
r:addClass('tnone')
r:css('margin', '0 auto')
r:css('overflow', 'hidden')
end
end
r:css('width', args[4] or 'auto')
r:css('max-width', noborder and (iwidth .. 'px') or ((iwidth + 8) .. 'px'))
local d = noborder and r or r:tag('div'):addClass('thumbinner')
d:tag('div')
:addClass('noresize')
:css('overflow', 'auto')
:css('direction', rtl and 'rtl' or nil)
:wikitext(getimage(args[1],args[2],args['alt'],args[3] or '',rtl))
if args[3] then
d = d:tag('div')
:addClass('thumbcaption')
:css('text-align', args['align-cap'])
if noborder == nil then
d:tag('div')
:addClass('magnify')
:wikitext('[[:File:' .. args[1] .. '| ]]')
end
d:wikitext(args[3])
end
return tostring(r)
end
return ''
end
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
return wideimage(getArgs(frame))
end
return p