Module:Random slideshow/sandbox: Difference between revisions

Content deleted Content added
improve alt param position check by temporarily removing pipes in wikilinks during processing
enable ignoreOnlyincludes
 
(6 intermediate revisions by the same user not shown)
Line 3:
local excerptModule = require('Module:Excerpt/portals/sandbox')
local randomModule = require('Module:Random')
local redirectModule = require('Module:Redirect')
 
function cleanupArgs(argsTable)
Line 40 ⟶ 39:
local sortedLines = nonRandom and galleryLines or randomModule.main('array', randomiseArgs)
for i = 1, #sortedLines do
local currentLine = sortedLines[i]
-- disable pipes in wikilinks
currentLine = currentLine:gsub(
"%[%[(.-)|(.-)]]",
"[[%1__PIPE__%2]]")
-- move any alt parameter to the end to avoid putting the switcher in too early and causing a linter error
currentLine = currentLine:gsub(
"^(.+)(|alt=[^|]*)(.*)$",
"%1%3%2")
-- bring back pipes in wikilinks
currentLine = currentLine:gsub(
"%[%[(.-)__PIPE__(.-)]]",
"[[%1|%2]]")
-- insert a switcher-label span just after the first pipe, which should ideally be the caption
currentLinesortedLines[i] = currentLinesortedLines[i]:gsub(
"|",
'|<span class="switcher-label" style="display:none"><span class="randomSlideshow-sr-only">Image ' .. tostring(i) .. '</span></span>',
1)
sortedLines[i] = currentLine
end
local galleryContent = table.concat(sortedLines, '\n')
Line 115 ⟶ 100:
file = mw.ustring.gsub(file, '|%s*center%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*centre%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*none%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*baseline%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*sub%s*([|%]])', '%1')
Line 127 ⟶ 113:
file = mw.ustring.gsub(file, '|%s*upright%s*=.-([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*link%s*=.-([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*lang%s*=.-([|%]])', '%1')
-- remove spaces prior to captions (which cause pre-formatted text)
file = mw.ustring.gsub(file, '|%s*', '|')
Line 140 ⟶ 127:
end
return files
end
 
--Central function for fixing issues that could occur in both gallery-fetched and file-fetched files
local function doubleCheck(file)
-- disable pipes in wikilinks
file = file:gsub(
"%[%[(.[^%]]-)|(.-)]]",
"[[%1__PIPE__%2]]")
-- move any alt parameter to the end to avoid putting the switcher in too early and causing a linter error
file = file:gsub(
"^(.+)(|alt=[^|]*)(.*)$",
"%1%3%2")
-- bring back pipes in wikilinks
file = file:gsub(
"%[%[(.-)__PIPE__(.-)]]",
"[[%1|%2]]")
return file
end
 
Line 168 ⟶ 172:
content = excerptModule.getSection(content, args['section'..i]) or ''
end
content = excerptModule.cleanupText(content, {keepSubsections=true, ignoreOnlyincludes=true}) -- true means keep subsections
local galleryFiles = extractGalleryFiles(content)
Line 177 ⟶ 181:
local isOkay = excerptModule.checkImage(filename)
if isOkay then
table.insert(lines, doubleCheck(f.." (from '''[["..pagename.."]]''')"))
end
end
Line 187 ⟶ 191:
for _, f in pairs(extractRegularFiles(otherFiles)) do
if f and f ~= '' and mw.ustring.sub(f, 1, 5) == 'File:' and hasCaption(f) then
table.insert(lines, doubleCheck(f.." (from '''[["..pagename.."]]''')"))
end
end