Module:Multiple image: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(Add multiple image module)
 
(updating to the current version on wikipedia)
 
Line 7: Line 7:
local function isnotempty(s)
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end

local function removepx(s)
return tostring(s or ''):match('^(.*)[Pp][Xx]%s*$') or s
end
end


Line 14: Line 18:
return tonumber(w), tonumber(h)
return tonumber(w), tonumber(h)
end
end
local file = s and mw.title.new('File:' .. mw.uri.decode(s, 'WIKI'))
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}
file = file and file.file or {width = 0, height = 0}
w = tonumber(file.width) or 0
w = tonumber(file.width) or 0
Line 22: Line 26:
end
end


local function renderImageCell(image, width, height, link, alt, thumbtime, caption, textalign, istyle)
local function renderImageCell(image, width, height, link, alt, thumbtime, caption, textalign, istyle, border)
local root = mw.html.create('')
local root = mw.html.create('')


Line 30: Line 34:
local thumbtimestr = ''
local thumbtimestr = ''


if widthstr == '|-nanpx' then
widthstr = ''
end
if isnotempty( thumbtime ) then
if isnotempty( thumbtime ) then
thumbtimestr = '|thumbtime=' .. thumbtime
thumbtimestr = '|thumbtime=' .. thumbtime
Line 35: Line 42:


local imagediv = root:tag('div')
local imagediv = root:tag('div')
imagediv:addClass('thumbimage')
imagediv:addClass((border ~= 'infobox') and 'thumbimage' or nil)
imagediv:cssText(istyle)
imagediv:cssText(istyle)
if( height ) then
if( height ) then
Line 44: Line 51:
if isnotempty(caption) then
if isnotempty(caption) then
local captiondiv = root:tag('div')
local captiondiv = root:tag('div')
captiondiv:addClass('thumbcaption')
captiondiv:addClass((border ~= 'infobox') and 'thumbcaption' or nil)
captiondiv:css('clear', 'left')
if isnotempty(textalign) then
if isnotempty(textalign) then
captiondiv:css('text-align', textalign)
captiondiv:addClass('text-align-' .. textalign)
end
end
captiondiv:wikitext(caption)
captiondiv:wikitext(caption)
Line 90: Line 96:
local pargs = frame:getParent().args
local pargs = frame:getParent().args
local args = frame.args
local args = frame.args
local width = pargs['width'] or ''
local width = removepx(pargs['width'] or '')
local dir = pargs['direction'] or ''
local dir = pargs['direction'] or ''
local border = pargs['border'] or args['border'] or ''
local border = pargs['border'] or args['border'] or ''
local align = pargs['align'] or args['align'] or (border == 'infobox' and 'center' 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 capalign = pargs['caption_align'] or args['caption_align'] or ''
local totalwidth = pargs['total_width'] or args['total_width'] or ''
local totalwidth = removepx(pargs['total_width'] or args['total_width'] or '')
local imgstyle = pargs['image_style'] or args['image_style']
local imgstyle = pargs['image_style'] or args['image_style']
local header = pargs['header'] or pargs['title'] or ''
local header = pargs['header'] or pargs['title'] or ''
Line 215: Line 221:
root:addClass('thumb')
root:addClass('thumb')
root:addClass('tmulti')
root:addClass('tmulti')
-- root:addClass('tmulti-sandbox')
root:addClass(thumbclass[align] or 'tright')
root:addClass(thumbclass[align] or 'tright')


if( align == 'center' or align == 'centre' ) then
if( align == 'center' or align == 'centre' ) then
root:addClass('center')
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
end
if( bg ~= '' ) then
if( bg ~= '' ) then
Line 231: Line 232:


local div = root:tag('div')
local div = root:tag('div')
div:addClass('thumbinner')
div:addClass((border ~= 'infobox') and 'thumbinner multiimageinner' or 'multiimageinner')
div:css('width', tostring(bodywidth) .. 'px')
div:css('width', tostring(bodywidth) .. 'px')
:css('max-width', tostring(bodywidth) .. 'px')
:css('max-width', tostring(bodywidth) .. 'px')
Line 243: Line 244:
if( isnotempty(header) ) then
if( isnotempty(header) ) then
div:tag('div')
div:tag('div')
:css('clear', 'both')
:addClass('trow')
:css('font-weight', 'bold')
:tag('div')
:addClass('theader')
:css('text-align', pargs['header_align'] or 'center')
:css('background-color', pargs['header_background'] or 'transparent')
:css('text-align', pargs['header_align'])
:css('background-color', pargs['header_background'])
:wikitext(header)
:wikitext(header)
end
end
-- loop through the images
-- loop through the images
local k = 0
local k = 0
for r=1,rowcount do
for r=1,rowcount do
local rowdiv = div:tag('div'):addClass('trow');
for j=1,perrow[r] do
for j=1,perrow[r] do
k = k + 1
k = k + 1
if( k <= imagecount ) then
if( k <= imagecount ) then
local imagediv = div:tag('div')
local imagediv = rowdiv:tag('div')
imagediv:addClass('tsingle')
imagediv:addClass('tsingle')
if dir ~= 'vertical' then
imagediv:css('float', 'left')
end
if bg ~= '' then
if bg ~= '' then
imagediv:css('background-color', bg);
imagediv:css('background-color', bg);
end
end
imagediv:css('margin', '1px')
if ((imagegap > 1) and (j < perrow[r])) then
if ((imagegap > 1) and (j < perrow[r])) then
imagediv:css('margin-right', tostring(imagegap) .. 'px')
imagediv:css('margin-right', tostring(imagegap) .. 'px')
Line 274: Line 273:
imagediv:wikitext(renderImageCell(img, w, heights[k],
imagediv:wikitext(renderImageCell(img, w, heights[k],
pargs['link' .. i], pargs['alt' .. i],
pargs['link' .. i], pargs['alt' .. i],
pargs['thumbtime' .. i], pargs['caption' .. i], capalign, imgstyle))
pargs['thumbtime' .. i], pargs['caption' .. i], capalign, imgstyle, border))
end
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
end
end
-- add the footer
-- add the footer
if( isnotempty(footer) ) then
if( isnotempty(footer) ) then
local falign = string.lower(pargs['footer_align'] or args['footer_align'] or '')
falign = (falign == 'centre') and 'center' or falign
div:tag('div')
div:tag('div')
:addClass('thumbcaption')
:addClass('trow')
:css('clear', 'left')
:css('display', (falign ~= '') and 'flow-root' or 'flex')
: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', (falign ~= '') and falign or nil)
:wikitext(footer)
:css('background-color', pargs['footer_background'])
:wikitext(footer)
end
end
return tostring(root)
return tostring(root)
Line 301: Line 299:
nonautoscaledimages = false
nonautoscaledimages = false


return frame:extensionTag {name = 'templatestyles', args = {src = 'Multiple image/styles.css', wrapper = ".tmulti"}}
return renderMultipleImages( frame )
.. renderMultipleImages( frame )
.. (autoscaledimages and '[[Category:Pages using multiple image with auto scaled images]]' or '')
.. (autoscaledimages and '[[Category:Pages using multiple image with auto scaled images]]' or '')
.. (nonautoscaledimages and '[[Category:Pages using multiple image with manual scaled images]]' or '')
.. (nonautoscaledimages and '[[Category:Pages using multiple image with manual scaled images]]' or '')