Module:Random slideshow/sandbox
Appearance
![]() | This is the module sandbox page for Module:Random slideshow (diff). |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This template contains coding that is not compatible with mobile versions of Wikipedia, causing display and accessibility problems. Read the documentation for an explanation. |
![]() | This module depends on the following other modules: |
![]() | This module uses TemplateStyles: |
Usage
{{#invoke:Random slideshow|main}}
- See {{Random slideshow}} for details.
{{#invoke:Random slideshow|transclude}}
- See {{Transclude files as random slideshow}} for details.
This module is also used by Module:Excerpt slideshow.
Display in the mobile view
On mobile devices, a standard gallery is displayed instead of the slideshow. If the screen width is less than 720px, only the first four images after randomisation are visible (example screenshot). For mobile devices with larger resolutions, all images are displayed (example screenshot). For some tables, it displays all images stacked (example screenshot).
Testcases
The following testcase pages are available for testing changes made to this module's sandbox:
-- Creates a slideshow gallery where the order is randomised. Intended for use on portal pages.
local p = {}
local randomModule = require('Module:Random')
function cleanupArgs(argsTable)
local cleanArgs = {}
for key, val in pairs(argsTable) do
if type(val) == 'string' then
val = val:match('^%s*(.-)%s*$')
if val ~= '' then
cleanArgs[key] = val
end
else
cleanArgs[key] = val
end
end
return cleanArgs
end
function makeOutput(galleryLines, maxWidth)
local randomiseArgs = { ['t'] = galleryLines }
local randomisedLines = randomModule.main('array', randomiseArgs)
local galleryContent = table.concat(randomisedLines, '\n')
local output = '<div style="max-width:' .. maxWidth .. 'px; margin:-4em auto;">{{#tag:gallery|' .. galleryContent .. '|mode=slideshow}}</div>'
return output
end
function makeGalleryLine(file, caption)
local title = mw.title.new(file, "File" )
return title.prefixedText .. '{{!}}' .. (caption or '')
end
function makeGalleryLinesTable(args)
local galleryLinesTable = {}
local i = 1
while args[i] do
table.insert(galleryLinesTable, makeGalleryLine(args[i], args[i+1]))
i = i + 2
end
return galleryLinesTable
end
p.main = function(frame)
local parent = frame.getParent(frame)
local parentArgs = parent.args
local args = cleanupArgs(parentArgs)
if not args[1] then
return error('No files specified', 0)
end
local lines = makeGalleryLinesTable(args)
local output = makeOutput(lines, args.width or '350')
return frame:preprocess(output)
end
return p