Module:Speedy
Appearance
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This module is used for speedy deletion notices and aims to increase flexibility greatly.
Features to be included include substitution detection and the ability to print out a full speedy deletion table.
Usage
{{#invoke:Speedy|function_name}}
Full Table of Reasons
See config page to edit
Script error: The function "makeTable" does not exist.
local getArgs = require("Module:Arguments").getArgs
local pageType = require("Module:Pagetype")
local p = {}
local config = mw.loadData('Module:Speedy/config')
----------------------------------------------------------------------------
-- message function from [[Module:Documentation]]
----------------------------------------------------------------------------
local function message(cfgKey, valArray, expectType)
--[[
-- Gets a message from the cfg table and formats it if appropriate.
-- The function raises an error if the value from the cfg table is not
-- of the type expectType. The default type for expectType is 'string'.
-- If the table valArray is present, strings such as $1, $2 etc. in the
-- message are substituted with values from the table keys [1], [2] etc.
-- For example, if the message "foo-message" had the value 'Foo $2 bar $1.',
-- message('foo-message', {'baz', 'qux'}) would return "Foo qux bar baz."
--]]
local msg = config.messages[cfgKey]
expectType = expectType or 'string'
if type(msg) ~= expectType then
error('message: type error in message cfg.' .. cfgKey .. ' (' .. expectType .. ' expected, got ' .. type(msg) .. ')', 2)
end
if not valArray then
return msg
end
local function getMessageVal(match)
match = tonumber(match)
return valArray[match] or error('message: no value found for key $' .. match .. ' in message cfg.' .. cfgKey, 4)
end
return ugsub(msg, '$([1-9][0-9]*)', getMessageVal)
end
----------------------------------------------------------------------------
-- Argument processing (from [[Module:Documentation]])
----------------------------------------------------------------------------
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame, {
valueFunc = function (key, value)
if type(value) == 'string' then
value = value:match('^%s*(.-)%s*$') -- Remove whitespace.
if key == 'heading' or value ~= '' then
return value
else
return nil
end
else
return value
end
end
})
return p[funcName](args)
end
end
p.main = makeInvokeFunc('_main')
----------------------------------------------------------------------------
-- Miscellaneous functions related to speedy deletion
----------------------------------------------------------------------------
--[[
-- Returns the deletion entry for a given reason
-- @param code the code to process
--]]
function getDeletionEntry(code)
return config.deletionCodes[code] or code
end
function processDeletionReasons(args)
local entries = {}
for k,v in ipairs(args) do
if type(k) == type(1) then
entries[k] = getDeletionEntry(code)
end
end
return codes
end
----------------------------------------------------------------------------
-- Entry point
----------------------------------------------------------------------------
function p._main(args)
-- get page
local deletionReasons = processDeletionReasons(args)
end
return p