local getArgs = require('Module:Arguments').getArgslocal yesno = require('Module:Yesno')local Date = require('Module:Date')._Datelocal lang = mw.language.new('en')local cfg = mw.loadData('Module:Spoken Wikipedia/configuration/sandbox')
p =
local function wikiError(message) local ret = mw.html.create('div') :addClass(cfg.i18n.class.err) :wikitext(message) :done return tostring(ret)end
local function category(c, nocat) if nocat then return else return c endend
local function formatPageText(page) if page then return '
' .. page .. '' end if mw.title.getCurrentTitle.namespacelocal function formatFileLength(filenames) local length = 0 for _, filename in ipairs(filenames) do local fileTitle = mw.title.new(filename, 'Media') if fileTitle and fileTitle.file and fileTitle.file.exists then length = length + fileTitle.file.length end end
-- Add 30 to offset the rounding down local intervals = lang:getDurationIntervals(length + 30,) local ret = string.format('
%s %s', intervals.minutes or 0, intervals.minuteslocal function formatHeader(filenames, page) local listento = mw.html.create('span') :addClass(cfg.i18n.class.listento) :wikitext(string.format(cfg.i18n.listento, formatPageText(page) )) :done local file_length if #filenames > 1 then file_length = string.format(cfg.i18n.n_files_length, tostring(#filenames), formatFileLength(filenames) ) else file_length = string.format(cfg.i18n.one_file_length, formatFileLength(filenames) ) end local header = mw.html.create('div') :addClass(cfg.i18n.class.header) :node(listento) :wikitext(file_length) if #filenames > 0 then header:attr('id', string.format(cfg.i18n.fragment.id, filenames[1])) end return header:doneend
local function formatIcon return mw.html.create('div') :addClass(cfg.i18n.class.icon) :wikitext(cfg.i18n.icon) :doneend
local function formatFiles(filenames, nocat) if #filenames
1 then table.insert(files, string.format(cfg.i18n.one_file, filenames[1])) else for i, filename in ipairs(filenames) do table.insert(files, string.format(cfg.i18n.n_files, filename, i)) end end
return mw.html.create('div') :addClass(cfg.i18n.class.files) :wikitext(table.concat(files)) :done :newlineend
local function formatDateText(frame, dateArg, nocat) local d = dateArg and Date(dateArg) or nil return d and frame:expandTemplate or (wikiError(cfg.i18n.err.no_date) .. category(cfg.i18n.cat.no_date, nocat))end
local function formatDisclaimer(frame, filenames, page, dateArg, nocat) local thisFileText = local disclaimer if #filenames
local function formatFooter return mw.html.create('div') :addClass(cfg.i18n.class.footer) :wikitext(cfg.i18n.footer) :doneend
local function formatTopicon(frame, filenames) local wikilink if #filenames > 0 then wikilink = string.format(cfg.i18n.fragment.id, filenames[1]) else wikilink = cfg.i18n.topicon_multiwikilink end return frame:expandTemplateend
local function extractFilenames(args) local filenames = for key, rawValue in ipairs(args) do local value = mw.text.trim(rawValue) if type(key)
local function sidebox(nodes) root = mw.html.create('div') :addClass(cfg.i18n.class.box) for _, node in ipairs(nodes) do root:node(node) end return rootend
function main(frame) local args = getArgs(frame)
-- Mandatory parameters local filenames = extractFilenames(args) local dateArg = args['date'] -- Optional parameters local page = args['page'] local nocat = yesno(args['nocat'], false) or false
local root = sidebox
if mw.title.getCurrentTitle.namespace
return frame:extensionTag .. tostring(root)end
p.main = main
return p