Модуль:Іншыя значэньні
Выгляд
Гэты модуль стварае й рэалізуе шаблён {{Іншыя значэньні}}.
-- Апрацоўвае шаблён {{Іншыя значэньні}}
local mHatnote = require('Модуль:Іншае значэньне')
local mHatlist = require('Модуль:Сьпіс верхніх зносак')
local mArguments -- лянівая ініцыялізацыя
local mTableTools -- лянівая ініцыялізацыя
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local p = {}
-- Стварае стандартны {{Іншыя значэньні}}
function p.otheruses(frame)
mArguments = require('Модуль:Аргумэнты')
mTableTools = require('Модуль:TableTools')
local args = mTableTools.compressSparseArray(mArguments.getArgs(frame))
local title = mw.title.getCurrentTitle().prefixedText
return p._otheruses(args, {title=title})
end
-- Стварае «іншыя [x]» шаблёны з дапамогай otherText пры выкліку функцыі
function p.otherX(frame)
mArguments = require('Модуль:Аргумэнты')
mTableTools = require('Модуль:TableTools')
local x = frame.args[1]
local args = mTableTools.compressSparseArray(
mArguments.getArgs(frame, {parentOnly = true})
)
local options = {
title = mw.title.getCurrentTitle().prefixedText,
otherText = x
}
return p._otheruses(args, options)
end
-- Асноўны генэратар
function p._otheruses(args, options)
-- Праверка тыпаў і дапомных значэньняў
checkType('_otheruses', 1, args, 'table', true)
args = args or {}
checkType('_otheruses', 2, options, 'table')
if not (options.defaultPage or options.title) then
error('У табліцы опцыяў _otheruses няма дапомных зьвестак загалоўку', 2)
end
local emptyArgs = true
for k, v in pairs(args) do
if type(k) == 'number' then emptyArgs = false break end
end
if emptyArgs then
args = {
options.defaultPage or
mHatnote.disambiguate(options.title, options.disambiguator)
}
end
-- Ствараем спасылкі ўручную
local links = {}
for i, page in ipairs(args) do
table.insert(links, string.format("[[%s]]", page))
end
local linksText = table.concat(links, ', ')
local text = string.format("Гэтая назва мае некалькі сэнсаў. Калі вас цікавяць іншыя сэнсы, глядзіце %s.", linksText)
-- Вяртаем верхнюю зноску
return mHatnote._hatnote(text)
end
return p