Modul:Service portal listing

IMT HilfeWiki - das Wiki
Documentation icon Module documentation
This module implements template {{Service portal listing}}.

Usage[Quelltext bearbeiten]

{{#invoke:Service portal listing|main}}

Note[Quelltext bearbeiten]

This module uses the following templates:

local getArgs = require('Module:Arguments').getArgs
local _CFG = mw.loadData('Modul:Article/config')	-- it is intended to load article's config
local _TT = require('Module:TableTools')
local _SMWUTIL = require('Module:SmwUtil')

local p = {}

-- 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, 'Service portal listing'}})
			errorBoxes:newline()
		end
	end
	return errorBoxes
end

-- executes an smw query 
local function executeLegacyQuery(uservalues)
	local service = uservalues.service or mw.title.getCurrentTitle().rootText
	local query = {
		select = { '[[Is associated to service.shows on service landing page::' .. service .. ']] ',
			'[[Is of type::' .. table.concat(uservalues.type, '||') .. ']]',
		},
		fields = {
			'?#',
			'?Is related to os#',
			'?Is written for target audience#',
			'?Is disambiguation page#',
			'?Is disambiguated by#',
			'?Is of type#'
		}
	}
	local attributes = {
		format = 'template',
		mainlabel = '-',
		sort = 'has sortkey,Is disambiguation page,Is related to os',
		order = 'asc,desc,asc',
		limit = 250,
		template = 'Service portal listing/table row',
		introtemplate = 'Service portal listing/table header',
		outrotemplate = 'Service portal listing/table footer',
	}
	local rawaskResult = _SMWUTIL.rawask(query, attributes)
	return rawaskResult
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 = {}
	
	-- 1st parameter: type
	if args['type'] then
		local valid = {}
		for fragment in mw.text.gsplit(args['type'], ',', true) do
			fragment = mw.text.trim(fragment)
			if fragment and mw.ustring.len(fragment) > 0 then
				if _TT.inTable(_CFG.validValues['type'], fragment) then
					table.insert(valid, fragment)
				else
					table.insert(errors, "Parameter ''type'' hat einen ungültigen Wert: \"" .. fragment .. "\"!")
				end
			end
		end
		processedArgs['type'] = valid
	else
		processedArgs['type'] = { 'Anleitung' }
	end

	-- 2nd parameter (OPTIONAL): service
	processedArgs['service'] = nil
	if args['service'] then
		processedArgs['service'] = mw.text.trim(args['service'])
	end
	
	-- Note: for legacy reasons, we assume that calls can contaon the additional parameter "type"
	-- since 2023 (transition to lua) this will be ignored
	
	return processedArgs, errors
end

function p._main(args)
	
	-- sanity, plausibiliy and defaults:
	local uservalues, errors = processArgs(args)
	local output = mw.html.create('')
	if #errors > 0 then
		output:newline()
		output:node(createErrorNode(errors))
	else
		local result = executeLegacyQuery(uservalues)
		output:wikitext(result)
	end
	return tostring(output)
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
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.