Module:Multiple image: Difference between revisions

updating to the current version on wikipedia
(Add multiple image module)
 
(updating to the current version on wikipedia)
 
Line 7:
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end
 
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 = ''
end
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)
captiondiv:css('clear', 'left')
if isnotempty(textalign) then
captiondiv:cssaddClass('text-align-', .. textalign)
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
if( pargs['margin_top'] or args['margin_top']) then
root:css('margin-top', pargs['margin_top'] or args['margin_top'])
end
if( pargs['margin_bottom'] or args['margin_bottom']) then
root:css('margin-bottom', pargs['margin_bottom'] or args['margin_bottom'])
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')
:cssaddClass('clear', 'bothtrow')
:csstag('font-weight', 'bolddiv')
:addClass('theader')
:css('text-align', pargs['header_align'] or 'center')
:css('backgroundtext-coloralign', pargs['header_backgroundheader_align'] or 'transparent')
:css('background-color', pargs['footer_backgroundheader_background'] or 'transparent')
: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 = divrowdiv:tag('div')
imagediv:addClass('tsingle')
if dir ~= 'vertical' then
imagediv:css('float', 'left')
end
if bg ~= '' then
imagediv:css('background-color', bg);
end
imagediv:css('margin', '1px')
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
end
-- only float content gives a parent height:0, so add a clearing div
if dir ~= 'vertical' then
div:tag('div')
:css('clear', 'left')
end
end
-- add the footer
if( isnotempty(footer) ) then
:css('text-align',local falign = string.lower(pargs['footer_align'] or args['footer_align'] or 'left')
falign = (falign == 'centre') and 'center' or falign
div:tag('div')
:addClass('thumbcaptiontrow')
:css('cleardisplay', (falign ~= '') and 'flow-root' or 'leftflex')
div:tag('div')
: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')
:css('text-align', pargs[(falign ~= 'header_align']) and falign or 'center'nil)
: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"}}
return .. renderMultipleImages( frame )
.. (autoscaledimages and '[[Category:Pages using multiple image with auto scaled images]]' or '')
.. (nonautoscaledimages and '[[Category:Pages using multiple image with manual scaled images]]' or '')