Modul:Listen: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
Tidak ada ringkasan suntingan |
k rev |
||
Baris 1:
-- This module implements {{listen}}.
local mFileLink = require('
local mTableTools = require('
local mSideBox = require('
local p = {}
local hasMissing -- For the tracking category
function p.main(frame)
Baris 15 ⟶ 16:
args[k] = v
end
end▼
if not args.filename then▼
return nil▼
end
return p._main(args)
Baris 24 ⟶ 21:
function p._main(args)
-- Find whether we are outputting a plain or an embedded box.▼
local isPlain = args.plain == 'yes'▼
-- Organise the arguments by number.
local numArgs = {}
Baris 31 ⟶ 32:
origNumArgs = mTableTools.compressSparseArray(origNumArgs)
for i, t in ipairs(origNumArgs) do
-- Check if the files exist.
if t.filename then▼
if obj and obj.exists then
numArgs[#numArgs + 1] = t
hasMissing = true
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
Baris 101 ⟶ 107:
if args.header then
header = mw.html.create('div')
header:css{
background = 'transparent',
:css{▼
▲ padding = args.embed and '2px 0' or '2px'
▲ }
:wikitext(args.header)
header = tostring(header)
Baris 115 ⟶ 120:
local text = {}
for i, t in ipairs(numArgs) do
text[#text + 1] = p.renderRow(
t.filename, t.title, t.play, t.alt, t.description if numArgs[i + 1] then
text[#text + 1] = '<hr
end
end
Baris 126 ⟶ 133:
if not isPlain and not isEmbedded and args.help ~= 'no' then
sbargs.below = string.format(
#numArgs
)
end
Baris 135 ⟶ 142:
-- Render the tracking categories.
local trackingCategories = p.renderTrackingCategories(
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
Baris 146 ⟶ 153:
end
local root = mw.html.create('')
root:tag('div')
:tag('div')
:
▲ :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▼
▲ )
:done()▼
:newline()▼
▲ :addClass('description')
:wikitext(description)▼
:done()▼
:done()
:addClass('description')
return tostring(root)
end
function p.renderTrackingCategories(
-- Renders all tracking categories produced by the template.
--
-- 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.
end
▲ local success, title = pcall(mw.title.new, 'Media:' .. t.filename)
cats[#cats + 1] = 'Artikel dengan empty listen template'
▲ 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('[[
end
return table.concat(cats)
|