Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Module:GetParameters

Permanently protected module
From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
WarningThis Lua module is used onapproximately 4,970,000 pages, or roughly 8% of all pages.
To avoid major disruption and server load, any changes should be tested in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on thetalk page before implementing them.
BetaThis 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.
ProtectedThis 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.

See also

The abovedocumentation istranscluded fromModule:GetParameters/doc.(edit |history)
Editors can experiment in this module's sandbox(create |mirror) and testcases(create) pages.
Subpages of this module.

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
Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:GetParameters&oldid=1259572050"
Categories:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp