v50 Steam/Premium information for editors
- v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
- Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.
Difference between revisions of "Module:Versions"
Jump to navigation
Jump to search
(+isNamespace*) |
(+normalizeNamespace, rearrange) |
||
Line 15: | Line 15: | ||
namespace = 'v0.31', | namespace = 'v0.31', | ||
versions = {'0.31'}, | versions = {'0.31'}, | ||
+ | aliases = {'DF2010'}, | ||
}, | }, | ||
{ | { | ||
namespace = 'v0.34', | namespace = 'v0.34', | ||
versions = {'0.34'}, | versions = {'0.34'}, | ||
+ | aliases = {'DF2012'}, | ||
}, | }, | ||
{ | { | ||
namespace = 'DF2014', | namespace = 'DF2014', | ||
versions = {'0.40', '0.42', '0.43', '0.44', '0.47'}, | versions = {'0.40', '0.42', '0.43', '0.44', '0.47'}, | ||
+ | aliases = {'cv'}, | ||
}, | }, | ||
-- mods: use the canonical name for the namespace index too, because they aren't sequenced | -- mods: use the canonical name for the namespace index too, because they aren't sequenced | ||
Line 32: | Line 35: | ||
local namespace_to_data = {} | local namespace_to_data = {} | ||
local version_to_namespace = {} | local version_to_namespace = {} | ||
+ | local alias_to_namespace = {} | ||
for i, data in pairs(namespaces) do | for i, data in pairs(namespaces) do | ||
if tonumber(i) ~= nil then | if tonumber(i) ~= nil then | ||
Line 42: | Line 46: | ||
data.category_prefix = data.namespace | data.category_prefix = data.namespace | ||
end | end | ||
− | for _, version in pairs(data.versions) do | + | for _, version in pairs(data.versions or {}) do |
version_to_namespace[version] = data.namespace | version_to_namespace[version] = data.namespace | ||
+ | end | ||
+ | for _, alias in pairs(data.aliases or {}) do | ||
+ | alias_to_namespace[alias] = data.namespace | ||
+ | alias_to_namespace[string.lower(alias)] = data.namespace | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function env.isNamespaceKnown(ns) | ||
+ | if namespace_to_data[string.lower(ns)] then | ||
+ | return true | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function env.isNamespaceVersioned(ns) | ||
+ | if env.getIndexForNamespace(ns, '') ~= '' then | ||
+ | return true | ||
end | end | ||
end | end | ||
Line 99: | Line 119: | ||
end | end | ||
− | function env. | + | function env.normalizeNamespace(ns) |
− | + | ns = string.lower(ns) | |
− | + | ns = alias_to_namespace[ns] or ns | |
− | + | if env.isNamespaceKnown(ns) then | |
− | + | return namespace_to_data[ns].namespace | |
− | |||
− | |||
− | if env. | ||
− | return | ||
end | end | ||
+ | error('Unknown namespace: ' .. ns) | ||
end | end | ||
return env | return env |
Revision as of 23:27, 27 November 2022
local env = {}
local namespaces = {
{
-- namespace is the canonical namespace name (not an alias), e.g. the list at Special:AllPages
namespace = '23a',
-- versions are sorted in ascending order
versions = {'0.21', '0.22', '0.23'},
},
{
namespace = '40d',
versions = {'0.27', '0.28'},
},
{
namespace = 'v0.31',
versions = {'0.31'},
aliases = {'DF2010'},
},
{
namespace = 'v0.34',
versions = {'0.34'},
aliases = {'DF2012'},
},
{
namespace = 'DF2014',
versions = {'0.40', '0.42', '0.43', '0.44', '0.47'},
aliases = {'cv'},
},
-- mods: use the canonical name for the namespace index too, because they aren't sequenced
Masterwork = {
namespace = 'Masterwork',
versions = {},
},
}
local namespace_to_data = {}
local version_to_namespace = {}
local alias_to_namespace = {}
for i, data in pairs(namespaces) do
if tonumber(i) ~= nil then
data.index = i
end
data.canonical_version = data.versions[#data.versions]
namespace_to_data[data.namespace] = data
namespace_to_data[string.lower(data.namespace)] = data
if not data.category_prefix then
data.category_prefix = data.namespace
end
for _, version in pairs(data.versions or {}) do
version_to_namespace[version] = data.namespace
end
for _, alias in pairs(data.aliases or {}) do
alias_to_namespace[alias] = data.namespace
alias_to_namespace[string.lower(alias)] = data.namespace
end
end
function env.isNamespaceKnown(ns)
if namespace_to_data[string.lower(ns)] then
return true
end
end
function env.isNamespaceVersioned(ns)
if env.getIndexForNamespace(ns, '') ~= '' then
return true
end
end
function env.versionToNamespace(version, default)
local parts = mw.text.split(version:gsub('^v', ''), '.', true)
local key = ''
while #parts > 0 do
if key ~= '' then
key = key .. '.'
end
key = key .. table.remove(parts, 1)
if version_to_namespace[key] then
return version_to_namespace[key]
end
end
if default then
return default
end
error('Unknown version: ' .. version)
end
function env.getNamespaceByIndex(i, default)
local data = namespaces[tonumber(i)]
if data then
return data.namespace
elseif default then
return default
else
error('Unknown namespace index: ' .. tostring(i))
end
end
function env.getIndexForNamespace(ns, default)
local data = namespace_to_data[string.lower(ns)]
if data then
return data.index
elseif default then
return default
else
error('Unknown namespace: ' .. tostring(ns))
end
end
function env.getIndexForVersion(v, default)
return env.getIndexForNamespace(env.versionToNamespace(v, default), default)
end
function env.getIndexFor(key, default)
local res = env.getIndexForNamespace(key, '')
if res ~= '' then
return res
end
return env.getIndexForVersion(key, default)
end
function env.normalizeNamespace(ns)
ns = string.lower(ns)
ns = alias_to_namespace[ns] or ns
if env.isNamespaceKnown(ns) then
return namespace_to_data[ns].namespace
end
error('Unknown namespace: ' .. ns)
end
return env