Module:In the news/image

From Γνωσιακή Βάση Υπηρεσιών και Διαδικασιών του Δημοσίου Τομέα
Revision as of 16:32, 11 June 2015 by Dkalo (talk | contribs) (Εισήχθη 1 αναθεώρηση)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Documentation for this module may be created at Module:In the news/image/doc

-- 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;" id="mp-itn-img">\n%s\n</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