<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.avardon.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AParamvalidate</id>
	<title>Module:Paramvalidate - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.avardon.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AParamvalidate"/>
	<link rel="alternate" type="text/html" href="https://wiki.avardon.com/index.php?title=Module:Paramvalidate&amp;action=history"/>
	<updated>2026-04-28T19:01:02Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.avardon.com/index.php?title=Module:Paramvalidate&amp;diff=66&amp;oldid=prev</id>
		<title>Rataj: Created page with &quot;local libraryUtil = require(&#039;libraryUtil&#039;) local checkType = libraryUtil.checkType local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg local mArguments -- initialize lazily local p = {} local categories = {}   --- Format table of strings into category wikitext --- @return string local function tableToCategory() 	local wikitext = {} 	for _, category in ipairs(categories) do 		table.insert(wikitext, string.format(&#039;Category:%s&#039;, category)) 	end 	return table.c...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.avardon.com/index.php?title=Module:Paramvalidate&amp;diff=66&amp;oldid=prev"/>
		<updated>2025-10-30T18:01:05Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local libraryUtil = require(&amp;#039;libraryUtil&amp;#039;) local checkType = libraryUtil.checkType local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg local mArguments -- initialize lazily local p = {} local categories = {}   --- Format table of strings into category wikitext --- @return string local function tableToCategory() 	local wikitext = {} 	for _, category in ipairs(categories) do 		table.insert(wikitext, string.format(&amp;#039;&lt;a href=&quot;/index.php?title=Category:%25s&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:%s (page does not exist)&quot;&gt;Category:%s&lt;/a&gt;&amp;#039;, category)) 	end 	return table.c...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local libraryUtil = require(&amp;#039;libraryUtil&amp;#039;)&lt;br /&gt;
local checkType = libraryUtil.checkType&lt;br /&gt;
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg&lt;br /&gt;
local mArguments -- initialize lazily&lt;br /&gt;
local p = {}&lt;br /&gt;
local categories = {}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--- Format table of strings into category wikitext&lt;br /&gt;
--- @return string&lt;br /&gt;
local function tableToCategory()&lt;br /&gt;
	local wikitext = {}&lt;br /&gt;
	for _, category in ipairs(categories) do&lt;br /&gt;
		table.insert(wikitext, string.format(&amp;#039;[[Category:%s]]&amp;#039;, category))&lt;br /&gt;
	end&lt;br /&gt;
	return table.concat(wikitext)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Validates if the given image file extension is one of the supported types (gif, png, jpg, jpeg, webp).&lt;br /&gt;
--- Return true if the extension is valid, false if isn&amp;#039;t (the input parameter is likely incorrect)&lt;br /&gt;
--- @param image string - The image argument of the template&lt;br /&gt;
--- @return boolean&lt;br /&gt;
local function checkImageExtension(image)&lt;br /&gt;
	local EXTENSIONS = {&lt;br /&gt;
		&amp;#039;gif&amp;#039;,&lt;br /&gt;
		&amp;#039;png&amp;#039;,&lt;br /&gt;
		&amp;#039;jpg&amp;#039;,&lt;br /&gt;
		&amp;#039;JPG&amp;#039;,&lt;br /&gt;
		&amp;#039;jpeg&amp;#039;,&lt;br /&gt;
		&amp;#039;svg&amp;#039;,&lt;br /&gt;
		&amp;#039;webp&amp;#039;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	for _, extension in ipairs(EXTENSIONS) do&lt;br /&gt;
		local pattern = &amp;quot;%.&amp;quot; .. extension .. &amp;quot;$&amp;quot;&lt;br /&gt;
		if string.match(image, pattern) then&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	table.insert(categories, &amp;#039;Pages with invalid image argument in template&amp;#039;)&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Check if the image actually exists and whether it has the sufficient width for the infobox&lt;br /&gt;
--- @param image string - The image argument of the template&lt;br /&gt;
--- @return nil&lt;br /&gt;
local function checkImageMetadata(image)&lt;br /&gt;
	local MIN_WIDTH = 640 -- 320px is the infobox width, 2x for HiDPI screens&lt;br /&gt;
	local MAX_HEIGHT = 960&lt;br /&gt;
&lt;br /&gt;
	local title = mw.title.makeTitle(&amp;#039;File&amp;#039;, image)&lt;br /&gt;
	local file = title.file&lt;br /&gt;
&lt;br /&gt;
	if not title.exists or not file or not file.exists then&lt;br /&gt;
		table.insert(categories, &amp;#039;Pages with non-existent  image in template&amp;#039;)&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if file.height &amp;lt; MAX_HEIGHT and file.width &amp;lt; MIN_WIDTH then&lt;br /&gt;
		table.insert(categories, &amp;#039;Pages with non-sufficient width image in infobox&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Performs checks on the image argument&lt;br /&gt;
--- @param image string - The image argument of the template&lt;br /&gt;
--- @return nil&lt;br /&gt;
function p.checkImage(image)&lt;br /&gt;
	local isImageParameterValid = checkImageExtension(image)&lt;br /&gt;
	-- Only continue if the parameter is valid&lt;br /&gt;
	if isImageParameterValid then&lt;br /&gt;
		checkImageMetadata(image)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Retrieves template arguments from the frame invoke function and pass to the main function&lt;br /&gt;
function p.paramvalidate(frame)&lt;br /&gt;
	mArguments = require(&amp;#039;Module:Arguments&amp;#039;)&lt;br /&gt;
	return p._paramvalidate(mArguments.getArgs(frame))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Validate template parameters and return the wikitext&lt;br /&gt;
--- @param args table - Template arguments to be validated&lt;br /&gt;
--- @return string|nil&lt;br /&gt;
function p._paramvalidate(args)&lt;br /&gt;
	checkType(&amp;#039;_paramvalidate&amp;#039;, 1, args, &amp;#039;table&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
	if args[&amp;#039;image&amp;#039;] and args[&amp;#039;image&amp;#039;] ~= &amp;#039;&amp;#039; then&lt;br /&gt;
		checkTypeForNamedArg(&amp;#039;_paramvalidate&amp;#039;, &amp;#039;image&amp;#039;, args.image, &amp;#039;string&amp;#039;, false)&lt;br /&gt;
		p.checkImage(args[&amp;#039;image&amp;#039;])&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Only add category if it is content pages&lt;br /&gt;
	if mw.title.getCurrentTitle().isContentPage then&lt;br /&gt;
		return tableToCategory()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Rataj</name></author>
	</entry>
</feed>