<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.cultopedia.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AGallery</id>
	<title>Module:Gallery - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.cultopedia.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AGallery"/>
	<link rel="alternate" type="text/html" href="https://www.cultopedia.org/index.php?title=Module:Gallery&amp;action=history"/>
	<updated>2026-04-05T23:33:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.5</generator>
	<entry>
		<id>https://www.cultopedia.org/index.php?title=Module:Gallery&amp;diff=1549&amp;oldid=prev</id>
		<title>imported&gt;Arthurfragoso: Returning to the new version + fixes tested in the sandbox and in a local mediawiki. The problem was because the parser was interpreting the pipe as part of the url in the reported case.</title>
		<link rel="alternate" type="text/html" href="https://www.cultopedia.org/index.php?title=Module:Gallery&amp;diff=1549&amp;oldid=prev"/>
		<updated>2025-02-10T10:31:44Z</updated>

		<summary type="html">&lt;p&gt;Returning to the new version + fixes tested in the sandbox and in a local mediawiki. The problem was because the parser was interpreting the pipe as part of the url in the reported case.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module implements {{gallery}} by wrapping the &amp;lt;gallery&amp;gt; core extension tag.&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local templatestyles = &amp;#039;Module:Gallery/styles.css&amp;#039;&lt;br /&gt;
local yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
local plaintextModule = require(&amp;#039;Module:Plain text&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local function plaintext(text)&lt;br /&gt;
	-- stips out external links without labels,&lt;br /&gt;
	-- and then passes to the Plain_text module to clean the rest&lt;br /&gt;
    return plaintextModule.main({ args = {&lt;br /&gt;
    	text:gsub(&amp;quot;([^%[])%[([^%[%]%s]+)%]&amp;quot;, &amp;#039;%1&amp;#039;)&lt;br /&gt;
    	, encode = &amp;quot;no&amp;quot; } })&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function trim(s)&lt;br /&gt;
	return mw.ustring.gsub(mw.ustring.gsub(s or &amp;#039;&amp;#039;, &amp;#039;%s&amp;#039;, &amp;#039; &amp;#039;), &amp;#039;^%s*(.-)%s*$&amp;#039;, &amp;#039;%1&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local tracking, preview&lt;br /&gt;
&lt;br /&gt;
local function isImage(file)&lt;br /&gt;
    local file = trim(file):lower() -- Case insensitive check&lt;br /&gt;
&lt;br /&gt;
    -- Check if it starts with &amp;quot;File:&amp;quot;, &amp;quot;Image:&amp;quot;, or &amp;quot;Media:&amp;quot;&lt;br /&gt;
    local prefix = file:match(&amp;quot;^(%a+):&amp;quot;)&lt;br /&gt;
    if prefix and (prefix == &amp;quot;file&amp;quot; or prefix == &amp;quot;image&amp;quot; or prefix == &amp;quot;media&amp;quot;) then&lt;br /&gt;
        return true&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    local valid_extensions = {&lt;br /&gt;
        &amp;quot;apng&amp;quot;, &amp;quot;djvu&amp;quot;, &amp;quot;flac&amp;quot;, &amp;quot;gif&amp;quot;, &amp;quot;jfi&amp;quot;, &amp;quot;jfif&amp;quot;, &amp;quot;jif&amp;quot;, &amp;quot;jpe&amp;quot;, &amp;quot;jpeg&amp;quot;, &amp;quot;jpg&amp;quot;,&lt;br /&gt;
        &amp;quot;m1a&amp;quot;, &amp;quot;m1v&amp;quot;, &amp;quot;m2a&amp;quot;, &amp;quot;m2v&amp;quot;, &amp;quot;mid&amp;quot;, &amp;quot;mp1&amp;quot;, &amp;quot;mp2&amp;quot;, &amp;quot;mp3&amp;quot;, &amp;quot;mpa&amp;quot;, &amp;quot;mpe&amp;quot;, &amp;quot;mpeg&amp;quot;, &amp;quot;mpg&amp;quot;,&lt;br /&gt;
        &amp;quot;mpv&amp;quot;, &amp;quot;oga&amp;quot;, &amp;quot;ogg&amp;quot;, &amp;quot;ogv&amp;quot;, &amp;quot;opus&amp;quot;, &amp;quot;pdf&amp;quot;, &amp;quot;png&amp;quot;, &amp;quot;stl&amp;quot;, &amp;quot;svg&amp;quot;, &amp;quot;svgz&amp;quot;, &amp;quot;tif&amp;quot;, &amp;quot;tiff&amp;quot;,&lt;br /&gt;
        &amp;quot;wav&amp;quot;, &amp;quot;wave&amp;quot;, &amp;quot;webm&amp;quot;, &amp;quot;webp&amp;quot;, &amp;quot;xcf&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    -- Extract file extension, of 3 or 4 characters only&lt;br /&gt;
    local ext = file:match(&amp;quot;%.(%w%w%w%w?)$&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
    -- Check if the extension is in the valid list&lt;br /&gt;
    if ext then&lt;br /&gt;
        for _, valid_ext in ipairs(valid_extensions) do&lt;br /&gt;
            if ext == valid_ext then&lt;br /&gt;
            	table.insert(tracking, &amp;#039;[[Category:Pages using gallery without a media namespace prefix]]&amp;#039;)&lt;br /&gt;
                return true&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function checkarg(k,v)&lt;br /&gt;
	if k and type(k) == &amp;#039;string&amp;#039; then&lt;br /&gt;
		if k == &amp;#039;align&amp;#039; or k == &amp;#039;state&amp;#039; or k == &amp;#039;style&amp;#039; or k == &amp;#039;title&amp;#039; or&lt;br /&gt;
			k == &amp;#039;width&amp;#039; or k == &amp;#039;height&amp;#039; or k == &amp;#039;whitebg&amp;#039; or&lt;br /&gt;
			k == &amp;#039;mode&amp;#039; or k == &amp;#039;footer&amp;#039; or k == &amp;#039;perrow&amp;#039; or k == &amp;#039;noborder&amp;#039; or&lt;br /&gt;
			k:match(&amp;#039;^alt%d+$&amp;#039;) or k:match(&amp;#039;^class%d+$&amp;#039;) or k:match(&amp;#039;^%d+$&amp;#039;) then&lt;br /&gt;
			-- valid&lt;br /&gt;
		elseif k == &amp;#039;captionstyle&amp;#039; then&lt;br /&gt;
			if not v:match(&amp;#039;^text%-align%s*:%s*center[;%s]*$&amp;#039;) then&lt;br /&gt;
				table.insert(tracking, &amp;#039;[[Category:Pages using gallery with the captionstyle parameter]]&amp;#039;)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			-- invalid&lt;br /&gt;
			local vlen = mw.ustring.len(k)&lt;br /&gt;
			k = mw.ustring.sub(k, 1, (vlen &amp;lt; 25) and vlen or 25)&lt;br /&gt;
			k = mw.ustring.gsub(k, &amp;#039;[^%w%-_ ]&amp;#039;, &amp;#039;?&amp;#039;)&lt;br /&gt;
			table.insert(tracking, &amp;#039;[[Category:Pages using gallery with unknown parameters|&amp;#039; .. k .. &amp;#039;]]&amp;#039;)&lt;br /&gt;
			table.insert(preview, &amp;#039;&amp;quot;&amp;#039; .. k .. &amp;#039;&amp;quot;&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.gallery(frame)&lt;br /&gt;
	-- If called via #invoke, use the args passed into the invoking template.&lt;br /&gt;
	-- Otherwise, for testing purposes, assume args are being passed directly in.&lt;br /&gt;
	local origArgs = (type(frame.getParent) == &amp;#039;function&amp;#039;) and frame:getParent().args or frame&lt;br /&gt;
&lt;br /&gt;
    -- ParserFunctions considers the empty string to be false, so to preserve the previous&lt;br /&gt;
    -- behavior of {{gallery}}, change any empty arguments to nil, so Lua will consider&lt;br /&gt;
    -- them false too.&lt;br /&gt;
    local args = {}&lt;br /&gt;
    tracking, preview = {}, {}&lt;br /&gt;
    for k, v in pairs(origArgs) do&lt;br /&gt;
    	if v ~= &amp;#039;&amp;#039; then&lt;br /&gt;
    		args[k] = v&lt;br /&gt;
    		checkarg(k,v)&lt;br /&gt;
    	end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if (args.mode or &amp;#039;&amp;#039;) == &amp;#039;packed&amp;#039; and (args.align or &amp;#039;&amp;#039;) == &amp;#039;&amp;#039; then&lt;br /&gt;
		args.align = &amp;#039;center&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if (args.align or &amp;#039;&amp;#039;) == &amp;#039;centre&amp;#039; then&lt;br /&gt;
		args.align = &amp;#039;center&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local tbl = mw.html.create(&amp;#039;div&amp;#039;)&lt;br /&gt;
	tbl:addClass(&amp;#039;mod-gallery&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
	if args.state then&lt;br /&gt;
		tbl&lt;br /&gt;
			:addClass(&amp;#039;mod-gallery-collapsible&amp;#039;)&lt;br /&gt;
			:addClass(&amp;#039;collapsible&amp;#039;)&lt;br /&gt;
			:addClass(args.state)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if args.style then&lt;br /&gt;
		tbl:cssText(args.style)&lt;br /&gt;
	else&lt;br /&gt;
		tbl:addClass(&amp;#039;mod-gallery-default&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if args.align then&lt;br /&gt;
		tbl:addClass(&amp;#039;mod-gallery-&amp;#039; .. args.align:lower())&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if args.title then&lt;br /&gt;
		tbl:tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
			:addClass(&amp;#039;title&amp;#039;)&lt;br /&gt;
				:tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
					:wikitext(args.title)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local gargs = {}&lt;br /&gt;
	gargs[&amp;#039;class&amp;#039;] = &amp;#039;nochecker&amp;#039; .. (args.noborder and &amp;#039;&amp;#039; or &amp;#039; bordered-images&amp;#039;)&lt;br /&gt;
	gargs[&amp;#039;widths&amp;#039;] = tonumber(args.width) or 180&lt;br /&gt;
	gargs[&amp;#039;heights&amp;#039;] = tonumber(args.height) or 180&lt;br /&gt;
	gargs[&amp;#039;style&amp;#039;] = args.captionstyle&lt;br /&gt;
	gargs[&amp;#039;perrow&amp;#039;] = args.perrow&lt;br /&gt;
	gargs[&amp;#039;mode&amp;#039;] = args.mode&lt;br /&gt;
	if yesno(args.whitebg or &amp;#039;yes&amp;#039;) then&lt;br /&gt;
		gargs[&amp;#039;class&amp;#039;] = gargs[&amp;#039;class&amp;#039;] .. &amp;#039; whitebg&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local virtualgallery = {}&lt;br /&gt;
	local gallery = {}&lt;br /&gt;
	&lt;br /&gt;
	local imageCount = 0&lt;br /&gt;
&lt;br /&gt;
	local zwsp = string.char(0xE2, 0x80, 0x8B) -- U+200B Zero Width Space&lt;br /&gt;
	local zwnj = string.char(0xE2, 0x80, 0x8C) -- U+200C Zero Width Non-Joiner&lt;br /&gt;
	&lt;br /&gt;
	-- create a coding to identify classes&lt;br /&gt;
	-- using unicode non-printing characters&lt;br /&gt;
	-- this is a workaround until we get the class arg in the &amp;lt;gallery&amp;gt; tag&lt;br /&gt;
	-- https://phabricator.wikimedia.org/T344784&lt;br /&gt;
 &lt;br /&gt;
	local skininvert    = zwsp .. zwsp .. zwsp;&lt;br /&gt;
	local bgtransparent = zwsp .. zwsp .. zwnj;&lt;br /&gt;
	&lt;br /&gt;
	for i = 1, #args do&lt;br /&gt;
	    local currentfield = trim(args[i]) or &amp;#039;&amp;#039;&lt;br /&gt;
	&lt;br /&gt;
	    if currentfield == &amp;#039;&amp;#039; then&lt;br /&gt;
	        -- Skip empty fields&lt;br /&gt;
	    elseif isImage(currentfield) then&lt;br /&gt;
	        imageCount = imageCount + 1&lt;br /&gt;
	        virtualgallery[imageCount] = { currentfield }&lt;br /&gt;
	    elseif imageCount &amp;gt; 0 and virtualgallery[imageCount][2] == nil then&lt;br /&gt;
	    	-- In case of multiple captions, use the first and ignore the laters&lt;br /&gt;
	        virtualgallery[imageCount][2] = currentfield&lt;br /&gt;
	    end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local altCount = 0;&lt;br /&gt;
	&lt;br /&gt;
	-- Run through virtualgallery and builds gallery&lt;br /&gt;
	for n = 1, #virtualgallery do&lt;br /&gt;
	    local img = virtualgallery[n][1]&lt;br /&gt;
	    local caption = virtualgallery[n][2] or &amp;#039;&amp;#039;&lt;br /&gt;
	    local alt = trim(args[&amp;#039;alt&amp;#039; .. n] or &amp;#039;&amp;#039;)&lt;br /&gt;
	    local class = trim(args[&amp;#039;class&amp;#039; .. n] or &amp;#039;&amp;#039;)&lt;br /&gt;
	    &lt;br /&gt;
	    -- we count alt text only before any modification&lt;br /&gt;
	    if alt ~= &amp;#039;&amp;#039; then&lt;br /&gt;
	    	altCount = altCount + 1&lt;br /&gt;
	    else&lt;br /&gt;
	    	-- if alt is empty, we use the caption as a alt text.&lt;br /&gt;
	    	-- It is necessary because we add classes codes in the next step,&lt;br /&gt;
	    	-- we do not want to let the alt empty with just the non-printing characters.&lt;br /&gt;
	    	alt = (caption ~= &amp;#039;&amp;#039;) and plaintext(caption) or &amp;#039;&amp;#039;&lt;br /&gt;
	    end&lt;br /&gt;
&lt;br /&gt;
	    -- we attach the non-printing code to the end of the alt text&lt;br /&gt;
	    if mw.ustring.find(class, &amp;#039;skin%-invert&amp;#039;) then -- this matches both skin-invert and skin-invert-image&lt;br /&gt;
	    	alt = alt .. skininvert&lt;br /&gt;
	    end&lt;br /&gt;
	    &lt;br /&gt;
	    -- as it is possible to combine multiple classes, we use find instead of ==&lt;br /&gt;
	    if mw.ustring.find(class, &amp;#039;bg%-transparent&amp;#039;) then&lt;br /&gt;
	    	alt = alt .. bgtransparent&lt;br /&gt;
	    end&lt;br /&gt;
	    &lt;br /&gt;
	    -- Some space between the arguments and the pipe to prevent unexpected behaviors.&lt;br /&gt;
	    -- for example: in some cases the parser interpret the pipe as part of urls&lt;br /&gt;
	    table.insert(gallery, img .. &lt;br /&gt;
	    	(alt ~= &amp;#039;&amp;#039; and (&amp;#039; |alt=&amp;#039; .. alt) or &amp;#039;&amp;#039;) ..&lt;br /&gt;
	    	(caption ~= &amp;#039;&amp;#039; and (&amp;#039; |&amp;#039; .. caption) or &amp;#039;&amp;#039;))&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- For tracking and verifying during migration to the new algorimth.&lt;br /&gt;
	-- It can be removed once everything is verified&lt;br /&gt;
	if math.ceil(#args / 2) &amp;gt; imageCount then&lt;br /&gt;
		if altCount &amp;gt; 0 then&lt;br /&gt;
			table.insert(tracking, &amp;#039;[[Category:Pages using gallery with potential alt text mismatch]]&amp;#039;)&lt;br /&gt;
		--else&lt;br /&gt;
		--	table.insert(tracking, &amp;#039;[[Category:Pages using gallery with extra empty fields]]&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	tbl:tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
		:addClass(&amp;#039;main&amp;#039;)&lt;br /&gt;
		:tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
			:wikitext(&lt;br /&gt;
				frame:extensionTag{ name = &amp;#039;gallery&amp;#039;, content = &amp;#039;\n&amp;#039; .. table.concat(gallery,&amp;#039;\n&amp;#039;), args = gargs}&lt;br /&gt;
				)&lt;br /&gt;
&lt;br /&gt;
	if args.footer then&lt;br /&gt;
		tbl:tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
			:addClass(&amp;#039;footer&amp;#039;)&lt;br /&gt;
				:tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
					:wikitext(args.footer)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local trackstr = (#tracking &amp;gt; 0) and table.concat(tracking, &amp;#039;&amp;#039;) or &amp;#039;&amp;#039;&lt;br /&gt;
	if #preview &amp;gt; 0 then&lt;br /&gt;
		trackstr = require(&amp;#039;Module:If preview&amp;#039;)._warning({&lt;br /&gt;
			&amp;#039;Unknown parameters &amp;#039; .. table.concat(preview, &amp;#039;; &amp;#039;) .. &amp;#039;.&amp;#039;&lt;br /&gt;
		}) .. trackstr&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return frame:extensionTag{ name = &amp;#039;templatestyles&amp;#039;, args = { src = templatestyles} } .. tostring(tbl) .. trackstr&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Arthurfragoso</name></author>
	</entry>
</feed>