Template talk:Replace
![]() | Template:Replace 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 protected}} to notify an administrator 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:Str rep all" listed at Redirects for discussion
editA discussion is taking place to address the redirect Template:Str rep all. The discussion will occur at Wikipedia:Redirects for discussion/Log/2021 April 26#Template:Str rep all until a consensus is reached, and readers of this page are welcome to contribute to the discussion. User:GKFXtalk 07:16, 26 April 2021 (UTC)
Edit request 19 August 2024
editThis edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
There is currently a code mistake in Module:String.replace()
: if provided with plain = ''
(argument present, empty string), the "plain mode" is unexpectedly set to "false", instead of the default "true".
To better understand the issue, see this diff: 1123206365.
The template {{Replace}} is consequently affected: if doing {{replace|...|plain=}}
, the "plain mode" is also unexpectedly set to "false", instead of the default "true".
Therefore, I am suggesting the following code, that replaces {{{plain|true}}}
with {{{#if:{{{plain|}}}|{{{plain}}}|true}}
. In addition to being better practice, it will "detach" the template behavior from the module behavior, so that the template works as expected (i.e. empty parameter gives default mode "true"), whether the module remains as currently, or gets fixed in the future.
<includeonly>{{safesubst:#invoke:String|replace|source={{{1}}}|{{{2}}}|{{{3}}}|plain={{safesubst:#if:{{{plain|}}}|{{{plain}}}|true}}|count={{{count|}}}}}</includeonly><noinclude> {{documentation}} </noinclude>
I have checked in the whole wiki, and there is no {{replace|...|plain=}}
use currently. So the change is completely safe.
Finally, note that if the module is fixed in the future, it would be possible to simplify the template code to |plain={{{plain|}}}
.
Od1n (talk) 08:32, 19 August 2024 (UTC)
- I have just noticed that
Module:String.find()
is affected by the exact same issue. And I have already noticed a consequently affected template: {{If string}} (which is very rarely used), and another one: {{In string}}. These templates currently useString.find()
by default in "plain = false" mode (because of the module bug), and fixing the module would change the default mode of these templates to "true" if they are not modified adequately. - By "detaching" behaviors (as in the current edit request) and leveraging the powerful in-wiki search engine (that allows regex searching) to examinate the existing uses, fixing all of that is quite simple actually.
- (edit: just noticed that
Module:String.count()
({{string count}}, {{str count}}…) is affected by the same issue) - Od1n (talk) 08:45, 19 August 2024 (UTC)
- Done * Pppery * it has begun... 20:57, 19 August 2024 (UTC)
- Thanks. A few other edit requests should be following up, to fix the situation step by step.
- As a reminder, the "plain mode" may also be specified as an unnamed parameter. Fortuitously, it is very unlikely that someone has specified a "plain mode" as a both unnamed and empty parameter. However, when fixing the module, we should consider that the parameter value may have spaces.
- Od1n (talk) 01:38, 20 August 2024 (UTC)
- Done * Pppery * it has begun... 20:57, 19 August 2024 (UTC)