м (test2) |
мНет описания правки |
||
Строка 89: | Строка 89: | ||
params.title = text |
params.title = text |
||
− | local template = require( [[Модуль:uBox]] ).box( { frame = { args = |
+ | local template = require( [[Модуль:uBox]] ).box( { frame = { args = params } } ) |
local result = template |
local result = template |
||
if not args["некат"] then |
if not args["некат"] then |
Версия от 15:09, 9 июня 2021
Модуль реализует шаблон {{Только для}} посредством сборки шаблона {{Ambox}}.
local p = {}
-- Приведение названий изданий к нормализованным
local edition_names = {
["компьютер"] = "java",
["пк"] = "java",
["java"] = "java",
["Java"] = "java",
["pocket"] = "bedrock",
["Pocket"] = "bedrock",
["bedrock"] = "bedrock",
["Bedrock"] = "bedrock",
["console"] = "console",
["Console"] = "console",
["legacy console"] = "console",
["Legacy console"] = "console",
["PlayStation 4"] = "ps4",
["ps4"] = "ps4",
["education"] = "education",
["Education"] = "education",
["new3ds"] = "3ds",
["New3ds"] = "3ds",
["nintendo"] = "3ds",
["Nintendo"] = "3ds",
["new nintendo 3ds"] = "3ds",
["New Nintendo 3DS"] = "3ds",
["earth"] = "minecraft earth",
["Minecraft earth"] = "minecraft earth",
["Minecraft Earth"] = "minecraft earth",
["Earth"] = "minecraft earth",
}
-- Данные об изданиях
local editions = {
["java"] = {link = "Java Edition", title = "Java Edition", category = "Java Edition"},
["bedrock"] = {link = "Bedrock Edition", title = "Bedrock Edition", category = "Bedrock Edition"},
["console"] = {link = "Legacy Console Edition", title = "Legacy Console Edition", category = "Legacy Console Edition"},
["ps4"] = {link = "PlayStation 4 Edition", title = "PlayStation 4 Edition", category = "PlayStation 4 Edition"},
["education"] = {link = "Education Edition", title = "Education Edition", category = "Education Edition"},
["3ds"] = {link = "New Nintendo 3DS Edition", title = "New Nintendo 3DS Edition", category = "New Nintendo 3DS Edition"},
["minecraft earth"] = {link = "Minecraft Earth", title = "Minecraft Earth", category = "Minecraft Earth"}
}
function p.only(f)
local args = f.args or f
if f == mw.getCurrentFrame() and args[1] == nil then
args = f:getParent().args
end
local params = {}
local edition_text = {}
local categories = {}
local lang = mw.language.getContentLanguage()
for i, v in ipairs(args) do
local edition_name = mw.text.trim(v)
if edition_names[edition_name] then
local edition = editions[edition_names[edition_name]]
table.insert(edition_text, ("[[%s|%s]]"):format(edition.link, edition.title))
table.insert(categories, ("[[Категория:%s]]"):format(edition.category))
else
local link = lang:ucfirst(edition_name) .. " Edition"
table.insert(edition_text, ("[[%s]]"):format(link))
table.insert(categories, ("[[Категория:%s]]"):format(edition_name))
end
end
local text = "'''Только для "
local n_editions = #edition_text
for i, link in ipairs(edition_text) do
if i > 1 then
if i == n_editions then
text = text .. " и "
else
text = text .. ", "
end
end
text = text .. link
end
text = text .. "'''"
params.class = "ubox-blue subentries-template msgbox-onlyfor"
params.title = text
local template = require( [[Модуль:uBox]] ).box( { frame = { args = params } } )
local result = template
if not args["некат"] then
local title = mw.title.getCurrentTitle()
-- namespace 2 — «Участник»
if title.namespace ~= 2 and not title.isTalkPage then
result = template .. table.concat(categories)
end
end
return result
end
return p