Modul:Random slideshow: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
Sophivorus (bicara | kontrib) Tidak ada ringkasan suntingan |
Tegarrifqi (bicara | kontrib) kTidak ada ringkasan suntingan |
||
(Satu revisi perantara oleh satu pengguna lainnya tidak ditampilkan) | |||
Baris 38:
local randomiseArgs = { ['t'] = galleryLines }
local sortedLines = nonRandom and galleryLines or randomModule.main('array', randomiseArgs)
for i = 1, #sortedLines do
-- insert a switcher-label span just after the first pipe, which should ideally be the caption
sortedLines[i] = sortedLines[i]:gsub(
"|",
'|<span class="switcher-label" style="display:none"><span class="randomSlideshow-sr-only">Image ' .. tostring(i) .. '</span></span>',
1)
end
local galleryContent = table.concat(sortedLines, '\n')
local output = '<div class="' .. containerClassName .. '" style="max-width:' .. normaliseCssMeasurement(maxWidth) .. '; margin:-4em auto;">
.. mw.getCurrentFrame():extensionTag({name="gallery",content=galleryContent,args={mode="slideshow",class="switcher-container"}}) .. '</div>'
return output
end
Baris 45 ⟶ 53:
function makeGalleryLine(file, caption, credit)
local title = mw.title.new(file, "File" )
if not title
then
return "File:Blank.png|{{Error|File [[:File:" .. file .. "]] does not exist.}}"
end
local creditLine = ( credit and '<p><span style="font-size:88%">' .. credit .. '</span></p>' or '' )
return title.prefixedText .. '
end
Baris 60 ⟶ 72:
function hasCaption(line)
local caption = mw.ustring.match(line, ".-
-- require caption to exist with more than 5 characters (avoids sizes etc being mistaken for captions)
return caption and #caption>5 and true or false
Baris 70 ⟶ 82:
return false
end
gallery = mw.ustring.gsub(gallery, '|', '{{!}}')▼
return mw.text.split(gallery, '%c')
end
Baris 84 ⟶ 95:
file = mw.ustring.gsub(file, '|%s*thumb%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*thumbnail%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*left%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*right%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*center%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*text%-top%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*bottom%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*text%-bottom%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*framed?%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*frameless%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*upright%s*[0-9%.]*%s*([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*upright%s*=.-([|%]])', '%1')
file = mw.ustring.gsub(file, '|%s*link%s*=.-([|%]])', '%1')
-- remove spaces prior to captions (which cause pre-formatted text)
file = mw.ustring.gsub(file, '|%s*', '|')
-- remove sizes, which sometimes get mistaken for captions
file = mw.ustring.gsub(file, '|%s*%d*x?%d+%s*px%s*([|%]])', '%1')
▲ file = mw.ustring.gsub(file, '{%b{}}', expand)
▲ file = mw.ustring.gsub(file, '}}', '')
▲ file = mw.ustring.gsub(file, '{{.-([|%]])', '$1')
▲ file = mw.ustring.gsub(file, '|', '{{!}}')
▲ file = mw.ustring.gsub(file, '=', '{{=}}')
-- remove linebreaks
file = mw.ustring.gsub(file, '\n\n', '<br>')
Baris 113 ⟶ 125:
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
Baris 139 ⟶ 168:
end
if args['section'..i] then
content = excerptModule.
end
content = excerptModule.cleanupText(content, {keepSubsections=true}) -- true means keep subsections
local galleryFiles = extractGalleryFiles(content)
Baris 147 ⟶ 176:
for _, f in pairs(galleryFiles) do
if hasCaption(f) then
local filename = string.gsub(f, '
local isOkay = excerptModule.
if isOkay then
table.insert(lines, doubleCheck(f.." (from '''[["..pagename.."]]''')"))
end
end
Baris 156 ⟶ 185:
end
local otherFiles = excerptModule.parse(content, {fileflags="1-100"
if otherFiles then
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
Baris 171 ⟶ 200:
end
p._main = function(args, transclude,
if not args[1] then
return error(linked and 'No page specified' or 'No page specified', 0)
end
local lines = transclude and makeTranscludedGalleryLinesTables(args) or makeGalleryLinesTable(args)
if extraClassName then classNames = classNames .. ' ' .. extraClassName end
return makeOutput(lines, args.width or '100%', classNames, isDeclined(args.random))
end
Baris 184 ⟶ 215:
local args = cleanupArgs(parentArgs)
local output = p._main(args, false)
return frame:extensionTag{ name='templatestyles', args = { src='Module:Random slideshow/styles.css'} }
.. frame:preprocess(output)
end
Baris 193 ⟶ 224:
local args = cleanupArgs(parentArgs)
local output = p._main(args, true)
return frame:extensionTag{ name='templatestyles', args = { src='Module:Random slideshow/styles.css'} }
.. frame:preprocess(output)
end
|