ページ「モジュール:Arguments」と「モジュール:Message box/configuration」の間の差分

提供:林 康紀研究室
(ページ間の差分)
ナビゲーションに移動 検索に移動
(1版 をインポートしました)
 
yhlabj>ネイ
(en:Module:Message box/configuration oldid=1097616239 より更新)
 
1行目: 1行目:
-- This module provides easy processing of arguments passed to Scribunto from
--------------------------------------------------------------------------------
-- #invoke. It is intended for use by other Lua modules, and should not be
--                          Message box configuration                        --
-- called from #invoke directly.
--                                                                            --
-- This module contains configuration data for [[Module:Message box]].        --
--------------------------------------------------------------------------------


local libraryUtil = require('libraryUtil')
return {
local checkType = libraryUtil.checkType
ambox = {
 
types = {
local arguments = {}
speedy = {
 
class = 'ambox-speedy',
-- Generate four different tidyVal functions, so that we don't have to check the
image = 'Ambox warning pn.svg'
-- options every time we call it.
},
 
delete = {
local function tidyValDefault(key, val)
class = 'ambox-delete',
if type(val) == 'string' then
image = 'Ambox warning pn.svg'
val = val:match('^%s*(.-)%s*$')
},
if val == '' then
content = {
return nil
class = 'ambox-content',
else
image = 'Ambox important.svg'
return val
},
end
style = {
else
class = 'ambox-style',
return val
image = 'Edit-clear.svg'
end
},
end
move = {
 
class = 'ambox-move',
local function tidyValTrimOnly(key, val)
image = 'Merge-split-transwiki default.svg'
if type(val) == 'string' then
},
return val:match('^%s*(.-)%s*$')
protection = {
else
class = 'ambox-protection',
return val
image = 'Padlock-silver-medium.svg'
end
},
end
notice = {
 
class = 'ambox-notice',
local function tidyValRemoveBlanksOnly(key, val)
image = 'Information icon4.svg'
if type(val) == 'string' then
}
if val:find('%S') then
},
return val
default                    = 'notice',
else
allowBlankParams            = {'talk', 'sect', 'date', 'issue', 'fix', 'subst', 'hidden'},
return nil
allowSmall                  = true,
end
smallParam                  = 'left',
else
smallClass                  = 'mbox-small-left',
return val
substCheck                  = true,
end
classes                    = {--[['metadata',]] 'ambox'},
end
imageEmptyCell              = true,
 
imageCheckBlank            = true,
local function tidyValNoChange(key, val)
imageSmallSize              = '20x20px',
return val
imageCellDiv                = true,
end
useCollapsibleTextFields    = true,
 
imageRightNone              = true,
local function matchesTitle(given, title)
sectionDefault              = '記事',
local tp = type( given )
allowMainspaceCategories    = true,
return (tp == 'string' or tp == 'number') and mw.title.new( given ).prefixedText == title
templateCategory            = '記事メッセージボックス',
end
        templateCategoryRequireName = true,
 
templateErrorCategory      = 'パラメータ指定の無い記事メッセージボックス',
local translate_mt = { __index = function(t, k) return k end }
templateErrorParamsToCheck  = {'issue', 'fix', 'subst'},
 
templatestyles              = 'Module:Message box/ambox.css'
function arguments.getArgs(frame, options)
},
checkType('getArgs', 1, frame, 'table', true)
checkType('getArgs', 2, options, 'table', true)
cmbox = {
frame = frame or {}
types = {
options = options or {}
speedy = {
 
class = 'cmbox-speedy',
--[[
image = 'Ambox warning pn.svg'
-- Set up argument translation.
},
--]]
delete = {
options.translate = options.translate or {}
class = 'cmbox-delete',
if getmetatable(options.translate) == nil then
image = 'Ambox warning pn.svg'
setmetatable(options.translate, translate_mt)
},
end
content = {
if options.backtranslate == nil then
class = 'cmbox-content',
options.backtranslate = {}
image = 'Ambox important.svg'
for k,v in pairs(options.translate) do
},
options.backtranslate[v] = k
style = {
end
class = 'cmbox-style',
end
image = 'Edit-clear.svg'
if options.backtranslate and getmetatable(options.backtranslate) == nil then
},
setmetatable(options.backtranslate, {
move = {
__index = function(t, k)
class = 'cmbox-move',
if options.translate[k] ~= k then
image = 'Merge-split-transwiki default.svg'
return nil
},
else
protection = {
return k
class = 'cmbox-protection',
end
image = 'Padlock-silver-medium.svg'
end
},
})
notice = {
end
class = 'cmbox-notice',
 
image = 'Information icon4.svg'
--[[
}
-- Get the argument tables. If we were passed a valid frame object, get the
},
-- frame arguments (fargs) and the parent frame arguments (pargs), depending
default              = 'notice',
-- on the options set and on the parent frame's availability. If we weren't
showInvalidTypeError = true,
-- passed a valid frame object, we are being called from another Lua module
classes              = {'cmbox'},
-- or from the debug console, so assume that we were passed a table of args
imageEmptyCell      = true,
-- directly, and assign it to a new variable (luaArgs).
templatestyles      = 'Module:Message box/cmbox.css'
--]]
},
local fargs, pargs, luaArgs
if type(frame.args) == 'table' and type(frame.getParent) == 'function' then
fmbox = {
if options.wrappers then
types = {
--[[
warning = {
-- The wrappers option makes Module:Arguments look up arguments in
class = 'fmbox-warning',
-- either the frame argument table or the parent argument table, but
image = 'Ambox warning pn.svg'
-- not both. This means that users can use either the #invoke syntax
},
-- or a wrapper template without the loss of performance associated
editnotice = {
-- with looking arguments up in both the frame and the parent frame.
class = 'fmbox-editnotice',
-- Module:Arguments will look up arguments in the parent frame
image = 'Information icon4.svg'
-- if it finds the parent frame's title in options.wrapper;
},
-- otherwise it will look up arguments in the frame object passed
system = {
-- to getArgs.
class = 'fmbox-system',
--]]
image = 'Information icon4.svg'
local parent = frame:getParent()
}
if not parent then
},
fargs = frame.args
default              = 'system',
else
showInvalidTypeError = true,
local title = parent:getTitle():gsub('/sandbox$', '')
classes              = {'fmbox'},
local found = false
imageEmptyCell      = false,
if matchesTitle(options.wrappers, title) then
imageRightNone      = false,
found = true
templatestyles      = 'Module:Message box/fmbox.css'
elseif type(options.wrappers) == 'table' then
},
for _,v in pairs(options.wrappers) do
if matchesTitle(v, title) then
imbox = {
found = true
types = {
break
speedy = {
end
class = 'imbox-speedy',
end
image = 'Ambox warning pn.svg'
end
},
 
delete = {
-- We test for false specifically here so that nil (the default) acts like true.
class = 'imbox-delete',
if found or options.frameOnly == false then
image = 'Ambox warning pn.svg'
pargs = parent.args
},
end
content = {
if not found or options.parentOnly == false then
class = 'imbox-content',
fargs = frame.args
image = 'Ambox important.svg'
end
},
end
style = {
else
class = 'imbox-style',
-- options.wrapper isn't set, so check the other options.
image = 'Edit-clear.svg'
if not options.parentOnly then
},
fargs = frame.args
move = {
end
class = 'imbox-move',
if not options.frameOnly then
image = 'Merge-split-transwiki default.svg'
local parent = frame:getParent()
},
pargs = parent and parent.args or nil
protection = {
end
class = 'imbox-protection',
end
image = 'Padlock-silver-medium.svg'
if options.parentFirst then
},
fargs, pargs = pargs, fargs
license = {
end
class = 'imbox-license licensetpl',
else
image = 'Imbox license.png' -- @todo We need an SVG version of this
luaArgs = frame
},
end
featured = {
 
class = 'imbox-featured',
-- Set the order of precedence of the argument tables. If the variables are
image = 'Cscr-featured.svg'
-- nil, nothing will be added to the table, which is how we avoid clashes
},
-- between the frame/parent args and the Lua args.
notice = {
local argTables = {fargs}
class = 'imbox-notice',
argTables[#argTables + 1] = pargs
image = 'Information icon4.svg'
argTables[#argTables + 1] = luaArgs
}
 
},
--[[
default              = 'notice',
-- Generate the tidyVal function. If it has been specified by the user, we
showInvalidTypeError = true,
-- use that; if not, we choose one of four functions depending on the
classes              = {'imbox'},
-- options chosen. This is so that we don't have to call the options table
imageEmptyCell      = true,
-- every time the function is called.
below                = true,
--]]
templateCategory    = 'ファイルメッセージボックス',
local tidyVal = options.valueFunc
templatestyles      = 'Module:Message box/imbox.css'
if tidyVal then
},
if type(tidyVal) ~= 'function' then
error(
ombox = {
"bad value assigned to option 'valueFunc'"
types = {
.. '(function expected, got '
speedy = {
.. type(tidyVal)
class = 'ombox-speedy',
.. ')',
image = 'Ambox warning pn.svg'
2
},
)
delete = {
end
class = 'ombox-delete',
elseif options.trim ~= false then
image = 'Ambox warning pn.svg'
if options.removeBlanks ~= false then
},
tidyVal = tidyValDefault
content = {
else
class = 'ombox-content',
tidyVal = tidyValTrimOnly
image = 'Ambox important.svg'
end
},
else
style = {
if options.removeBlanks ~= false then
class = 'ombox-style',
tidyVal = tidyValRemoveBlanksOnly
image = 'Edit-clear.svg'
else
},
tidyVal = tidyValNoChange
move = {
end
class = 'ombox-move',
end
image = 'Merge-split-transwiki default.svg'
 
},
--[[
protection = {
-- Set up the args, metaArgs and nilArgs tables. args will be the one
class = 'ombox-protection',
-- accessed from functions, and metaArgs will hold the actual arguments. Nil
image = 'Padlock-silver-medium.svg'
-- arguments are memoized in nilArgs, and the metatable connects all of them
},
-- together.
notice = {
--]]
class = 'ombox-notice',
local args, metaArgs, nilArgs, metatable = {}, {}, {}, {}
image = 'Information icon4.svg'
setmetatable(args, metatable)
}
 
},
local function mergeArgs(tables)
default              = 'notice',
--[[
showInvalidTypeError = true,
-- Accepts multiple tables as input and merges their keys and values
classes              = {'ombox'},
-- into one table. If a value is already present it is not overwritten;
allowSmall          = true,
-- tables listed earlier have precedence. We are also memoizing nil
imageEmptyCell      = true,
-- values, which can be overwritten if they are 's' (soft).
imageRightNone      = true,
--]]
templatestyles      = 'Module:Message box/ombox.css'
for _, t in ipairs(tables) do
},
for key, val in pairs(t) do
if metaArgs[key] == nil and nilArgs[key] ~= 'h' then
tmbox = {
local tidiedVal = tidyVal(key, val)
types = {
if tidiedVal == nil then
speedy = {
nilArgs[key] = 's'
class = 'tmbox-speedy',
else
image = 'Ambox warning pn.svg'
metaArgs[key] = tidiedVal
},
end
delete = {
end
class = 'tmbox-delete',
end
image = 'Ambox warning pn.svg'
end
},
end
content = {
 
class = 'tmbox-content',
--[[
image = 'Ambox important.svg'
-- Define metatable behaviour. Arguments are memoized in the metaArgs table,
},
-- and are only fetched from the argument tables once. Fetching arguments
style = {
-- from the argument tables is the most resource-intensive step in this
class = 'tmbox-style',
-- module, so we try and avoid it where possible. For this reason, nil
image = 'Edit-clear.svg'
-- arguments are also memoized, in the nilArgs table. Also, we keep a record
},
-- in the metatable of when pairs and ipairs have been called, so we do not
move = {
-- run pairs and ipairs on the argument tables more than once. We also do
class = 'tmbox-move',
-- not run ipairs on fargs and pargs if pairs has already been run, as all
image = 'Merge-split-transwiki default.svg'
-- the arguments will already have been copied over.
},
--]]
protection = {
 
class = 'tmbox-protection',
metatable.__index = function (t, key)
image = 'Padlock-silver-medium.svg'
--[[
},
-- Fetches an argument when the args table is indexed. First we check
notice = {
-- to see if the value is memoized, and if not we try and fetch it from
class = 'tmbox-notice',
-- the argument tables. When we check memoization, we need to check
image = 'Information icon4.svg'
-- metaArgs before nilArgs, as both can be non-nil at the same time.
}
-- If the argument is not present in metaArgs, we also check whether
},
-- pairs has been run yet. If pairs has already been run, we return nil.
default              = 'notice',
-- This is because all the arguments will have already been copied into
showInvalidTypeError = true,
-- metaArgs by the mergeArgs function, meaning that any other arguments
classes              = {'tmbox'},
-- must be nil.
allowSmall          = true,
--]]
imageRightNone      = true,
if type(key) == 'string' then
imageEmptyCell      = true,
key = options.translate[key]
templateCategory    = 'ノートページメッセージボックス',
end
templatestyles      = 'Module:Message box/tmbox.css'
local val = metaArgs[key]
}
if val ~= nil then
}
return val
elseif metatable.donePairs or nilArgs[key] then
return nil
end
for _, argTable in ipairs(argTables) do
local argTableVal = tidyVal(key, argTable[key])
if argTableVal ~= nil then
metaArgs[key] = argTableVal
return argTableVal
end
end
nilArgs[key] = 'h'
return nil
end
 
metatable.__newindex = function (t, key, val)
-- This function is called when a module tries to add a new value to the
-- args table, or tries to change an existing value.
if type(key) == 'string' then
key = options.translate[key]
end
if options.readOnly then
error(
'could not write to argument table key "'
.. tostring(key)
.. '"; the table is read-only',
2
)
elseif options.noOverwrite and args[key] ~= nil then
error(
'could not write to argument table key "'
.. tostring(key)
.. '"; overwriting existing arguments is not permitted',
2
)
elseif val == nil then
--[[
-- If the argument is to be overwritten with nil, we need to erase
-- the value in metaArgs, so that __index, __pairs and __ipairs do
-- not use a previous existing value, if present; and we also need
-- to memoize the nil in nilArgs, so that the value isn't looked
-- up in the argument tables if it is accessed again.
--]]
metaArgs[key] = nil
nilArgs[key] = 'h'
else
metaArgs[key] = val
end
end
 
local function translatenext(invariant)
local k, v = next(invariant.t, invariant.k)
invariant.k = k
if k == nil then
return nil
elseif type(k) ~= 'string' or not options.backtranslate then
return k, v
else
local backtranslate = options.backtranslate[k]
if backtranslate == nil then
-- Skip this one. This is a tail call, so this won't cause stack overflow
return translatenext(invariant)
else
return backtranslate, v
end
end
end
 
metatable.__pairs = function ()
-- Called when pairs is run on the args table.
if not metatable.donePairs then
mergeArgs(argTables)
metatable.donePairs = true
end
return translatenext, { t = metaArgs }
end
 
local function inext(t, i)
-- This uses our __index metamethod
local v = t[i + 1]
if v ~= nil then
return i + 1, v
end
end
 
metatable.__ipairs = function (t)
-- Called when ipairs is run on the args table.
return inext, t, 0
end
 
return args
end
 
return arguments

2023年3月8日 (水) 00:54時点における版

このモジュールについての説明文ページを モジュール:Message box/configuration/doc に作成できます

--------------------------------------------------------------------------------
--                          Message box configuration                         --
--                                                                            --
-- This module contains configuration data for [[Module:Message box]].        --
--------------------------------------------------------------------------------

return {
	ambox = {
		types = {
			speedy = {
				class = 'ambox-speedy',
				image = 'Ambox warning pn.svg'
			},
			delete = {
				class = 'ambox-delete',
				image = 'Ambox warning pn.svg'
			},
			content = {
				class = 'ambox-content',
				image = 'Ambox important.svg'
			},
			style = {
				class = 'ambox-style',
				image = 'Edit-clear.svg'
			},
			move = {
				class = 'ambox-move',
				image = 'Merge-split-transwiki default.svg'
			},
			protection = {
				class = 'ambox-protection',
				image = 'Padlock-silver-medium.svg'
			},
			notice = {
				class = 'ambox-notice',
				image = 'Information icon4.svg'
			}
		},
		default                     = 'notice',
		allowBlankParams            = {'talk', 'sect', 'date', 'issue', 'fix', 'subst', 'hidden'},
		allowSmall                  = true,
		smallParam                  = 'left',
		smallClass                  = 'mbox-small-left',
		substCheck                  = true,
		classes                     = {--[['metadata',]] 'ambox'},
		imageEmptyCell              = true,
		imageCheckBlank             = true,
		imageSmallSize              = '20x20px',
		imageCellDiv                = true,
		useCollapsibleTextFields    = true,
		imageRightNone              = true,
		sectionDefault              = '記事',
		allowMainspaceCategories    = true,
		templateCategory            = '記事メッセージボックス',
	        templateCategoryRequireName = true,
		templateErrorCategory       = 'パラメータ指定の無い記事メッセージボックス',
		templateErrorParamsToCheck  = {'issue', 'fix', 'subst'},
		templatestyles              = 'Module:Message box/ambox.css'
	},
	
	cmbox = {
		types = {
			speedy = {
				class = 'cmbox-speedy',
				image = 'Ambox warning pn.svg'
			},
			delete = {
				class = 'cmbox-delete',
				image = 'Ambox warning pn.svg'
			},
			content = {
				class = 'cmbox-content',
				image = 'Ambox important.svg'
			},
			style = {
				class = 'cmbox-style',
				image = 'Edit-clear.svg'
			},
			move = {
				class = 'cmbox-move',
				image = 'Merge-split-transwiki default.svg'
			},
			protection = {
				class = 'cmbox-protection',
				image = 'Padlock-silver-medium.svg'
			},
			notice = {
				class = 'cmbox-notice',
				image = 'Information icon4.svg'
			}
		},
		default              = 'notice',
		showInvalidTypeError = true,
		classes              = {'cmbox'},
		imageEmptyCell       = true,
		templatestyles       = 'Module:Message box/cmbox.css'
	},
	
	fmbox = {
		types = {
			warning = {
				class = 'fmbox-warning',
				image = 'Ambox warning pn.svg'
			},
			editnotice = {
				class = 'fmbox-editnotice',
				image = 'Information icon4.svg'
			},
			system = {
				class = 'fmbox-system',
				image = 'Information icon4.svg'
			}
		},
		default              = 'system',
		showInvalidTypeError = true,
		classes              = {'fmbox'},
		imageEmptyCell       = false,
		imageRightNone       = false,
		templatestyles       = 'Module:Message box/fmbox.css'
	},
	
	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 = 'Padlock-silver-medium.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     = 'ファイルメッセージボックス',
		templatestyles       = 'Module:Message box/imbox.css'
	},
	
	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 = 'Padlock-silver-medium.svg'
			},
			notice = {
				class = 'ombox-notice',
				image = 'Information icon4.svg'
			}
		},
		default              = 'notice',
		showInvalidTypeError = true,
		classes              = {'ombox'},
		allowSmall           = true,
		imageEmptyCell       = true,
		imageRightNone       = true,
		templatestyles       = 'Module:Message box/ombox.css'
	},
	
	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 = 'Padlock-silver-medium.svg'
			},
			notice = {
				class = 'tmbox-notice',
				image = 'Information icon4.svg'
			}
		},
		default              = 'notice',
		showInvalidTypeError = true,
		classes              = {'tmbox'},
		allowSmall           = true,
		imageRightNone       = true,
		imageEmptyCell       = true,
		templateCategory     = 'ノートページメッセージボックス',
		templatestyles       = 'Module:Message box/tmbox.css'
	}
}