Module:Random slideshow
Appearance
![]() | 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 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 isAffirmed(val)
if not(val) then return false end
local affirmedWords = ' add added affirm affirmed include included on true yes y '
return string.find(affirmedWords, ' '..string.lower(val)..' ', 1, true ) and true or false
end
function makeOutput(galleryLines)
local randomiseArgs = { ['t'] = galleryLines }
local randomisedLines = randomModule.main('array', galleryLines)
local galleryTagContent = table.concat(randomisedLines, '\n')
local galleryTag = mw.html.create('gallery')
galleryTag
:attr('mode', 'slideshow')
:wikitext(tagContent)
return tostring(galleryTag)
end
function makeGalleryLine(file, caption)
local title = mw.title.new(args[i], "File" )
return title.prefixedText .. '{{!}}' .. (caption or '')
end
function makeGalleryLinesTable(args)
local galleryLinesTable = {}
local i = 1
while args[i] do
table.insert( 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)
local lines = makeGalleryLinesTable(args)
return makeOutput(lines)
end
return p