![]() | Template:MultiReplace is permanently protected from editing because it is a heavily used or highly visible template. Substantial changes should first be proposed and discussed here on this page. If the proposal is uncontroversial or has been discussed and is supported by consensus, editors may use {{edit template-protected}} to notify an administrator or template editor to make the requested edit. Usually, any contributor may edit the template's documentation to add usage notes or categories.
Any contributor may edit the template's sandbox. Functionality of the template can be checked using test cases. |
![]() | This edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
Please add {{{|safesubst:}}}
before the #invoke
to make the template subst cleanly. {{3x|p}}ery (talk) 19:02, 12 April 2018 (UTC)
@Ahecht: I see that you have added the following lines:
if args[1] == '' then
args[1] = frame:getParent().args[1]
end
I cannot understand the purpose of this check. Empty input is perfectly valid and nothing should be done about it. If this assignment takes place, then argument 1 is taken from the parent frame, but other arguments are taken from the current frame. This appears incorrect to me and I suggest that it should be removed. Petr Matas 13:10, 25 April 2018 (UTC)
{{#invoke:MultiReplace|main|findtext|replacetext}}
without having to do {{#invoke:MultiReplace|main|{{{1|}}}|findtext|replacetext}}
. If both the module invokation and the template call are blank, it will still be processed as a blank input. It's syntax I copied from other modules, where it's used because it allows the module to distinguish between blank (|1=
) and missing input in the template call, but if there isn't a need to do that here, it can be removed. --Ahecht (TALKargs[1] = nil
does not work as expected (args is not an ordinary table). Therefore the better readable invocation {{#invoke:MultiReplace|main|{{{1|}}}|findtext|replacetext}}
becomes equivalent to the shortened one.{{#invoke:MultiReplace|main|{{{2|}}}|findtext|replacetext}}
. Now if the template's parameter 2 is empty or missing, MultiReplace will use the template's parameter 1 instead, which is unexpected and incorrect.{{#invoke:MultiReplace|main|inputparam=1|findtext|replacetext}}
. Such invocation is self-explanatory and the module needs no hacks, which could cause unexpected behavior. Petr Matas 18:35, 25 April 2018 (UTC)
require('Module:MultiReplace').main{input, findtext, replacetext}
from lua, because calling templates from there is not so straightforward. The provision for a call using {{#invoke:MultiReplace|main|input|findtext|replacetext}}
was added just for completeness, because it was simple to do so. The rest really serves no purpose, because the input always has to be provided and therefore there is no point in distinguishing an empty one from a missing one. Consider it to be just a "what if..." speculation with no direct consequences. Petr Matas 09:33, 29 April 2018 (UTC)![]() | This edit request to Module:MultiReplace has been answered. Set the |answered= parameter to no to reactivate your request. |
There is a global variable that should be fixed, as I did here. Thanks in advance. Od1n (talk) 00:44, 14 November 2022 (UTC)
{{MultiReplace|1=haystack|2=<span style="color:green">foobar</span>}}
2 = foobar
2 = <span style="color:green">foobar</span>
{{MultiReplace|1=haystack|2=''foobar''}}
2 = foobar
2 = ''foobar''
mw.text.nowiki()
should be added, like I did here. Od1n (talk) 01:14, 14 November 2022 (UTC)
![]() | This edit request to Module:MultiReplace has been answered. Set the |answered= parameter to no to reactivate your request. |
Module:String, and subsequently all templates based on it, supports 'false'
/ 'no'
/ '0'
and conversely 'true'
/ 'yes'
/ '1'
values, case-insensitive (and unrecognized values are handled as "true"), for the "plain" parameter in particular. (note the module can be used only through template #require's, not from other modules)
However, this module Module:MultiReplace (used by {{MultiReplace}} and many other templates, see search) only supports 'yes'
, case-sensitive. For convenience and security, we should support more values, mainly 'true'
(which is very often used in template #invoke's of Module:String), and case-insensitive.
Note the module function can be called from other modules, though currently it seems to be called only from template #invoke's.
Below are two implementations, that support 'yes'
, 'true'
(string), '1'
(string), true
(boolean) and 1
(number):
local argPlain = args.plain
if type(argPlain) == 'string' then
argPlain = argPlain:lower()
end
local plain = (argPlain == 'yes' or argPlain == 'true' or argPlain == true or tonumber(argPlain) == 1)
local argPlain = tostring(args.plain):lower()
local plain = (argPlain == 'yes' or argPlain == 'true' or argPlain == '1')
Lua's string.lower() is very fast, thus I would prefer the 2nd implementation.
Module:Yesno could have been used, but for performance reasons, I prefer to avoid require()'ing it.
Od1n (talk) 06:45, 20 August 2024 (UTC)
true
or yes
(and true
is the common one), but then in {{MultiReplace}} only yes
works… (edit, case in point: 1241264158) Od1n (talk) 07:49, 20 August 2024 (UTC)
'true'
value, case-sensitive?local plain = args.plain == "yes" or args.plain == "true"
'true'
for the time being. This could always be expanded later.local plain = args.plain and require('Module:String')._getBoolean(args.plain) or false
for consistency with Module:String_getBoolean
method is intended as private, and I think it should be respected. Case in point, in my local sandboxes for fixing this issue in Module:String, my best solution so far involves modifying the _getBoolean
method (namely, adding it a second parameter to provide the default value).-- NO, see next message -- local plain = args.plain ~= nil and require('Module:String')._getBoolean(args.plain) or true
-- NO, see next message -- local plain = args.plain ~= nil and require('Module:Yesno')(args.plain, true) or true
require('Module:Yesno')(args.plain, true)
gives "false", then args.plain ~= nil and require('Module:Yesno')(args.plain, true) or true
gives "false" instead of the expected "true"…local plain
if args.plain ~= nil then
plain = require('Module:Yesno')(args.plain, true)
else
plain = true
end
args.plain ~= nil
because there's no need to distinguish between it being missing ("nil") or false since we're emulating Module:String which passes new_args['plain'] or false
to _getBoolean
. And I'm not buying that the underscore indicates a private function -- if it were private it would use local function _getBoolean( boolean_str )
. The underscore is commonly used on Wikipedia to indicate functions that should only be called from Lua and not invoked from wikitext (see mw:Manual:Coding conventions/Lua#Naming conventions). --Ahecht (TALK_getParameters()
, _error()
, _escapePattern()
; at the very least, the first two are definitely not meant to be used anywhere else. Od1n (talk) 16:30, 17 September 2024 (UTC)