Modul:Listen: Perbedaan antara revisi

218 bita ditambahkan ,  1 tahun yang lalu
k
rev
Tidak ada ringkasan suntingan
k (rev)
-- This module implements {{listen}}.
 
local mFileLink = require('ModuleModul:File link')
local mTableTools = require('ModuleModul:TableTools')
local mSideBox = require('ModuleModul:Side box')
 
local p = {}
local hasMissing -- For the tracking category
 
function p.main(frame)
args[k] = v
end
end
-- Exit early if filename (required) is not provided.
if not args.filename then
return nil
end
return p._main(args)
 
function p._main(args)
-- Find whether we are outputting a plain or an embedded box.
local isPlain = args.plain == 'yes'
local isEmbedded = args.embed and true or false
 
-- Organise the arguments by number.
local numArgs = {}
origNumArgs = mTableTools.compressSparseArray(origNumArgs)
for i, t in ipairs(origNumArgs) do
-- Check if the files exist.
if t.filename then
local success, titleobj = pcall(t.filename and mw.title.new, ('Media:' .. t.filename)
if obj and obj.exists then
numArgs[#numArgs + 1] = t
}else
hasMissing = true
end
end
-- Exit early if none exist.
if #numArgs == 0 then
return p.renderTrackingCategories(isPlain, true)
end
end
 
-- Find whether we are outputting a plain or an embedded box.
local isPlain = args.plain == 'yes'
local isEmbedded = args.embed and true or false
 
-- Build the arguments for {{side box}}
local sbargs = {}
sbargs.class = 'noprint'
sbargs.metadata = 'no'
sbargs.position = args.pos
if args.header then
header = mw.html.create('div')
header:css{
background = 'transparent',
:css{
background['text-align'] = 'transparentleft',
padding = args.embed and '2px 0' or '2px'
['text-align'] = 'left',
)}
padding = args.embed and '2px 0' or '2px'
}
:wikitext(args.header)
header = tostring(header)
local text = {}
for i, t in ipairs(numArgs) do
text[#text + 1] = p.renderRow(t.filename, t.title, t.play, t.alt, t.description)
t.filename, t.title, t.play, t.alt, t.description, t.start
end)
if numArgs[i + 1] then
text[#text + 1] = '<hr />'
end
end
if not isPlain and not isEmbedded and args.help ~= 'no' then
sbargs.below = string.format(
"'<hr /><spani class="selfreference">''Bermasalah memainkan %s ini? Lihat [[Help:Media|bantuan media]].''</spani>"',
#numArgs >== 1 and 'berkas-berkas' or 'berkas'
)
end
 
-- Render the tracking categories.
local trackingCategories = p.renderTrackingCategories(args, numArgsisPlain)
 
return sideBox .. trackingCategories
end
 
function p.renderRow(filename, title, play, alt, description, start)
-- Renders the HTML for one file description row.
if not filename then
end
local root = mw.html.create('')
root:tag('div')
:addClass('descriptionhaudio')
:newline()
:tag('div')
:addClasscss('haudiopadding', '4px 0')
:wikitext(string.format('[[:FileBerkas:%s|%s]]', filename, title or ''))
:newline()
:tag('div')
:css('padding', '4px 0')
:wikitext(string.format('[[:File:%s|%s]]', filename, title or ''))
:done()
:newline()
:tag('div')
:wikitext(
play ~= 'no'
and mFileLink._main{
file = filename,
size = '220px',
alt = alt
}
or nil
)
:done()
:newline()
:tag('div')
:css('padding', '2px 0 0 0')
:addClass('description')
:wikitext(description)
:done()
:done()
:newline()
:tag('div')
:wikitext(
play ~= 'no'
and mFileLink._main{
if file t.filename= thenfilename,
filesize = filename'220px',
sizealt = '220px'alt,
altstart = altstart
:css{ }
return or nil
})
:done()
:newline()
:tag('div')
:css('padding', '4px2px 0 0 0')
:addClass('description')
:wikitext(description)
:done()
:done()
return tostring(root)
end
 
function p.renderTrackingCategories(argsisPlain, numArgsisEmpty, titleObj)
-- Renders all tracking categories produced by the template.
-- argsisPlain and numArgsisEmpty are passed through from p._main,
-- and the titleObj is only used for testing purposes.
local cats = {}
 
local currentTitle = titleObj or mw.title.getCurrentTitle()
if currentTitle.namespace == 0 then
-- We are in mainspace.
if not args.filenameisEmpty then
 
cats[#cats + 1] = 'ListenArtikel templatedengan usinghAudio plain parametermicroformats'
for i, t in ipairs(numArgs) do
end
local success, title = pcall(mw.title.new, 'Media:' .. t.filename)
if success and title and not title.existshasMissing then
cats[#cats + 1] = 'Artikel dengan empty listen template'
break
end
end
end
if isPlain then
 
cats[#cats + 1] = 'Templat dengar menggunakan parameter biasa'
if args.plain == 'yes' then
cats[#cats + 1] = 'Listen template using plain parameter'
end
 
for i, cat in ipairs(cats) do
cats[i] = string.format('[[CategoryKategori:%s]]', cat)
end
return table.concat(cats)