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&amp;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( &quot;U&quot; ))*10000 + os.clock()*10000)<br /> local args = frame:getParent().args<br /> local popupConfig = {}<br /> local caption = &#039;&#039;<br /> popupConfig.loop = args.loop == &quot;yes&quot;<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[&#039;noregisterimages&#039;] == 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 = &#039;:&#039; .. args.list }<br /> end<br /> -- If we don&#039;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 = &quot;imagestackpopup-caption-&quot; .. math.random()<br /> caption = tostring( mw.html.create( &#039;div&#039; )<br /> :attr( &#039;id&#039;, popupConfig.caption )<br /> :attr( &#039;style&#039;, &#039;display: none&#039; )<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( &#039;div&#039; )<br /> :attr( &#039;class&#039;, &#039;ImageStackPopup&#039; )<br /> :attr( &#039;data-imagestackpopup-config&#039;, 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( &quot;U&quot; ))*10000 + os.clock()*10000)<br /> local args = frame:getParent().args<br /> local reuseImageCaption = args.reuse_image_caption ~= nil<br /> local title = args[&quot;popup-title&quot;]<br /> local captionId = nil<br /> local captionText = &#039;&#039;<br /> local galleryContents = &#039;&#039;<br /> local optionsArray = {}<br /> local galleryArgs = {}<br /> <br /> local galleryAttr = { &quot;mode&quot;, &quot;widths&quot;, &quot;heights&quot;, &quot;perrow&quot;, &quot;caption&quot;, &quot;showfilename&quot;, &quot;showthumbnail&quot;, &quot;id&quot;, &quot;title&quot;, &quot;class&quot;, &quot;lang&quot;, &quot;dir&quot; }<br /> for i, j in ipairs( galleryAttr ) do<br /> galleryArgs[j] = args[j]<br /> end<br /> <br /> if args[&#039;popup-caption&#039;] then<br /> captionId = &#039;imagestackpopup-caption-&#039; .. math.random()<br /> captionText = tostring(<br /> mw.html.create( &#039;div&#039; )<br /> :attr( &#039;style&#039;, &#039;display:none&#039; )<br /> :attr( &#039;id&#039;, captionId )<br /> :wikitext( args[&#039;popup-caption&#039;] )<br /> )<br /> end<br /> <br /> for row in mw.text.gsplit( args.gallery, &quot;\n&quot;, true ) do<br /> local galleryRow = &#039;&#039;<br /> local popupOptions = { title = title, caption = captionId }<br /> for part in mw.text.gsplit( row, &quot;!&quot;, true ) do<br /> equalSplit = mw.text.split( part, &#039;=&#039;, true )<br /> if #equalSplit &lt;= 1 then<br /> -- be sure this really is a caption.<br /> if galleryRow ~= &#039;&#039; and<br /> reuseImageCaption and<br /> #part &gt; 8 and<br /> string.find( part, &quot; &quot;, 1, true )<br /> then<br /> local captionId = &#039;imagestackpopup-caption-&#039; .. math.random()<br /> local wrappedPart = tostring( mw.html.create( &#039;span&#039; )<br /> :attr( &#039;id&#039;, captionId )<br /> :wikitext( part )<br /> )<br /> popupOptions.caption = captionId<br /> galleryRow = galleryRow .. wrappedPart .. &#039;|&#039;<br /> else<br /> galleryRow = galleryRow .. part .. &#039;|&#039;<br /> end<br /> else<br /> if equalSplit[1] == &#039;popup-width&#039; then<br /> popupOptions.width = tonumber(equalSplit[2])<br /> elseif equalSplit[1] == &#039;popup-height&#039; then<br /> popupOptions.height = tonumber(equalSplit[2])<br /> elseif equalSplit[1] == &#039;popup-loop&#039; then<br /> popupOptions.loop = equalSplit[2] ~= &#039;&#039;<br /> elseif equalSplit[1] == &#039;popup-start&#039; then<br /> popupOptions.start = tonumber(equalSplit[2])<br /> elseif equalSplit[1] == &#039;popup-caption&#039; then<br /> local captionIdForImg = &#039;imagestackpopup-caption-&#039; .. math.random()<br /> captionText = captionText .. tostring( mw.html.create( &#039;div&#039; )<br /> :attr( &#039;id&#039;, captionIdForImg )<br /> :css( &#039;display&#039;, &#039;none&#039; )<br /> :wikitext( table.concat( equalSplit, &#039;=&#039;, 2 ) )<br /> )<br /> popupOptions.caption = captionIdForImg<br /> elseif equalSplit[1] == &#039;popup-title&#039; then<br /> popupOptions.title = table.concat( equalSplit, &#039;=&#039;, 2 )<br /> elseif equalSplit[1] == &#039;popup-list&#039; then<br /> popupOptions.list = table.concat( equalSplit, &#039;=&#039;, 2 )<br /> if args[&#039;noregisterimages&#039;] == 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 = &#039;:&#039; .. table.concat( equalSplit, &#039;=&#039;, 2 ) }<br /> end<br /> else<br /> galleryRow = galleryRow .. part .. &#039;|&#039;<br /> end<br /> <br /> end<br /> end<br /> if string.sub( galleryRow, -1 ) == &#039;|&#039; then<br /> galleryRow = string.sub( galleryRow, 1, -2 )<br /> end<br /> galleryContents = galleryContents .. galleryRow .. &quot;\n&quot;<br /> optionsArray[#optionsArray+1] = popupOptions<br /> end<br /> return tostring( mw.html.create( &#039;div&#039; )<br /> :attr( &#039;class&#039;, &#039;ImageStackPopup&#039; )<br /> :attr( &#039;data-imagestackpopup-config&#039;, mw.text.jsonEncode( optionsArray ) )<br /> :wikitext( frame:extensionTag( &#039;gallery&#039;, galleryContents, galleryArgs ) )<br /> ) .. captionText<br /> end<br /> <br /> <br /> return p</div> Doc James