Jump to content
Menü aufrufen
Toggle preferences menu
Persönliches Menü aufrufen
Nicht angemeldet
Ihre IP-Adresse wird öffentlich sichtbar sein, wenn Sie Änderungen vornehmen.
Modul Dokumentation[view][edit][history][purge]
Diese Dokumentation wird von Modul:Guide/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
Function list
L 13 — item
L 21 — pack
L 35 — trimMarkers
L 41 — getExplicitImage
L 56 — Guide.infobox

Dieses Modul setzt die Vorlage:Guide um. Anweisungen zur Verwendung findest du auf der Vorlagenseite.


require('strict')

--- Infobox for guide pages (Community-Content namespace).
--- InfoboxLua port replacing the capiunto box. Adds the base category
--- Kategorie:Guide and the author alias handle; invalid websites no longer
--- raise script errors but render as plain rows.
--- Called by Vorlage:Guide ({{#invoke:Guide|infobox}}).

local Guide = {}

local common = require('Module:Common')

local function item(label, content)
	if content == nil or content == '' then
		return nil
	end

	return { label = label, content = content }
end

local function pack(...)
	local out = {}

	for i = 1, select('#', ...) do
		local it = select(i, ...)
		if it ~= nil then
			table.insert(out, it)
		end
	end

	return out
end

--- Strips capiunto cell markers ('<><>col2') from '!' escape rows.
local function trimMarkers(value)
	return mw.text.split(value, '<>', true)[1]
end

--- Explicit image without the File: prefix, only honored when the file
--- exists (mirrors Module:Organisation and Module:Projekt).
local function getExplicitImage(raw)
	if raw == nil or raw == '' then
		return nil
	end

	local name = raw:gsub('^[Dd]atei%:[%s]*', ''):gsub('^[Ff]ile%:[%s]*', '')
	local ok, title = pcall(mw.title.makeTitle, 'File', name)

	if ok and title ~= nil and title.file ~= nil and title.file.exists == true then
		return name
	end

	return nil
end

function Guide.infobox(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local categories = {
		'[[Kategorie:Guide]]',
	}

	local items = {}
	local websiteItem

	local author = args.author or args.handle

	if author ~= nil and author ~= '' then
		table.insert(
			items,
			item('Autor', '[https://robertsspaceindustries.com/citizens/' .. author .. ' ' .. author .. ']')
		)
	else
		table.insert(categories, '[[Kategorie:Guide mit fehlendem Autor]]')
	end

	if args.guide_type ~= nil and args.guide_type ~= '' then
		local lowered = mw.ustring.lower(args.guide_type)
		local label = args.guide_type

		-- canonical spelling for the category, whatever casing the editor used
		if lowered == 'star citizen' then
			label = 'Star Citizen'
			table.insert(categories, '[[Kategorie:Guide (Star Citizen)]]')
		elseif lowered == 'squadron 42' then
			label = 'Squadron 42'
			table.insert(categories, '[[Kategorie:Guide (Squadron 42)]]')
		end

		table.insert(items, item('Guide für', label))
	else
		table.insert(categories, '[[Kategorie:Guide mit fehlendem Typen]]')
	end

	if args.topic ~= nil and args.topic ~= '' then
		table.insert(items, item('Thematik', args.topic))
	else
		table.insert(categories, '[[Kategorie:Guide mit fehlendem Thema]]')
	end

	if args.website ~= nil and args.website ~= '' then
		if args.website:match('^https?://') then
			websiteItem = item('Webseite', args.website)
			mw.smw.set({ Webseite = args.website })
		else
			websiteItem = item('Webseite', args.website)
		end
	end

	local information = pack(items[1], items[2], items[3], websiteItem, item('Sonstiges', args.other))

	-- '!' escape rows from capiunto times, in sorted order
	local escapeKeys = {}

	for key, value in pairs(args) do
		if type(key) == 'string' and key:sub(1, 1) == '!' and type(value) == 'string' and value ~= '' then
			table.insert(escapeKeys, key)
		end
	end

	table.sort(escapeKeys)

	for _, key in ipairs(escapeKeys) do
		table.insert(information, item(key:sub(2), trimMarkers(args[key])))
	end

	local infobox = require('Module:InfoboxLua')

	common.setDisplayTitle(frame, 'Guide: ' .. mw.title.getCurrentTitle().subpageText)

	return infobox.render({
		title = 'Übersicht',
		image = getExplicitImage(args.logo or args.image),
		imageUploadName = mw.title.getCurrentTitle().subpageText .. ' Logo',
		sections = {
			{
				columns = 2,
				items = information,
			},
		},
	}) .. table.concat(categories, '')
end

return Guide
Cookies helfen uns bei der Bereitstellung dieses Wikis. Durch die Nutzung des Star Citizen Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.