Module:GetParameters: Difference between revisions

Content deleted Content added
p.defined(): fix
m Changed protection settings for "Module:GetParameters": Used on 4.8 million pages ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite))
 
(3 intermediate revisions by 3 users not shown)
Line 1:
--[[
 
This module is intended to provide access to basic string functions.
 
Most of the functions provided here can be invoked with named parameters,
unnamed parameters, or a mixture. If named parameters are used, Mediawiki will
automatically remove any leading or trailing whitespace from the parameter.
Depending on the intended use, it may be advantageous to either preserve or
remove such whitespace.
 
Global options
ignore_errors: If set to 'true' or 1, any error condition will result in
an empty string being returned rather than an error message.
error_category: If an error occurs, specifies the name of a category to
include with the error message. The default category is
[Category:Errors reported by Module String].
no_category: If set to 'true' or 1, no category will be added if an error
is generated.
Unit tests for this module are available at Module:String/tests.
]]
 
local p = {}
 
Line 71 ⟶ 47:
 
function p.defined(frame)
returnlocal arg = frame:getParent().args[mw.text.trim(frame.args[1])] ~= nil
--if arg == tostring(tonumber(arg)) then -- undesired result for '-0'
-- arg = tonumber(arg)
--end
--if mw.ustring.find(arg, '^%s*-?[1-9][0-9]*%s*$') ~= nil or arg == '0' then
-- arg = tonumber(arg)
--end
if mw.ustring.find(arg, '^-?[1-9][0-9]*$') ~= nil then
arg = tonumber(arg)
elseif arg == '0' then
arg = 0
end
return frame:getParent().args[arg] ~= nil
end