Template talk:MultiReplace
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. |
Template-protected edit request on 12 April 2018[edit]
This edit request has been answered. Set the |answered= or |ans= 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)
- Done by Ahecht {{3x|p}}ery (talk) 20:59, 12 April 2018 (UTC)
Superfluous input sanitization[edit]
@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)
- The intent was to allow for a template to invoke the module with the form
{{#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 (TALK
PAGE) 15:15, 25 April 2018 (UTC) - Forgot to ping Petr Matas. --Ahecht (TALK
PAGE) 15:16, 25 April 2018 (UTC)- Thank you for your explanation. Distinguishing between blank and missing input will not work here, because the assignment
args[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. - What I dislike about your solution, is that the behavior is different when the input happens to be empty. Consider someone using in their template
{{#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. - A cleaner way to distinguish between empty and missing template input: Enable a module to be invoked like this:
{{#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)- @Petr Matas: That's fine. I'll go ahead and remove it. --Ahecht (TALK
PAGE) 18:41, 25 April 2018 (UTC)- I don't get why any of these changes were necessary, as opposed to keeping the system "everyone invokes the module through {{MultiReplace}}" {{3x|p}}ery (talk) 23:51, 28 April 2018 (UTC)
- An important improvement is the provision for a simple call
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)
- An important improvement is the provision for a simple call
- I don't get why any of these changes were necessary, as opposed to keeping the system "everyone invokes the module through {{MultiReplace}}" {{3x|p}}ery (talk) 23:51, 28 April 2018 (UTC)
- @Petr Matas: That's fine. I'll go ahead and remove it. --Ahecht (TALK
- Thank you for your explanation. Distinguishing between blank and missing input will not work here, because the assignment
Template-protected edit request on 14 November 2022[edit]
This edit request to Module:MultiReplace has been answered. Set the |answered= or |ans= 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)
- Requesting an additional change. Currently, if the pattern contains some HTML code, and an error message is displayed, the HTML code is interpreted, whereas it shouldn't be.
- For example,
{{MultiReplace|1=haystack|2=<span style="color:green">foobar</span>}}
- Currently outputs: MultiReplace: Unpaired argument:
2 = foobar
- But it should be: MultiReplace: Unpaired argument:
2 = <span style="color:green">foobar</span>
- Currently outputs: MultiReplace: Unpaired argument:
- Another example, wiki markup is interpreted as well :
{{MultiReplace|1=haystack|2=''foobar''}}
- Currently outputs: MultiReplace: Unpaired argument:
2 = foobar
- But it should be: MultiReplace: Unpaired argument:
2 = ''foobar''
- Currently outputs: MultiReplace: Unpaired argument:
- To fix this issue, a
mw.text.nowiki()
should be added, like I did here. Od1n (talk) 01:14, 14 November 2022 (UTC)- Done both * Pppery * it has begun... 20:58, 15 November 2022 (UTC)