Module:Version
The above documentation is transcluded from Module:Version/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
local getArgs = require('Module:Arguments').getArgs
local util = require('Module:Util')
local p = {}
local g_frame, g_args
-- -----
-- ----------------------------------------------------------------------------------------------------
-- Template: Version
-- todo: rework, add a mapping for fields
function p.version(frame)
g_args = getArgs(frame, {parentFirst = true})
g_frame = util.misc.get_frame(frame)
--[[ test args
= p.version{
before = '2.4.0h',
patch = '2.4.1',
patchdate = 'October 18, 2016',
after = '2.4.1b',
}
--]]
-- Parser
local vargs = {before = '←', after = '→' }
local properties = {}
--
for arg in pairs(vargs) do
if g_args[arg] ~= nil then
properties['Has version ' .. arg] = g_args[arg]
local query = {}
query[#query + 1] = string.format('[[Is version::%s]][[Has release date::+]]', g_args[arg])
query[#query + 1] = '?Has release date'
local result = ''
local results = util.smw.query(query, g_frame)
if #results ~= 0 then
result = results[1]['Has release date']
end
vargs[arg] = string.format('[[Version %s|%s %s]]<br>%s', g_args[arg], vargs[arg], g_args[arg], result)
else
vargs[arg] = nil
end
end
properties['Is version'] = g_args['patch']
properties['Has release date'] = g_args['patchdate']
util.smw.set(g_frame, properties)
-- Output
-- todo: rework it somehow
local patch_date = g_frame:callParserFunction('#show: Version ' .. g_args['patch'], {'?Has release date'})
local tbl = mw.html.create('table')
tbl
:attr('class', 'wikitable successionbox')
:tag('tr')
:tag('th')
:attr('colspan', 3)
:wikitext('[[Version history|Version History]]')
:done()
:done()
:tag('tr')
:tag('td')
:attr('style', 'width: 30%;')
:wikitext(vargs['before'])
:done()
:tag('td')
:attr('style', 'width: 40%;')
:wikitext(string.format('[[Version %s]]<br>%s', g_args['patch'], patch_date))
:done()
:tag('td')
:attr('style', 'width: 30%;')
:wikitext(vargs['after'])
return tostring(tbl)
end
-- -----
return p