3,615
edits
(Add multiple image module) |
(updating to the current version on wikipedia) |
||
Line 7:
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
local function removepx(s)
return tostring(s or ''):match('^(.*)[Pp][Xx]%s*$') or s
end
Line 14 ⟶ 18:
return tonumber(w), tonumber(h)
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, height = 0}
w = tonumber(file.width) or 0
Line 22 ⟶ 26:
end
local function renderImageCell(image, width, height, link, alt, thumbtime, caption, textalign, istyle, border)
local root = mw.html.create('')
Line 30 ⟶ 34:
local thumbtimestr = ''
if widthstr == '|-nanpx' then
widthstr = ''
if isnotempty( thumbtime ) then
thumbtimestr = '|thumbtime=' .. thumbtime
Line 35 ⟶ 42:
local imagediv = root:tag('div')
imagediv:addClass((border ~= 'infobox') and 'thumbimage' or nil)
imagediv:cssText(istyle)
if( height ) then
Line 44 ⟶ 51:
if isnotempty(caption) then
local captiondiv = root:tag('div')
captiondiv:addClass((border ~= 'infobox') and 'thumbcaption' or nil)
if isnotempty(textalign) then
captiondiv:
end
captiondiv:wikitext(caption)
Line 90 ⟶ 96:
local pargs = frame:getParent().args
local args = frame.args
local width = removepx(pargs['width'] or '')
local dir = pargs['direction'] or ''
local border = pargs['border'] or args['border'] or ''
local align = pargs['align'] or args['align'] or (border == 'infobox' and 'center' or '')
local capalign = pargs['caption_align'] or args['caption_align'] or ''
local totalwidth = removepx(pargs['total_width'] or args['total_width'] or '')
local imgstyle = pargs['image_style'] or args['image_style']
local header = pargs['header'] or pargs['title'] or ''
Line 215 ⟶ 221:
root:addClass('thumb')
root:addClass('tmulti')
-- root:addClass('tmulti-sandbox')
root:addClass(thumbclass[align] or 'tright')
if( align == 'center' or align == 'centre' ) then
root:addClass('center')
▲ end
▲ end
end
if( bg ~= '' ) then
Line 231 ⟶ 232:
local div = root:tag('div')
div:addClass((border ~= 'infobox') and 'thumbinner multiimageinner' or 'multiimageinner')
div:css('width', tostring(bodywidth) .. 'px')
:css('max-width', tostring(bodywidth) .. 'px')
Line 243 ⟶ 244:
if( isnotempty(header) ) then
div:tag('div')
:
:
:addClass('theader')
:css('text-align', pargs['header_align'] or 'center')▼
:css('
:wikitext(header)
end
-- loop through the images
local k = 0
for r=1,rowcount do
local rowdiv = div:tag('div'):addClass('trow');
for j=1,perrow[r] do
k = k + 1
if( k <= imagecount ) then
local imagediv =
imagediv:addClass('tsingle')
if bg ~= '' then
imagediv:css('background-color', bg);
end
if ((imagegap > 1) and (j < perrow[r])) then
imagediv:css('margin-right', tostring(imagegap) .. 'px')
Line 274 ⟶ 273:
imagediv:wikitext(renderImageCell(img, w, heights[k],
pargs['link' .. i], pargs['alt' .. i],
pargs['thumbtime' .. i], pargs['caption' .. i], capalign, imgstyle, border))
end
div:tag('div')▼
end
end
-- add the footer
if( isnotempty(footer) ) then
falign = (falign == 'centre') and 'center' or falign
div:tag('div')
:addClass('
:css('
▲ :css('text-align', pargs['footer_align'] or args['footer_align'] or 'left')
:addClass((border ~= 'infobox') and 'thumbcaption' or nil)
▲ :css('background-color', pargs['footer_background'] or 'transparent')
:wikitext(footer)▼
:css('background-color', pargs['footer_background'])
▲ :wikitext(footer)
end
return tostring(root)
Line 301 ⟶ 299:
nonautoscaledimages = false
return frame:extensionTag {name = 'templatestyles', args = {src = 'Multiple image/styles.css', wrapper = ".tmulti"}}
.. (autoscaledimages and '[[Category:Pages using multiple image with auto scaled images]]' or '')
.. (nonautoscaledimages and '[[Category:Pages using multiple image with manual scaled images]]' or '')
|