This module formats images for display in Template:In the news, which is in turn displayed on the Main Page. It implements Template:In the news/image - please see the template page for documentation.

-- This module implements [[Template:In the news/image]], which displays
-- the news image on the Main Page.

local mFileLink = require('Module:File link')

local p = {}

function p._main(args)
	if not args.image then
		return nil
	end
	if not args.title then
		error('no title specified', 2)
	end

	local imageTitle = mw.title.new(args.image, 6) -- NS_FILE
	if not imageTitle then
		error('invalid image title (check for bad characters): ' .. args.image, 2)
	elseif not imageTitle.file.exists then
		return string.format(
			'<span class="error">No file exists at [[:%s]]</span>',
			imageTitle.prefixedText
		)
	end

	local link
	if args.link then
		local linkTitle = mw.title.new(args.link, 6) -- NS_FILE
		if not linkTitle then
			error('invalid link (check for bad characters): ' .. args.link, 2)
		elseif linkTitle ~= imageTitle then
			if not linkTitle.file.exists then
				return string.format(
					'<span class="error">No file exists at [[:%s]]</span>',
					linkTitle.prefixedText
				)
			end
			link = linkTitle.prefixedText
		end
	end

	return string.format(
		'<div style="float:right;margin-left:0.5em;">\n%s</div>',
		mFileLink._main{
			file = imageTitle.text,
			link = link,
			size = args.size or '100x100px',
			border = args.border,
			caption = args.title,
			alt = args.alt or args.title
		}
	)
end

function p.main(frame)
	return p._main(require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:In the news/image'
	}))
end

return p