Jump to content

Module:Database report

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by SD0001 (talk | contribs) at 17:02, 17 June 2021 (simple module for basic template syntax checking). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local getArgs = require('Module:Arguments').getArgs

local p = {}

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

local function error(text)
	return '*' .. require('Module:Error').error{ 'Invalid config: ' .. text, tag = 'p' }
end 

local function has_value(array, val)
    for index, value in ipairs(array) do
        if value == val then
            return true
        end
    end
    return false
end

local function get_namespaces(namespaces_list)
	local list = {}
	for token in string.gmatch(namespaces_list, "%d+") do
		local ns_id = tonumber(token)
		table.insert(list, ns_id ~= 0 and lowerfirst(mw.site.namespaces[ns_id]['name']) or 'main')
	end
	return table.concat(list, ', ')
end 	


function p.check_syntax(args)
	
	-- check for invalid parameters
	for param, value in pairs(args) do
		if not has_value({'sql', 'wikilinks', 'excerpts', 'comments', 'widths', 'table_style', 'remove_underscores', 'update'}, param) then
			return error('unknown parameter: ' .. param .. ' used')
		end
	end
	
	-- check that required parameters are provided
	if not args.sql then
		return error('required parameters "bot" and/or "task" missing')
	end
	
	return ''
end

return p