Module:Version
Appearance
From mediawiki.org
This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
The main entrypoint is the get function.
First parameter is the release type, which can be one of the following:
stablelegacyltsbetaalpha
Second parameter is the format, which can be one of the following:
versionbranchgitdate
Note that alpha and beta only work with branch, the behavior of other output formats is undefined.
Examples
{{#invoke:Version|get|alpha|branch}}: 1.46{{#invoke:Version|get|beta|branch}}: 1.45{{#invoke:Version|get|stable|version}}: 1.44.2{{#invoke:Version|get|stable|branch}}: 1.44{{#invoke:Version|get|stable|git}}: REL1_44{{#invoke:Version|get|stable|date}}: 2025年10月03日{{#invoke:Version|get|lts|version}}: 1.43.5{{#invoke:Version|get|legacy|version}}: 1.43.5{{#invoke:Version|get|legacylts|version}}: 1.39.15
That said, you probably want to use one of the wrapper templates in Category:MediaWiki version information templates instead of calling this module directly.[why? ]
The above documentation is transcluded from Module:Version/doc. (edit | history)
Editors can experiment in this module’s sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module’s sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.
localp={} localreleases={} -- HEY YOU, UPDATE THESE releases["1.44.2"]="2025年10月03日" releases["1.43.5"]="2025年10月03日" releases["1.39.15"]="2025年10月03日" -- Is there a beta branch that isn't a proper release yet? p.isthereabeta=true -- OKAY YOU CAN STOP NOW -- Iterate in reverse -- from http://lua-users.org/wiki/IteratorsTutorial functionripairs(t) localfunctionripairs_it(t,i) i=i-1 localv=t[i] ifv==nilthenreturnvend returni,v end returnripairs_it,t,#t+1 end p.releases=releases -- get trimmed version like "1.XX" functionp.branch(version) returnstring.sub(version,0,4) end -- git branch like REL1_XX functionp.git_branch(version) return"REL1_"..string.sub(p.branch(version),3) end -- is the given version an LTS release? functionp.islts(version) -- if we ever cut a 2.x release this will need to be rethought localx=tonumber(string.sub(p.branch(version),3)) ifx<19thenreturnfalseend -- every 4th release starting with 1.19 is an LTS return((x-19)%4)==0 end functionp.get(frame) returnp.version(frame.args[1],frame.args[2]) end -- main function -- release: stable, legacy, legacylts, lts, alpha -- format: version, branch, git, date functionp.version(release,format) localversions={} fork,vinpairs(p.releases)do table.insert(versions,k) end table.sort(versions) --mw.logObject(versions) --mw.log(#versions) localversion="0.0.0" ifrelease=="stable"then version=versions[#versions] elseifrelease=="legacy"then version=versions[#versions-1] elseifrelease=="lts"then fori,vinipairs(versions)do -- this might not be right. ifp.islts(v)then version=v end end elseifrelease=="legacylts"then -- the oldest LTS version is the legacy LTS version. -- (e.g. when there are both 1.23.x and 1.27.x releases, choose 1.23.x) fori,vinripairs(versions)do ifp.islts(v)then version=v end end elseif(release=="alpha"orrelease=="beta")then -- alpha and beta only works with "branch" output version_parts=mw.text.split(p.branch(versions[#versions]),".",true) version_parts[2]=tonumber(version_parts[2])+1 if(p.isthereabetaandrelease=="alpha")then version_parts[2]=tonumber(version_parts[2])+1 end version=table.concat(version_parts,".") if(notp.isthereabetaandrelease=="beta")then version="—" end end localout="WRONG" ifformat=="version"then out=version elseifformat=="branch"then out=p.branch(version) elseifformat=="git"then out=p.git_branch(version) elseifformat=="date"then out=p.releases[version] end returnout end returnp