The main entrypoint is the "get" function. First parameter is release, can be "stable", "legacy", "lts", or "alpha". Second parameter is the format, can be "version", "branch", "git", or "date". Note that "alpha" only works with "branch", the behavior of other output formats is undefined.

  • {{#invoke:Sandbox/BDavis_(WMF)/Version|get|stable|version}}: 1.27.0
  • {{#invoke:Sandbox/BDavis_(WMF)/Version|get|stable|branch}}: 1.27
  • {{#invoke:Sandbox/BDavis_(WMF)/Version|get|stable|git}}: REL1_27
  • {{#invoke:Sandbox/BDavis_(WMF)/Version|get|stable|date}}: 2016-06-28
  • {{#invoke:Sandbox/BDavis_(WMF)/Version|get|legacy|version}}: 1.26.3
  • {{#invoke:Sandbox/BDavis_(WMF)/Version|get|lts|version}}: 1.23.14
  • {{#invoke:Sandbox/BDavis_(WMF)/Version|get|alpha|branch}}: 1.28

That said, you probably want to use one of the wrapper templates in Category:MediaWiki version information templates instead of calling this module directly.


local p = {}
local releases = {}

-- HEY YOU, UPDATE THESE
releases["1.27.0"] = "2016-06-28"
releases["1.26.3"] = "2016-05-20"
releases["1.23.14"] = "2016-05-20"

-- Is there a beta branch that isn't a proper release yet?
p.isthereabeta = false
-- OKAY YOU CAN STOP NOW

-- Iterate a table in reverse
-- from http://lua-users.org/wiki/IteratorsTutorial
function ripairs(t)
  local function ripairs_it(t,i)
    i=i-1
    local v=t[i]
    if v==nil then return v end
    return i,v
  end
  return ripairs_it, t, #t+1
end

p.releases = releases

-- get trimmed version like "1.XX"
function p.branch( version )
	return string.sub(version, 0,4)
end

-- git branch like REL1_XX
function p.git_branch( version )
	return "REL1_" .. string.sub(p.branch(version), 3)
end

function p.islts( version )
	local branch = p.branch( version )
	-- yeah don't do this
	return branch == "1.19" or branch == "1.23" or branch == "1.27"
end

function p.get( frame )
	return p.version( frame.args[1], frame.args[2] )
end

-- main function
-- release: stable, legacy, lts, alpha
-- format: version, branch, git, date
function p.version( release, format )
	local versions = {}
	for k,v in pairs(p.releases) do
		table.insert(versions,k)
	end
	table.sort(versions)
	--mw.logObject(versions)
	--mw.log(#versions)
	local version = "0.0.0"
	if release == "stable" then
		version = versions[#versions]
	elseif release == "legacy" then
		version = versions[#versions-1]
	elseif release == "lts" then
		for i,v in ripairs(versions) do
			-- this might not be right.
			if p.islts(v) then
				version = v
			end
		end
	elseif release == "alpha" then
		-- alpha only works with "branch" output
		
		version = tonumber(p.branch(versions[#versions]))+0.01
		if p.isthereabeta then
			version = version + 0.01
		end
		version = tostring(version)
	end

	local out = "WRONG"
	if format == "version" then
		out = version
	elseif format == "branch" then
		out = p.branch( version )
	elseif format == "git" then
		out = p.git_branch( version )
	elseif format == "date" then
		out = p.releases[version]
	end

	return out
end

return p