https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AImageStackPopup
Module:ImageStackPopup - Revision history
2025-06-06T06:36:12Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.4
https://en.wikipedia.org/w/index.php?title=Module:ImageStackPopup&diff=1226582846&oldid=prev
Doc James: Copied from MDWiki https://mdwiki.org/w/index.php?title=Module:ImageStackPopup&action=edit
2024-05-31T15:37:42Z
<p>Copied from MDWiki https://mdwiki.org/w/index.php?title=Module:ImageStackPopup&action=edit</p>
<p><b>New page</b></p><div>local p = {}<br />
<br />
function p.image( frame )<br />
math.randomseed(tonumber(mw.getContentLanguage():formatDate( "U" ))*10000 + os.clock()*10000)<br />
local args = frame:getParent().args<br />
local popupConfig = {}<br />
local caption = ''<br />
popupConfig.loop = args.loop == "yes"<br />
if tonumber( args.start ) then<br />
popupConfig.start = tonumber( args.start )<br />
else<br />
popupConfig.start = 1<br />
end<br />
if tonumber( args.width ) then<br />
popupConfig.width = tonumber( args.width )<br />
end<br />
if tonumber( args.height ) then<br />
popupConfig.height = tonumber( args.height )<br />
end<br />
popupConfig.list = args.list<br />
if args['noregisterimages'] == nil then<br />
-- Register this as a dependency so that this page shows up as using all the images on the list page<br />
frame:expandTemplate{ title = ':' .. args.list }<br />
end<br />
-- If we don't want to transclude for performance, maybe we could at least link<br />
-- however links need to actually be output on the page to register them.<br />
<br />
if args.caption then<br />
popupConfig.caption = "imagestackpopup-caption-" .. math.random()<br />
caption = tostring( mw.html.create( 'div' )<br />
:attr( 'id', popupConfig.caption )<br />
:attr( 'style', 'display: none' )<br />
:wikitext( args.caption )<br />
:done() )<br />
end<br />
if args.title then<br />
popupConfig.title = args.title<br />
end<br />
<br />
return tostring( mw.html.create( 'div' )<br />
:attr( 'class', 'ImageStackPopup' )<br />
:attr( 'data-imagestackpopup-config', mw.text.jsonEncode( { popupConfig } ) )<br />
:wikitext( args.file ) )<br />
.. caption<br />
<br />
end<br />
<br />
<br />
function p.gallery( frame )<br />
-- Seems like math.random is always seeded with 0 :(<br />
math.randomseed(tonumber(mw.getContentLanguage():formatDate( "U" ))*10000 + os.clock()*10000)<br />
local args = frame:getParent().args<br />
local reuseImageCaption = args.reuse_image_caption ~= nil<br />
local title = args["popup-title"]<br />
local captionId = nil<br />
local captionText = ''<br />
local galleryContents = ''<br />
local optionsArray = {}<br />
local galleryArgs = {}<br />
<br />
local galleryAttr = { "mode", "widths", "heights", "perrow", "caption", "showfilename", "showthumbnail", "id", "title", "class", "lang", "dir" }<br />
for i, j in ipairs( galleryAttr ) do<br />
galleryArgs[j] = args[j]<br />
end<br />
<br />
if args['popup-caption'] then<br />
captionId = 'imagestackpopup-caption-' .. math.random()<br />
captionText = tostring(<br />
mw.html.create( 'div' )<br />
:attr( 'style', 'display:none' )<br />
:attr( 'id', captionId )<br />
:wikitext( args['popup-caption'] )<br />
)<br />
end<br />
<br />
for row in mw.text.gsplit( args.gallery, "\n", true ) do<br />
local galleryRow = ''<br />
local popupOptions = { title = title, caption = captionId }<br />
for part in mw.text.gsplit( row, "!", true ) do<br />
equalSplit = mw.text.split( part, '=', true )<br />
if #equalSplit <= 1 then<br />
-- be sure this really is a caption.<br />
if galleryRow ~= '' and<br />
reuseImageCaption and<br />
#part > 8 and<br />
string.find( part, " ", 1, true )<br />
then<br />
local captionId = 'imagestackpopup-caption-' .. math.random()<br />
local wrappedPart = tostring( mw.html.create( 'span' )<br />
:attr( 'id', captionId )<br />
:wikitext( part )<br />
)<br />
popupOptions.caption = captionId<br />
galleryRow = galleryRow .. wrappedPart .. '|'<br />
else<br />
galleryRow = galleryRow .. part .. '|'<br />
end<br />
else<br />
if equalSplit[1] == 'popup-width' then<br />
popupOptions.width = tonumber(equalSplit[2])<br />
elseif equalSplit[1] == 'popup-height' then<br />
popupOptions.height = tonumber(equalSplit[2])<br />
elseif equalSplit[1] == 'popup-loop' then<br />
popupOptions.loop = equalSplit[2] ~= ''<br />
elseif equalSplit[1] == 'popup-start' then<br />
popupOptions.start = tonumber(equalSplit[2])<br />
elseif equalSplit[1] == 'popup-caption' then<br />
local captionIdForImg = 'imagestackpopup-caption-' .. math.random()<br />
captionText = captionText .. tostring( mw.html.create( 'div' )<br />
:attr( 'id', captionIdForImg )<br />
:css( 'display', 'none' )<br />
:wikitext( table.concat( equalSplit, '=', 2 ) )<br />
)<br />
popupOptions.caption = captionIdForImg<br />
elseif equalSplit[1] == 'popup-title' then<br />
popupOptions.title = table.concat( equalSplit, '=', 2 )<br />
elseif equalSplit[1] == 'popup-list' then<br />
popupOptions.list = table.concat( equalSplit, '=', 2 )<br />
if args['noregisterimages'] == nil then<br />
-- Register this as a dependency so that this page shows up as using all the images on the list page<br />
frame:expandTemplate{ title = ':' .. table.concat( equalSplit, '=', 2 ) }<br />
end<br />
else<br />
galleryRow = galleryRow .. part .. '|'<br />
end<br />
<br />
end<br />
end<br />
if string.sub( galleryRow, -1 ) == '|' then<br />
galleryRow = string.sub( galleryRow, 1, -2 )<br />
end<br />
galleryContents = galleryContents .. galleryRow .. "\n"<br />
optionsArray[#optionsArray+1] = popupOptions<br />
end<br />
return tostring( mw.html.create( 'div' )<br />
:attr( 'class', 'ImageStackPopup' )<br />
:attr( 'data-imagestackpopup-config', mw.text.jsonEncode( optionsArray ) )<br />
:wikitext( frame:extensionTag( 'gallery', galleryContents, galleryArgs ) )<br />
) .. captionText<br />
end<br />
<br />
<br />
return p</div>
Doc James