Module:Clean image

From Old School RuneScape Wiki
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Clean image/doc. [edit] [history] [purge]
Module:Clean image's function main is invoked by Template:Clean image.
Module:Clean image requires Module:Paramtest.
Module:Clean image is required by Module:Sandbox/User:Faison/Materials.
Module:Clean image is required by Module:Sandbox/User:Faison/Recipe.
Module:Clean image is required by Module:Sandbox/User:Jakesterwars/Recipe.
Module:Clean image is required by Module:Sandbox/User:Mejrs/Infobox NPC.
Module:Clean image is required by Module:Sandbox/User:Towelcat/Recipe.

Cleans an input image to prevent double linking.

This module is a helper module to be used by other modules; it may not be designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information.

Clean imageclean(args)stringInput args is a table with fields:
  • file - the full wikitext to be cleaned. All processing is skipped if file is empty or is the string no.
  • width - width to resize the file to; no default
  • height - height to resize the file to, can be combined with width; no default
  • link - what page to link the file to; no default (file will link to file page), 'no' to link to nothing

local hc = require('Module:Paramtest').has_content
local p = {}
p.main = function(frame)
	local args = frame:getParent().args
	local clean = {
		file = args.file or args[1],
		width = args.width or args[2],
		height = args.height or args[3],
		link =
	return p.clean(clean)

p.clean = function(args)
	local file = args.file
	if not hc(file) or (file and (file:lower() == 'no' or file == '')) then
		return ''
	local height, width = '',''
	if hc(args.height) then
		height = 'x'..args.height
	if hc(args.width) then
		width = args.width
	local link = ''
	if hc( then
		if == 'no' then
			link = '|link='
			link = '|link='
	local size = ''
	if width ~= '' or height ~= '' then
		size = string.format('|%s%spx', width, height)
	file = file:gsub('%[',''):gsub('%]',''):gsub('[Ff]ile:',''):gsub('{{!}}','|')

	-- enforce max height and width
	file = mw.text.split(file, '|')

	file = string.format('%s%s%s',file[1], size, link)
	return '[[File:'..file..'|frameless]]'

return p