Вукипедия
Advertisement
Вукипедия
41 643
страницы

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

-- Этот модуль принадлежит [[Вукипедия:Шаблоны|шаблону]] [[Шаблон:TORcite|TORcite]].

local p = {}

local function makeCategoryLink(cat)
	-- "Категория" разделяется здесь так что модуль не переведен в состояние
	-- категория "%s", когда страница сохранена.
	return string.format('[[%s:%s]]', 'Категория', cat)
end

local function makeWikitextError(msg)
	local ret = ''
	ret = ret .. string.format(
		'<strong class="error">[[Шаблон:TORcite]] error: %s.</strong>',
		msg
	)
	if mw.title.getCurrentTitle().namespace == 0 then
		ret = ret .. makeCategoryLink('Страницы с ошибками шаблонов')
	end
	return ret
end

local function check(str)
	if str == nil then
		str = ""
	end
	return str
end

function p.citation(args, data)
	local image = "[[Файл:SWTOR mini.png|x14px|link=Star Wars: The Old Republic]] "

	local game = "''[[Star Wars: The Old Republic]] ''&mdash; "
	if args.exp then
		game = data.expansions[args.exp]
	end

	local src = ''
	if args.chapter then
		local chap = tonumber(args.chapter)
		if not chap then
			src = args[1] or '{{{1}}}'
		else
			if args.exp then
				src = data.chapters[args.exp][chap]
			else
				src = data.chapters.kotfe[chap]
			end
		end
	else		
		local mode = data.modes[args.type]
		if not mode then
			src = args[1] or '{{{1}}}'
		else
			src = check(mode.a) .. check(args[1]) .. check(mode.b) .. check(args[2]) .. check(mode.c) .. check(args[3])
		end
	end

	local result = image .. game .. src
	return result
end

function p.main(frame)
	local data = mw.loadData('Модуль:TORcite/data')
	local args = {}
	for k, v in pairs(frame:getParent().args) do 
		v = v:match('^%s*(.-)%s*$') -- trim whitespace
		if v ~= '' then
			args[k] = v
		end
	end
	return p.citation(args, data) or '{{{1}}}'
end

return p
Advertisement