Changes
		
		
		
		
		
		
		Jump to navigation
		Jump to search
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
		
		
	
		
		
		
		
		
		
		
	
rename the image table to a fileLink table, seeing as this code is applicable to all file links
-- This module provides a library for formatting image file wikilinks.
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local image fileLink = {}
function imagefileLink.new(filename)	checkType('imagefileLink.new', 1, filename, 'string', true)
	local obj, data = {}, {}
	local checkSelf = libraryUtil.makeCheckSelfFunction(
		'imagefileLink',		'imagefileLink',
		obj,
		'image fileLink object'
	)
	-- Set the filename if we were passed it as an input to imagefileLink.new.
	if filename then
		data.theName = filename
	function data:name(s)
		checkSelf(self, 'imagefileLink:name')		checkType('imagefileLink:name', 1, s, 'string')
		data.theName = s
		return self
	function data:format(s, filename)
		checkSelf(self, 'imagefileLink:format')		checkType('imagefileLink:format', 1, s, 'string', true)		checkType('imagefileLink:format', 2, format, 'string', true)
		local validFormats = {
			thumb = true,
		else
			error(string.format(
				"bad argument #1 to 'imagefileLink:format' ('%s' is not a valid format)",
				s
			), 2)
	function data:width(px)
		checkSelf(self, 'imagefileLink:width')		checkType('imagefileLink:width', 1, px, 'number', true)
		if px and data.isUpright then
			sizeError('imagefileLink:width')
		end
		data.theWidth = px
	function data:height(px)
		checkSelf(self, 'imagefileLink:height')		checkType('imagefileLink:height', 1, px, 'number', true)
		if px and data.isUpright then
			sizeError('imagefileLink:height')
		end
		data.theHeight = px
	function data:upright(isUpright, factor)
		checkSelf(self, 'imagefileLink:upright')		checkType('imagefileLink:upright', 1, isUpright, 'boolean', true)		checkType('imagefileLink:upright', 2, factor, 'number', true)
		if isUpright and (data.theWidth or data.theHeight) then
			sizeError('imagefileLink:upright')
		end
		data.isUpright = isUpright
	function data:resetSize()
		checkSelf(self, 'imagefileLink:resetSize')
		for i, field in ipairs{'theWidth', 'theHeight', 'isUpright', 'uprightFactor'} do
			data[field] = nil
	function data:location(s)
		checkSelf(self, 'imagefileLink:location')		checkType('imagefileLink:location', 1, s, 'string', true)
		local validLocations = {
			right = true,
		else
			error(string.format(
				"bad argument #1 to 'imagefileLink:location' ('%s' is not a valid location)",
				s
			), 2)
	function data:alignment(s)
		checkSelf(self, 'imagefileLink:alignment')		checkType('imagefileLink:alignment', 1, s, 'string', true)
		local validAlignments = {
			baseline = true,
		else
			error(string.format(
				"bad argument #1 to 'imagefileLink:alignment' ('%s' is not a valid alignment)",
				s
			), 2)
	function data:border(hasBorder)
		checkSelf(self, 'imagefileLink:border')		checkType('imagefileLink:border', 1, hasBorder, 'boolean', true)
		data.hasBorder = hasBorder
		return self
	function data:link(s)
		checkSelf(self, 'imagefileLink:link')		checkType('imagefileLink:link', 1, s, 'string', true)
		data.theLink = s
		return self
	function data:alt(s)
		checkSelf(self, 'imagefileLink:alt')		checkType('imagefileLink:alt', 1, s, 'string', true)
		data.theAlt = s
		return self
	function data:page(num)
		checkSelf(self, 'imagefileLink:page')		checkType('imagefileLink:page', 1, num, 'number', true)
		data.thePage = s
		return self
	function data:class(s)
		checkSelf(self, 'imagefileLink:class')		checkType('imagefileLink:class', 1, s, 'string', true)
		data.theClass = s
		return self
	function data:lang(s)
		checkSelf(self, 'imagefileLink:lang')		checkType('imagefileLink:lang', 1, s, 'string', true)
		data.theLang = s
		return self
	function data:caption(s)
		checkSelf(self, 'imagefileLink:caption')		checkType('imagefileLink:caption', 1, s, 'string', true)
		data.theCaption = s
		return self
	function data:render()
		checkSelf(self, 'imagefileLink:render')
		local ret = {}
		-- Image name.Filename
		if not data.theName then
			error('imagefileLink:render: no image name filename was found')
		end
		ret[#ret + 1] = 'File:' .. data.theName
		-- Image formatFormat
		if data.theFormat and data.theFormatFilename then
			ret[#ret + 1] = data.theFormat .. '=' .. data.theFormatFilename
		readOnlyFields[field] = true
	end
	readOnlyFields.theName = nil -- This is set if a filename is given to imagefileLink.new, so remove it.
	local function restrictedFieldError(key, restriction)
		error(string.format(
			"image fileLink object field '%s' is %s",
			tostring(key),
			restriction
end
return imagefileLink