Modul:Os family

IMT HilfeWiki - das Wiki
Documentation icon Module documentation
This module implements template {{Os family}}.

Usage[Quelltext bearbeiten]

{{#invoke:Os family|main}}

local getArgs = require('Module:Arguments').getArgs
local _INFOBOX = require('Module:Infobox').infobox
local _SMW = require('Module:SmwUtil')

-- helper vars, standing in for missing config
local category = 'Betriebssystemfamilien'

local p = {}

local function getCurrentOs(family)
	local family = family
	
	local query = { select = '[[is member of os family::' .. family .. ']]' }
	local options = { sort='was released in', order='desc', limit=1 }
	
	local result = _SMW.ask(query, options)
	
	if not result or #result < 1 or not result[1]['PageName'] then
		return nil
	else
		return result[1]['PageName']
	end
end

local function compileInfobox(processedArgs)
	
	local family = mw.title.getCurrentTitle().rootText
	local current = getCurrentOs(family)

	local ib_args = {
--		aboveclass = 'objtitle titletext',
		above = family,
		image = processedArgs.image,
		subheader = 'Entwickler: ' .. processedArgs.developer,
		caption = family,
--		headerclass = 'headertext',
		labelstyle = 'width: 30%;',
		datastyle = 'width: 70%;',
		header1 = "Informationen",
		label2 = 'Entwickler/r',
		data2 = processedArgs.developer,
		label3 = 'Aktuelle Version',
		data3 = current,
	}
	return _INFOBOX(ib_args)
end

-- creates an mw.html node, containing (an) errorbox(es), if errors are present.
--	in this case, Category:Erroneous will be set by template Template warning
local function createErrorNode(errors)
	local errorBoxes = mw.html.create('')
	local frame = mw.getCurrentFrame()
	if #errors > 0 then
		for _, errorText in pairs(errors) do
			errorBoxes:wikitext(frame:expandTemplate{title = 'Template warning', args={errorText, 'Os family'}})
			errorBoxes:newline()
		end
	end
	return errorBoxes
end

-- Here we process the supplied args, sanitize then, check for plausibility and set defaults, if needed
local function processArgs(args)
	local errors = {}
	local processedArgs = {}

	-- we need to process the following arguments: image, developer
	-- 1st parameter (OPTIONAL): image
	-- if empty, try a fallback name
	-- else if encased in [[]], then use directly
	-- else if contains . then encase it in [[]] and use
	processedArgs.image = '[[File:Logo_' .. mw.title.getCurrentTitle().rootText .. '.png]]'
	if args.image and mw.ustring.len(mw.text.trim(args.image)) then
		local suppliedImage = mw.text.trim(args.image)
		if mw.ustring.match(suppliedImage, '^%[%[.+%]%]$') then
			processedArgs.image = suppliedImage
		elseif mw.ustring.find(suppliedImage, '.', 1, true) then
			processedArgs.image = '[[File:' .. suppliedImage .. ']]'
		else
			table.insert(errors, "Parameter ''image'' hat einen ungültigen Wert: \"" .. image .. "\"!")
			processedArgs.image = '[[File:Logo_' .. mw.title.getCurrentTitle().rootText .. '.png]]'
		end
	end

	-- 2nd parameter (OPTIONAL): developer
	processedArgs.developer = 'nicht angegeben'
	if args.developer and mw.ustring.len(mw.text.trim(args.developer)) then
		processedArgs.developer = mw.text.trim(args.developer)
	end

	return processedArgs, errors
end

function p._main(args)
	
	-- sanity, plausibiliy and defaults:
	local processedArgs, errors = processArgs(args)
	
	-- add infobox
	local output = mw.html.create('')
	output:wikitext(compileInfobox(processedArgs))
	output:newline()

	-- display errors, if there are some
	if #errors > 0 then
		output:newline()
		output:node(createErrorNode(errors))
	end

	-- add category
	output:wikitext('[[Category:' .. category .. ']]')

	return tostring(output)
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p.dl(arg)
	
	local processedArgs, errors = processArgs(arg)
	--return compileInfobox(processedArgs)
	--return p._main(arg)
	local result, query = getCurrentOs(arg)
	return result
end

return p
Cookies helfen uns bei der Bereitstellung des IMT HilfeWikis. Bei der Nutzung vom IMT HilfeWiki werden die in der Datenschutzerklärung beschriebenen Cookies gespeichert.