Модуль:KharkivMetro

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация

Функции[править код]

NameByNum[править код]

Возвращает название линии Харьковского метрополитена (без слова "линия", если таковое присутствует). Параметр - номер линии или сокращение её названия (см. ниже).

ColorByNum[править код]

Возвращает цвет линии (наиболее близкий к официальной схеме). Параметр - номер линии или сокращение её названия (см. ниже).

interchange[править код]

Возвращает иконку с номером линии и, в зависимости от параметров, название линии или станции пересадки. Подробнее см. {{KHARKIVMETRO icon}}. Параметры:

  • line — номер или сокращение названия линии
  • size — размер иконки
  • station_dabbed — название статьи о станции пересадки
  • station — станция пересадки без уточнения
  • CPIC — непустое значение для кроссплатформенной пересадки
  • text, alt, small, style — так же, как в {{KHARKIVMETRO icon}}
Линия NameByNum ColorByNum {{KHARKIVMETRO icon}}
1 Холодногорско-Заводская 880000 Холодногорско-Заводская линия
2 Салтовская 0000FF Салтовская линия
3 Алексеевская 008800 Алексеевская линия
4 Кольцевая 800080 Кольцевая линия
0 остальные линии 231F20
local i18n = {
	NAMES = {
		['1']   = 'Холодногорско-Заводская',
		['2']   = 'Салтовская',
		['3']   = 'Алексеевская',
		['4']   = 'Кольцевая'
	},
	html = {
		icon_fmt = '<span title="%s">[[File:Kharkiv Metro Line %s.png|%spx|%s|link=%s]]</span>', -- parameters: alt, linenum, icon size, alt, link
		text_fmt = '[[%s|<span style="display:inline-block;line-height:%spx;height:%spx;font-size:%spx;font-style:normal;font-weight:bold;background:#%s;color:white;white-space:nowrap;text-align:center" title="%s">&thinsp;%s&thinsp;</span>]]', --[[
		                                          parameters: link, icon size, icon size, icon size - 3, color, alt, linenum   ]]
		small = '<span style="font-size:85%%">%s</span>',
		style = '<span style="%s">%s</span>',
		sortkey = '<span style="display:none" class="sortkey">%s</span>',
	},
	text = {
		transfer = 'Переход на станцию «%s» %s',
		dab = ' (станция метро)',
	},
	default = {
		icon_size = '15'
	}
}
i18n.line = function(num) -- название линии в именительном падеже
  return i18n.NAMES[num] .. ' линия'
end

i18n.link = function(num) -- ссылка на страницу линии
	return i18n.line(num)
end

i18n.ofLine = function(num) -- название линии в родительном падеже ("пересадка на станцию ... ... линии")
	return mw.ustring.sub(i18n.NAMES[num], 1, -3) .. 'ой линии'
end

local COLORS = { -- МЕНЯЙТЕ ЗНАЧЕНИЯ ЦВЕТОВ ТОЛЬКО ПОСЛЕ ОБСУЖДЕНИЯ
	['1']   = '880000', -- Холодногорско-Заводская
	['2']   = '0000FF', -- Салтовская
	['3']   = '008800', -- Алексеевская
	['4']   = '800080', -- Кольцевая
	['0']   = '231F20', -- для всех остальных планирующихся линий
}

local p = {}

function p.ColorByNum(frame)
	return COLORS[mw.text.trim(frame.args[1] or '')] or '[[Категория:Википедия:Статьи с неверно заданными параметрами модуля KharkivMetro]]'
end

function p.NameByNum(frame)
    return i18n.NAMES[mw.text.trim(frame.args[1] or '')] or '[[Категория:Википедия:Статьи с неверно заданными параметрами модуля KharkivMetro]]'
end

function p.interchange(frame)
	local num, station, station_dabbed, CPIC = frame.args['line'] or '', frame.args['station'] or '', frame.args['station_dabbed'] or '', frame.args['CPIC'] or '' ~= ''
	local icon_size, alt, text, small, style = frame.args['size'] or '', frame.args['alt'] or '', frame.args['text'] or '', frame.args['small'] or '', frame.args['style'] or ''
	local icon, station_stripped
	if not i18n.NAMES[num] then return '[[Категория:Википедия:Статьи с неверно заданными параметрами модуля KharkivMetro]]' end
	--local iconN = IconByNum(num)
	local iconN = num
	local Dx = num == 'D1' or num == 'D2' or  num == 'D3' or  num == 'D4' or  num == 'D5';
	if icon_size == '' then
		if Dx then icon_size = '22' 
		else icon_size = i18n.default.icon_size end
	elseif mw.ustring.sub(icon_size, -2 ) == 'px' then
		icon_size = mw.ustring.sub(icon_size, 1, -3 )
	end
	if alt == '' then
		if station ~= '' then
			alt = mw.ustring.format(i18n.text[CPIC ~= '' and 'CPIC' or 'transfer'], station, i18n.ofLine(num))
		elseif station_dabbed ~= '' then
			station_stripped = mw.ustring.match(station_dabbed, '(.-) %(') or station_dabbed
			alt = mw.ustring.format(i18n.text[CPIC ~= '' and 'CPIC' or 'transfer'], station_stripped, i18n.ofLine(num))
		else
			alt = i18n.line(num)
		end
	elseif station_dabbed ~= '' then
		station_stripped = mw.ustring.match(station_dabbed, '(.-) %(') or station_dabbed
	end
	local link = text == '' and (station_dabbed ~= '' and station_dabbed or (station ~= '' and station .. i18n.text.dab or i18n.link(num))) or i18n.link(num)
	if iconN then
		icon = mw.ustring.format(i18n.html.sortkey, mw.ustring.len(iconN) == 2 and iconN or '0' .. iconN) .. mw.ustring.format(i18n.html.icon_fmt, alt, iconN, icon_size, alt, link)
	else
		icon = mw.ustring.format(i18n.html.text_fmt, link, icon_size, icon_size, tonumber(icon_size) - 3, COLORS[num], alt, num)
	end
	if text == '' then return icon end
	
	function text2()
		return text == '2' and i18n.NAMES[num] or i18n.line(num)
	end
	
	local result = ''
	if station_dabbed ~= '' then
		result = '[[' .. station_dabbed .. '|' .. (station ~= '' and station or station_stripped) .. ']]'
	elseif station ~= '' then
		result = '[[' .. station .. i18n.text.dab .. '|' .. station .. ']]'
	elseif link == mw.title.getCurrentTitle().prefixedText then
		result = style ~= '' and mw.ustring.format(i18n.html.style, style, text2()) or text2()
	elseif text == '2' and num ~= 'ТПК' or style ~= '' or num == '5' then
		result = '[[' .. link .. '|' .. (style ~= '' and mw.ustring.format(i18n.html.style, style, text2()) or text2()) .. ']]'
	else
		result = '[[' .. link .. ']]'
	end
	if small ~= '' then result = mw.ustring.format(i18n.html.small, result) end
	return (not iconN and station == '' and station_dabbed == '' and '' or icon .. '&nbsp;') .. result
end

return p