Модул:Маъноҳои дигар

Мавод аз Википедиа — донишномаи озод

local get_args = require('Модуль:Arguments').getArgs
local mHatnote = require('Модуль:Hatnote')

local p = {}

function p.main(frame)
	local args = get_args(frame)
	local prefixes = mw.loadData('Модуль:Другие значения/префиксы')
	local remove_precision = mHatnote.remove_precision
	local disambig_type = args.type or args['тип'] or 'default'
	local tracking_categories = {
		red_link = 'Другие значения: указана несуществующая страница',
		no_links = 'Другие значения: не найдена страница значений',
		bad_type = 'Другие значения: указан несуществующий тип',
		deprecated_param = 'Википедия:Страницы с шаблоном Другие значения с устаревшим параметром'
	}
	
	local categories = mHatnote.define_categories(tracking_categories)
	local prefix = prefixes[disambig_type]
	if not prefix then
		prefix = prefixes.default
		categories:add('bad_type')
	elseif type(prefix) == 'table' then
		prefix = prefix.singular
	end
	
	local hatnote_args = {
		prefix = prefix,
		hide_disambig = true,
		dot = true,
		preview_error = true
	}
	
	if args[2] then
		categories:add('deprecated_param')
	end
	
	local disambig_page = args[1] or args[2]
	if not disambig_page then
		local without = remove_precision{mw.title.getCurrentTitle().prefixedText}
		local with = without .. ' (значения)'
		if disambig_page ~= with and mw.title.new(with).exists then
			disambig_page = with
		elseif disambig_page ~= without and mw.title.new(without).exists then
			disambig_page = without
		else
			disambig_page = with
		end
	elseif not mw.title.new(disambig_page).exists then
		local without = remove_precision{disambig_page}
		local with = without .. ' (значения)'
		if disambig_page ~= with and mw.title.new(with).exists then
			disambig_page = with
		elseif disambig_page ~= without and mw.title.new(without).exists then
			disambig_page = without
		end
	end

	hatnote_args[1] = disambig_page
	hatnote_args['l1'] = args['l1'] or disambig_page
	
	return mHatnote.main(hatnote_args, tracking_categories) .. categories
end

return p