Модуль:Hatnote list

Википеди материал

Для документации этого модуля может быть создана страница Модуль:Hatnote list/doc

local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local p = {}

--default options table used across the list stringification functions
local stringifyListDefaultOptions = {
	conjunction = 'и',
	separator = ',',
	altSeparator = ';',
	space = ' ',
	formatted = false
}

--Searches display text only
local function searchDisp(haystack, needle)
	return string.find(
		string.sub(haystack, (string.find(haystack, '|') or 0) + 1), needle
	)
end

-- Stringifies a list generically; probably shouldn't be used directly
local function stringifyList(list, options)
	-- Type-checks, defaults, and a shortcut
	checkType('stringifyList', 1, list, 'table')
	if #list == 0 then return nil end
	checkType('stringifyList', 2, options, 'table', true)
	options = options or {}
	for k, v in pairs(stringifyListDefaultOptions) do
		if options[k] == nil then options[k] = v end
	end
	local s = options.space
	-- Set the separator; if any item contains it, use the alternate separator
	local separator = options.separator
	for k, v in pairs(list) do
		if searchDisp(v, separator) then
			separator = options.altSeparator
			break
		end
	end
	-- Set the conjunction
	local conjunction = s .. options.conjunction .. s
	-- Return the formatted string
	return mw.text.listToText(list, separator .. s, conjunction)
end

--DRY function
function p.conjList (conj, list, fmt)
	return stringifyList(list, {conjunction = conj, formatted = fmt})
end

function p.disambiguate(page, disambiguator)
	-- Форматирует заголовок страницы со скобками для устранения неоднозначности,
	-- то есть «Пример» → «Пример (значения)».
	checkType('disambiguate', 1, page, 'string')
	checkType('disambiguate', 2, disambiguator, 'string', true)
	disambiguator = disambiguator or 'маӀанаш'
	return mw.ustring.format('%s (%s)', page, disambiguator)
end

function p.forSee(z)
	if z then return z .. ' хьажа' end
	return 'см. также'
end

function p.otherUse(z, y)
	if not y then return '' end
	if z then return '[[' .. y .. ']]' end
	return '[[' .. y .. '|кхыдола маӀанаш]]'
end

return p