This module is rated asbeta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected.
This module issubject to page protection. It is ahighly visible module in use by a very large number of pages, or issubstituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it isprotected from editing.
Usage
getParameters
Takes 2 required arguments,frame_args andarg_list. Parses a frame's arguments, returning either the provided named arguments inarg_list if found or the positional parameters instead if not. This is designed to work around the stripping of values that takes place for defined parameters which could be important.
As an example, the callsgetParameters({"a","b","c"},{"x","y"}) andgetParameters({x="a",y="b",z="c"},{"x","y"}) would both give back{x="a",y="b"}.
getBoolean
Takes 1 required argumentboolean_str. Turns the input into a true/false boolean value based on the input. Will error if given anything other than a string or boolean value.
defined
To be invoked from inside a template instead of a module. Determines if a certain parameter is defined in the parent frame's arguments.
localp={}--[[Helper function that populates the argument list given that user may need to use a mix ofnamed and unnamed parameters. This is relevant because named parameters are notidentical to unnamed parameters due to string trimming, and when dealing with stringswe sometimes want to either preserve or remove that whitespace depending on the application.]]functionp.getParameters(frame_args,arg_list)localnew_args={};localindex=1;localvalue;fori,arginipairs(arg_list)dovalue=frame_args[arg]ifvalue==nilthenvalue=frame_args[index];index=index+1;endnew_args[arg]=value;endreturnnew_args;end--[[Helper Function to interpret boolean strings]]functionp.getBoolean(boolean_str)localboolean_value;iftype(boolean_str)=='string'thenboolean_str=boolean_str:lower();ifboolean_str=='false'orboolean_str=='no'orboolean_str=='0'orboolean_str==''thenboolean_value=false;elseboolean_value=true;endelseiftype(boolean_str)=='boolean'thenboolean_value=boolean_str;elseerror('No boolean value found');endreturnboolean_valueendfunctionp.defined(frame)localarg=mw.text.trim(frame.args[1])--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)--endifmw.ustring.find(arg,'^-?[1-9][0-9]*$')~=nilthenarg=tonumber(arg)elseifarg=='0'thenarg=0endreturnframe:getParent().args[arg]~=nilendreturnp