Anonymous
×
Create a new article
Write your page title here:
We currently have 15 articles on TwistedFates Database. Type your article name above or click on one of the titles below and start writing!



TwistedFates Database
15Articles

Module:Message box/configuration and Module:File link: Difference between pages

(Difference between pages)
wikip>MusikAnimal
m (1 revision imported)
 
m (1 revision imported)
 
Line 1: Line 1:
--------------------------------------------------------------------------------
-- This module provides a library for formatting file wikilinks.
--                          Message box configuration                        --
--                                                                            --
-- This module contains configuration data for [[Module:Message box]].       --
--------------------------------------------------------------------------------


return {
local yesno = require('Module:Yesno')
ambox = {
local checkType = require('libraryUtil').checkType
types = {
 
speedy = {
local p = {}
class = 'ambox-speedy',
 
image = 'Ambox warning pn.svg'
function p._main(args)
},
checkType('_main', 1, args, 'table')
delete = {
 
class = 'ambox-delete',
-- This is basically libraryUtil.checkTypeForNamedArg, but we are rolling our
image = 'Ambox warning pn.svg'
-- own function to get the right error level.
},
local function checkArg(key, val, level)
content = {
if type(val) ~= 'string' then
class = 'ambox-content',
error(string.format(
image = 'Ambox important.svg'
"type error in '%s' parameter of '_main' (expected string, got %s)",
},
key, type(val)
style = {
), level)
class = 'ambox-style',
end
image = 'Edit-clear.svg'
end
},
 
move = {
local ret = {}
class = 'ambox-move',
 
image = 'Merge-split-transwiki default.svg'
-- Adds a positional parameter to the buffer.
},
local function addPositional(key)
protection = {
local val = args[key]
class = 'ambox-protection',
if not val then
image = 'Semi-protection-shackle-keyhole.svg'
return nil
},
end
notice = {
checkArg(key, val, 4)
class = 'ambox-notice',
ret[#ret + 1] = val
image = 'Information icon4.svg'
end
}
 
},
-- Adds a named parameter to the buffer. We assume that the parameter name
default                    = 'notice',
-- is the same as the argument key.
allowBlankParams            = {'talk', 'sect', 'date', 'issue', 'fix', 'subst', 'hidden'},
local function addNamed(key)
allowSmall                  = true,
local val = args[key]
smallParam                  = 'left',
if not val then
smallClass                  = 'mbox-small-left',
return nil
substCheck                  = true,
end
classes                    = {'metadata', 'ambox'},
checkArg(key, val, 4)
imageEmptyCell              = true,
ret[#ret + 1] = key .. '=' .. val
imageCheckBlank            = true,
end
imageSmallSize              = '20x20px',
 
imageCellDiv                = true,
-- Filename
useCollapsibleTextFields    = true,
checkArg('file', args.file, 3)
imageRightNone              = true,
ret[#ret + 1] = 'File:' .. args.file
sectionDefault              = 'article',
 
allowMainspaceCategories    = true,
-- Format
templateCategory            = 'Article message templates',
if args.format then
        templateCategoryRequireName = true,
checkArg('format', args.format)
templateErrorCategory      = 'Article message templates with missing parameters',
if args.formatfile then
templateErrorParamsToCheck  = {'issue', 'fix', 'subst'},
checkArg('formatfile', args.formatfile)
removalNotice              = '[[Help:Maintenance template removal|Learn how and when to remove this template message]]'
ret[#ret + 1] = args.format .. '=' .. args.formatfile
},
else
ret[#ret + 1] = args.format
cmbox = {
end
types = {
end
speedy = {
 
class = 'cmbox-speedy',
-- Border
image = 'Ambox warning pn.svg'
if yesno(args.border) then
},
ret[#ret + 1] = 'border'
delete = {
end
class = 'cmbox-delete',
 
image = 'Ambox warning pn.svg'
addPositional('location')
},
addPositional('alignment')
content = {
addPositional('size')
class = 'cmbox-content',
addNamed('upright')
image = 'Ambox important.svg'
addNamed('link')
},
addNamed('alt')
style = {
addNamed('page')
class = 'cmbox-style',
addNamed('class')
image = 'Edit-clear.svg'
addNamed('lang')
},
addNamed('start')
move = {
addNamed('end')
class = 'cmbox-move',
addNamed('thumbtime')
image = 'Merge-split-transwiki default.svg'
addPositional('caption')
},
 
protection = {
return string.format('[[%s]]', table.concat(ret, '|'))
class = 'cmbox-protection',
end
image = 'Semi-protection-shackle-keyhole.svg'
 
},
function p.main(frame)
notice = {
local origArgs = require('Module:Arguments').getArgs(frame, {
class = 'cmbox-notice',
wrappers = 'Template:File link'
image = 'Information icon4.svg'
})
}
if not origArgs.file then
},
error("'file' parameter missing from [[Template:File link]]", 0)
default              = 'notice',
end
showInvalidTypeError = true,
 
classes              = {'cmbox'},
-- Copy the arguments that were passed to a new table to avoid looking up
imageEmptyCell      = true
-- every possible parameter in the frame object.
},
local args = {}
for k, v in pairs(origArgs) do
fmbox = {
-- Make _BLANK a special argument to add a blank parameter. For use in
types = {
-- conditional templates etc. it is useful for blank arguments to be
warning = {
-- ignored, but we still need a way to specify them so that we can do
class = 'fmbox-warning',
-- things like [[File:Example.png|link=]].
image = 'Ambox warning pn.svg'
if v == '_BLANK' then
},
v = ''
editnotice = {
end
class = 'fmbox-editnotice',
args[k] = v
image = 'Information icon4.svg'
end
},
return p._main(args)
system = {
end
class = 'fmbox-system',
 
image = 'Information icon4.svg'
return p
}
},
default              = 'system',
showInvalidTypeError = true,
classes              = {'fmbox'},
imageEmptyCell      = false,
imageRightNone      = false
},
imbox = {
types = {
speedy = {
class = 'imbox-speedy',
image = 'Ambox warning pn.svg'
},
delete = {
class = 'imbox-delete',
image = 'Ambox warning pn.svg'
},
content = {
class = 'imbox-content',
image = 'Ambox important.svg'
},
style = {
class = 'imbox-style',
image = 'Edit-clear.svg'
},
move = {
class = 'imbox-move',
image = 'Merge-split-transwiki default.svg'
},
protection = {
class = 'imbox-protection',
image = 'Semi-protection-shackle-keyhole.svg'
},
license = {
class = 'imbox-license licensetpl',
image = 'Imbox license.png' -- @todo We need an SVG version of this
},
featured = {
class = 'imbox-featured',
image = 'Cscr-featured.svg'
},
notice = {
class = 'imbox-notice',
image = 'Information icon4.svg'
}
},
default              = 'notice',
showInvalidTypeError = true,
classes              = {'imbox'},
imageEmptyCell      = true,
below                = true,
templateCategory    = 'File message boxes'
},
ombox = {
types = {
speedy = {
class = 'ombox-speedy',
image = 'Ambox warning pn.svg'
},
delete = {
class = 'ombox-delete',
image = 'Ambox warning pn.svg'
},
content = {
class = 'ombox-content',
image = 'Ambox important.svg'
},
style = {
class = 'ombox-style',
image = 'Edit-clear.svg'
},
move = {
class = 'ombox-move',
image = 'Merge-split-transwiki default.svg'
},
protection = {
class = 'ombox-protection',
image = 'Semi-protection-shackle-keyhole.svg'
},
notice = {
class = 'ombox-notice',
image = 'Information icon4.svg'
}
},
default              = 'notice',
showInvalidTypeError = true,
classes              = {'ombox'},
allowSmall          = true,
imageEmptyCell      = true,
imageRightNone      = true
},
tmbox = {
types = {
speedy = {
class = 'tmbox-speedy',
image = 'Ambox warning pn.svg'
},
delete = {
class = 'tmbox-delete',
image = 'Ambox warning pn.svg'
},
content = {
class = 'tmbox-content',
image = 'Ambox important.svg'
},
style = {
class = 'tmbox-style',
image = 'Edit-clear.svg'
},
move = {
class = 'tmbox-move',
image = 'Merge-split-transwiki default.svg'
},
protection = {
class = 'tmbox-protection',
image = 'Semi-protection-shackle-keyhole.svg'
},
notice = {
class = 'tmbox-notice',
image = 'Information icon4.svg'
}
},
default              = 'notice',
showInvalidTypeError = true,
classes              = {'tmbox'},
allowSmall          = true,
imageRightNone      = true,
imageEmptyCell      = true,
imageEmptyCellStyle  = true,
templateCategory    = 'Talk message boxes'
}
}

Latest revision as of 21:26, 21 May 2021

Documentation for this module may be created at Module:File link/doc

-- This module provides a library for formatting file wikilinks.

local yesno = require('Module:Yesno')
local checkType = require('libraryUtil').checkType

local p = {}

function p._main(args)
	checkType('_main', 1, args, 'table')

	-- This is basically libraryUtil.checkTypeForNamedArg, but we are rolling our
	-- own function to get the right error level.
	local function checkArg(key, val, level)
		if type(val) ~= 'string' then
			error(string.format(
				"type error in '%s' parameter of '_main' (expected string, got %s)",
				key, type(val)
			), level)
		end
	end

	local ret = {}

	-- Adds a positional parameter to the buffer.
	local function addPositional(key)
		local val = args[key]
		if not val then
			return nil
		end
		checkArg(key, val, 4)
		ret[#ret + 1] = val
	end

	-- Adds a named parameter to the buffer. We assume that the parameter name
	-- is the same as the argument key.
	local function addNamed(key)
		local val = args[key]
		if not val then
			return nil
		end
		checkArg(key, val, 4)
		ret[#ret + 1] = key .. '=' .. val
	end

	-- Filename
	checkArg('file', args.file, 3)
	ret[#ret + 1] = 'File:' .. args.file

	-- Format
	if args.format then
		checkArg('format', args.format)
		if args.formatfile then
			checkArg('formatfile', args.formatfile)
			ret[#ret + 1] = args.format .. '=' .. args.formatfile
		else
			ret[#ret + 1] = args.format
		end
	end

	-- Border
	if yesno(args.border) then
		ret[#ret + 1] = 'border'
	end

	addPositional('location')
	addPositional('alignment')
	addPositional('size')
	addNamed('upright')
	addNamed('link')
	addNamed('alt')
	addNamed('page')
	addNamed('class')
	addNamed('lang')
	addNamed('start')
	addNamed('end')
	addNamed('thumbtime')
	addPositional('caption')

	return string.format('[[%s]]', table.concat(ret, '|'))
end

function p.main(frame)
	local origArgs = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:File link'
	})
	if not origArgs.file then
		error("'file' parameter missing from [[Template:File link]]", 0)
	end

	-- Copy the arguments that were passed to a new table to avoid looking up
	-- every possible parameter in the frame object.
	local args = {}
	for k, v in pairs(origArgs) do
		-- Make _BLANK a special argument to add a blank parameter. For use in
		-- conditional templates etc. it is useful for blank arguments to be
		-- ignored, but we still need a way to specify them so that we can do
		-- things like [[File:Example.png|link=]].
		if v == '_BLANK' then
			v = ''
		end
		args[k] = v
	end
	return p._main(args)
end

return p