Module:Infobox

-- -- Infobox template module for w:c:dev documentation. -- @module     infobox -- @version    0.8.0 -- @usage -- @author     Speedit -- @see        Template:Infobox JavaScript; Template:Infobox CSS -- @release    unstable

-- Module package. local infobox = {}

-- Module variables and utilities. -- @section utils local title = mw.title.getCurrentTitle

-- Module message data. -- @see        Module:Infobox/i18n local i18n = require('Module:I18n').loadMessages('Infobox')

-- Installation exports. -- @section exps

-- Infobox data argument handler. -- Substitutes $n arguments with version numbers. -- @param      {table} frame Frame invocation object. -- @param      {string} frame.args[1] Infobox data input. -- @raise      'missing argument in infobox.data' -- @usage -- @return     {string} Argument-substituted infobox data. function infobox.data(frame) if ((frame or {}).args or {})[1] then -- Template arguments & variables. local args = frame:getParent.args local ret = frame.args[1] -- Replacement handler. local repl = function(d) if d == '1' then return args.Submodule or                   i18n:msg('original') else return args['Submodule' .. d] or                   i18n:msg('version', d)            end end -- Argument substitution. ret = string.find(ret, '$') and ret:gsub('%$(%w+)', repl) or           ret return ret else -- Throw error if incorrectly configured. error('missing argument in infobox.data') end end

-- Infobox date list generator with version numbers. -- @param      {table} frame Frame invocation object. -- @param      {string} frame:getParent.args Template arguments. -- @usage -- @return     {string} Formatted multi-line date string. function infobox.date(frame) -- Template arguments & variables. local args = frame:getParent.args local ret = '' local dfmt = args.dateformat or '' local lang = i18n:getLang -- Formatted value. if args.Updated then -- Generated first formatted date. ret = frame:expandTemplate{ title = 'FormatDate', args = { args.Updated, dateformat = dfmt, uselang = lang }       }        if args.Updated2 then -- Append first version tag. local sub1 = args.Submodule1 or i18n:msg('original') ret = ret .. ' (' .. sub1 .. ')' -- Handle further versions. for k, p in ipairs(args) do               if string.match(k, '^Updated%d+$') then -- Version variables. local n = string.match(k, 'Updated(%d+)$') local s_k = 'Submodule' .. n                   local s = args[s_k] or i18n:msg('version', n)                    ret = ret .. ' ' .. frame:expandTemplate{ title = 'FormatDate', args = { p, dateformat = dfmt, uselang = lang }                   } .. ' (' .. s ..')' end end end -- Default value. elseif args.Code then --           @todo use DPL template to extract main code page        -- ret = frame:expandTemplate{ title = 'FormatDate', args = { frame:expandTemplate{ title = 'Updated', args = { 'MediaWiki:' .. title.baseText .. '/code.js' }               },                dateformat = args.dateformat or '', uselang = i18n:getLang }       }    end return ret end

return infobox