Jump to content

Module:Speedy

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Awesome Aasim (talk | contribs) at 05:50, 21 November 2022 (start work on module that can be used for more advanced deletions, etc.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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