Module:Unsubst: Difference between revisions
sync from sandbox; see talk; |
|||
| Line 1: | Line 1: | ||
{{permanently protected}} | |||
==Edit request on 25 November 2013== | |||
{{edit protected|<!-- Page to be edited -->|answered=yes}} | |||
<!-- Begin request --> | |||
I get this error: | |||
Lua error in Module:Unsubst at | |||
line 18: attempt to call field | |||
'isSubsting' (a nil value). | |||
Shouldn't that be isSubstring? | |||
<!-- End request --> | |||
<span style="color:#d30000; text-decoration:inherit">☠</span>[[User:MarkAHershberger|MarkAHershberger]]<span style="color:#d30000; text-decoration:inherit">☢</span>([[User_talk:MarkAHershberger|talk]])<span style="color:#d30000; text-decoration:inherit">☣</span> 16:27, 25 November 2013 (UTC) | |||
* {{A note}} changed request from {{Tl|edit template-protected}} to {{Tl|edit protected}} because it is cascade protected. [[User:Technical 13|Technical 13]] ([[User talk:Technical 13|talk]]) 16:41, 25 November 2013 (UTC) | |||
::[[File:Pictogram voting comment.svg|20px|link=|alt=]] '''Note:'''<!-- Template:EP --> The module name is "Unsubst", implying a reversal of "subst"; "subst" is a verb, being Wiki shorthand for [[WP:SUBST|substitute]]; so the present participle would be "substing", and may be used in a phrase like "it is substing", hence I think that "isSubsting" is a reasonable name for an identifier, such as a function returning a Boolean result. --[[User:Redrose64|<span style="color:#a80000; background:#ffeeee; text-decoration:inherit">Red</span>rose64]] ([[User talk:Redrose64|talk]]) 17:22, 25 November 2013 (UTC) | |||
: [[File:Red information icon with gradient background.svg|20px|link=|alt=]] '''Not done:'''<!-- Template:EP --> As Redrose64 explained, isSubsting is the correct spelling. Where are you getting this error? Given that we haven't been inundated by people complaining that every maintenance tag (e.g. {{citation needed}}) is giving script errors, I am skeptical that you're seeing this here on enwiki. On non-WMF wikis, do note that you will need an extremely recent version of Scribunto (or you will have to cherry-pick [[gerrit:93019]]). [[User:Anomie|Anomie]][[User talk:Anomie|⚔]] 18:09, 25 November 2013 (UTC) | |||
== You can avoid using {{para|$N}} == | |||
You can get the template name from {{code|mw.getCurrentFrame():getTitle()|lua}} <span class="signature">— [[User:Kephir|Keφr]]</span> 08:59, 27 March 2014 (UTC) | |||
: I retract that. It does not seem to work. Shame, really. <span class="signature">— [[User:Kephir|Keφr]]</span> 09:28, 27 March 2014 (UTC) | |||
:: Oh wait, the proper code is {{code|mw.getCurrentFrame():getParent():getTitle()|lua}}, and it does work. (And above, I actually meant {{code|mw.getCurrentFrame().parent:getTitle()}}, which does not.) <span class="signature">— [[User:Kephir|Keφr]]</span> 09:50, 27 March 2014 (UTC) | |||
::: [[Special:Diff/581707228/598491600|Sandbox version]], needs review and deploy. {{ping|Mr. Stradivarius|Jackmcbarn}} any final comments? Or should we do this thing? My only comment is that I was worried about the expensive mw.title.new until I realized that only gets called on subst so it'd only be a problem if someone adds ~500 substed maintenance tags in one edit (if even that). [[User:Anomie|Anomie]][[User talk:Anomie|⚔]] 10:38, 27 March 2014 (UTC) | |||
:::: This is ready to go now, as far as I can see. However, I did tweak the error messages, as they were showing the #invoke call as <code><nowiki>{{#invoke:Unsubst|unsubst}}</nowiki></code>, when actually it's just <code><nowiki>{{#invoke:Unsubst|}}</nowiki></code>. As for the expensive mw.title.new, I agree that if it only gets called on subst then it shouldn't be a problem. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 12:20, 27 March 2014 (UTC) | |||
::::: {{ping|Anomie}} Is $N still deliberately in specialParams? (Do we need specialParams at all anymore?) [[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 22:21, 27 March 2014 (UTC) | |||
:::::: Mr. Stradivarius restored it in [//en.wikipedia.org/w/index.php?title=Module:Unsubst/sandbox&diff=598067783&oldid=598044098], and I agree with his reasoning. [[User:Anomie|Anomie]][[User talk:Anomie|⚔]] 20:23, 29 March 2014 (UTC) | |||
::::::: Ah, I was under the impression that that was done now. Anyway, looks good then. [[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 01:35, 30 March 2014 (UTC) | |||
:::::::: I've updated the module. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 01:54, 30 March 2014 (UTC) | |||
== mw.isSubsting not working == | |||
I have a local wikipedia copy and get the 'Lua error in Module:Unsubst atline 18: attempt to call field 'isSubsting' (a nill value)' error and I have changed the Unsubst module to the new one but still get the error, is there anything else I need to do? | |||
: Yes, you need to upgrade Scribunto to the latest version. Wikipedia uses the cutting-edge version of Scribunto, so you will need to go to the [https://www.mediawiki.org/wiki/Special:ExtensionDistributor/Scribunto download page] and select "master (latest development version)" from the drop-down menu. Earlier versions of Scribunto don't have the mw.isSubsting function. Although it is called the "latest development version", it should be stable enough to use in production. (If it's good enough for Wikipedia, it's probably good enough for you.) Hope this helps. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 12:19, 22 April 2014 (UTC) | |||
::Also, if you don't want to upgrade, then you can use the [https://en.wikipedia.org/w/index.php?title=Module:Unsubst&oldid=579696121 old version] of the module. That will work just fine, but you will need to specify the <code>$N</code> (template name) parameter in the #invoke text, whereas in the latest version this is not necessary. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 12:25, 22 April 2014 (UTC) | |||
::: Just installed the "master" version of Scribunto and it works :) Thanks very much. <span style="font-size: smaller;" class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/195.217.192.7|195.217.192.7]] ([[User talk:195.217.192.7|talk]]) 14:01, 22 April 2014 (UTC)</span><!-- Template:Unsigned IP --> | |||
== Protected edit request on 22 August 2014 == | |||
{{edit protected|Module:Unsubst|answered=yes}} | |||
<!-- Begin request --> | |||
Please make [[Special:Diff/622347161|these changes]]. | |||
<!-- End request --> | |||
[[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 15:04, 22 August 2014 (UTC) | |||
:[[File:Yes check.svg|20px|link=]] '''Done'''<!-- Template:EP --> — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 15:48, 22 August 2014 (UTC) | |||
== template invocation name override == | |||
Using this module imposes a time penalty. Not surprising, that. I have been experimenting with a module to translate {{tlx|Literatur}} (a template that attempts to translate de.wiki's [[:de:Vorlage:Literatur|Vorlage:Literatur]] to a {{tlx|citation}} template). In its current form, {{tld|Literatur}} is always subst'd so I tweaked {{tlx|citation/new}} (the sandbox) to use this module. At {{slink|Help_talk:Citation_Style_1|non-English_translator_templates_and_substing}} I was queried about the time penalty. My simple experiments show that there is a significant time penalty for no benefit. | |||
In that discussion, I wondered if the translator module might call a special substable version of {{tld|citation}} so I created {{tlx|citation/subst}} which uses this module and then modified the translator module to call that template. The substitution worked as it should except that the substituted template name was {{tld|citation/subst}}. In that discussion at [[WT:CS1]], I also wondered if this module might be tweaked to support a template invocation name override parameter. I have {{diff|Module:Unsubst/sandbox|1039776614|784253929|tweaked the sandbox}} to support {{para|$template-name}}. {{tld|citation/subst}} uses this parameter to set the template name to <code>citation/new</code> and when a {{tlx|Literatur/sandbox}} template is subst'd, the result is an invocation of {{tld|citation/new}}. | |||
If there are no objections, I will update the live module from the sandbox. Comments, of course, are welcome. | |||
—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 18:06, 20 August 2021 (UTC) | |||
: [[User:Trappist the monk|Trappist the monk]], I was just about to ask the same question. it looks like there are no objections, so I would suggest you go ahead and make the change. thank you. [[User:Frietjes|Frietjes]] ([[User talk:Frietjes|talk]]) 14:58, 8 October 2021 (UTC) | |||
::done | |||
::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 18:22, 8 October 2021 (UTC) | |||
== Question about sigs in this template == | |||
I'm looking to add a signature option to {{t|Dashboard.wikiedu.org assignment}} using this template so that if someone adds the template, a bot can subst the call and return the original template call plus the user's signature (or maybe even just a timestamp). However, I am concerned that adding in something dynamic like a timestamp will cause issues if the template is substed. Basically, I'm not sure how to code it so that it gives accurate information that stays static after substing. Example: | |||
*<code><nowiki>{{dashboard.wikiedu.org assignment | course = Wikipedia:Example | assignments = [[User:Primefac]] | start_date = 2022-01-24 | end_date = 2022-05-13 }}</nowiki></code> | |||
*{{dashboard.wikiedu.org assignment | course = Wikipedia:Example | assignments = [[User:Primefac]] | start_date = 2022-01-24 | end_date = 2022-05-13 }} | |||
Substing the template call would ideally give something like | |||
*{{dashboard.wikiedu.org assignment | course = Wikipedia:Example | assignments = [[User:Primefac]] | start_date = 2022-01-24 | end_date = 2022-05-13 }} 08:16, 16 March 2022 (UTC) | |||
This is primarily to allow for archiving when the course is over (because at current, sections [[Talk:GLAAD#Wiki_Education_assignment:_Gender_and_Technoculture|like this]] won't ever be archived). Please let me know how far off the mark I am. Thanks! [[User:Primefac|Primefac]] ([[User talk:Primefac|talk]]) 08:17, 16 March 2022 (UTC) | |||
: The module already has a magic value <code><nowiki>__DATE__</nowiki></code> that is replaced with the current month and year when adding the parameter while substing. This is used in maintenance templates. [[User:Anomie|Anomie]][[User talk:Anomie|⚔]] 11:44, 16 March 2022 (UTC) | |||
::Right, I guess it's just a question of how I can best use that to include a timestamp for archival purposes... [[User:Primefac|Primefac]] ([[User talk:Primefac|talk]]) 14:08, 16 March 2022 (UTC) | |||
== Square brackets == | |||
When I read the documentation I incorrectly assumed that the square brackets were a required part of the syntax, i.e. {{para|$aliases|[œuf>egg,melt>cheese]}} but actually it should be {{para|$aliases|œuf>egg,melt>cheese}} Perhaps the wording can be made clearer? — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 11:53, 17 July 2024 (UTC) | |||
== Substituted wrapper templates == | |||
A common way this module is used with wrapper templates which are supposed to be replaced, e.g. | |||
<syntaxhighlight lang="wikitext">{{SAFESUBST:<noinclude />#invoke:Unsubst|main | |||
|Senegal=yes|subst= | |||
|$template-name=WikiProject Africa | |||
|$flags=override,remove-empty | |||
|$aliases=importance>Senegal-importance | |||
|$B={{WikiProject Africa | |||
|class={{{class|}}} | |||
|Senegal=yes | |||
|Senegal-importance={{{importance|}}} | |||
|category={{{category|}}} | |||
}} | |||
}}</syntaxhighlight> | |||
It seems to me there could be a simpler way to do this, rather than (a) having to pass all known parameters to the target template, and (b) specifying the target template twice effectively. Could we consider an additional flag for <code>wrapper</code> which could do this? — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 12:02, 17 July 2024 (UTC) | |||
: That doesn't seem like a common use for this module to me. Or if it is, people have been doing some weird stuff with it. Seems like you'd do better with a different module that requires <code>$template-name</code> but doesn't take a <code>$B</code> option. [[User:Anomie|Anomie]][[User talk:Anomie|⚔]] 02:29, 18 July 2024 (UTC) | |||
== Page protections and code architecture == | |||
This module seems really poorly architected. I do not mean to slight anyone that has worked on this as it is a very useful concept and I realize it was sort of organically developed but this lack of architectural foresight now has significant implications that I want to point out. This module is heavily used to prevent template substitutions but in its 12 million plus transclusions it is basically doing nothing except getting out of the way (i.e., yielding its {{para|$B}}), however, the majority of the logic in this module comes into play during substitutions (which by definition go away at page save time) and yet the entire module is fully protected from any changes by anyone but administrators. | |||
It seems to me it would be much more useful to develop a module that does the unsubst'ing and another module that checks for substitution and either gets out of the way or loads (on demand) the unsubst'ing module to generate a template invocation that us not {{code|subst:}}ed. The "get out of the way under normal transclusion" module can be a fully protected stub module transcluded upon millions of pages while the unsubst'ing module can be (mostly) unprotected because it is transcluded nowhere (because that is what substitution means). | |||
return | In any event, I wanted to record my thoughts on the subject until someone comes up with a better solution (which might be me if I get the time since I am thinking about this). —[[User:Uzume|Uzume]] ([[User talk:Uzume|talk]]) 16:04, 12 October 2024 (UTC) | ||
:@[[User:Uzume|Uzume]] I would be happy to port over my completely different implementation at [[wikt:Module:unsubst]] which indeed isn't transcluded on any pages, despite protecting templates which are invoked many millions of times. | |||
:{{pb}} | |||
:The way it works for module-based templates is to have something like this at the top level in the modules which need to be protected, which means it's never called if it's not needed:<syntaxhighlight lang=lua>if mw.isSubsting() then | |||
return require("Module:unsubst") | |||
end</syntaxhighlight> | |||
:There are two issues which need to be considered in doing this, though: | |||
:# I haven't got a ready-made template wrapper which does this for non-Lua templates, but it wouldn't be especially difficult to write one. | |||
:# The if-block implementation assumes that the module it's in is only ever called via <code>#invoke</code> (i.e. that it's not called from other modules, which would result in breakage), which fits Wiktionary's module architecture, but may not be suitable in all Wikipedia modules. However, this shouldn't be too difficult to adapt as appropriate. | |||
:[[User:Theknightwho|Theknightwho]] ([[User talk:Theknightwho|talk]]) 23:07, 4 August 2025 (UTC) | |||
::@[[User:Theknightwho|Theknightwho]]: I haven't thought about this for a while now but thanks for the feedback. Even though we sort of already have the key requirement in {{tlx|ifsubst}} and it should not be that hard to implement a template based on that that either calls {{code|#invoke}} or returns the "body" or an error which could be protected and should not need much further development freeing the module to do just the wikitext template invocation construction, that won't really work as the wikitext generation module needs access to the parent frame which would be lost if there was another template in between. To that end, we {{em|do}} need a single "get out of the way" module that would then be able to do something like the code you provided above. I always like reading your code even when I am confused by how you write it. For example, [[wikt:Module:pages#L-101]] could be simplified to just <syntaxhighlight lang=lua inline>if type(val) ~= "table" then</syntaxhighlight> because it is not an error to call {{code|lang=lua|type}} on {{code|lang=lua|nil}} (or any value; it does throw an error if no value is provided though so <syntaxhighlight lang=lua inline>type(fn())</syntaxhighlight> might be dangerous; a clear difference using expression lists and varargs vs. assignment and function parameters where empty values are implicitly converted to {{code|lang=lua|nil}}). The same logic can be applied to simplify [[wikt:Module:pages#L-108--L-109]] too. I often prefer to not test for {{code|lang=lua|nil}} but just check something is the type I expect and move on. I doubt the comparison prior to the call to {{code|lang=lua|type}} buys you much in terms of speed. I know Lua employs [[string interning]] (sort of like memoization) for the creation of all strings which are immutable. This means every string is compared to all the others via hash tables at creation time and that for every string with a certain value there is only a single instance. That makes {{code|lang=lua|1=~=}} and {{code|lang=lua|1===}} very fast for strings (i.e., literally only a reference comparison since interning guarantees no two strings can be equal unless they are the same reference). Since the results of {{code|lang=lua|type}} are severely limited, I imagine such string construction overhead is minimal and probably based upon literals. Anyway, I got off on a tangent. Thanks for the pointer to your [[wikt:Module:unsubst]] implementation. I think I meant to look at that anyway. —[[User:Uzume|Uzume]] ([[User talk:Uzume|talk]]) 01:51, 5 August 2025 (UTC) | |||
::The problem with your [[wikt:Module:unsubst]] is that it allows transclusions with its {{mlx|unsubst|me|{{=}}...}} syntax so that transclusion stub will eventually get used and eventually the module will end up protected like this one is either due to a large number of transclusions and/or sensitive ones (via a cascade). | |||
::I was thinking of a super simple stub similar to your {{code|me}} stub like: | |||
::<syntaxhighlight lang=lua> | |||
if mw.isSubsting() then | |||
local frame= mw.getCurrentFrame() | |||
return require("Module:" .. frame.args[''] or mw.wikibase.getSitelink('Q15243885')) | |||
end | |||
local mt = {} | |||
function mt:__index(key) | |||
return function(frame) | |||
return key | |||
end | |||
end | |||
return setmetatable({}, mt) | |||
</syntaxhighlight> | |||
::And maybe call this [[Module:Unsubststub]] (or perhaps with your nomenclature [[Module:Unsubstme]]). This would allow something similar to your [[wikt:Module:unsubst]] but without the {{code|me}} transclusion stub (instead always generating an error during transclusions) and this stub code is simple and flexible enough that protections due to high transclusion counts, etc. would not be an issue. It would also allow for potentially different kinds of unsubsting wikitext generation modules to be used for different formats, etc. (e.g., this module vs. [[Module:Unsubst-infobox]], etc.) I appreciate your impressive [[wikt:Module:template parser]] but it is a little heavy compared to this module (although it does seem to only be called during the substing path so the impact is to page save and not to page render). —[[User:Uzume|Uzume]] ([[User talk:Uzume|talk]]) 16:31, 5 August 2025 (UTC) | |||
Revision as of 16:36, 5 August 2025
Template:Permanently protected
Edit request on 25 November 2013
Template:Edit protected I get this error:
Lua error in Module:Unsubst at line 18: attempt to call field 'isSubsting' (a nil value).
Shouldn't that be isSubstring? ☠MarkAHershberger☢(talk)☣ 16:27, 25 November 2013 (UTC)
- Template:A note changed request from {{edit template-protected}} to {{edit protected}} because it is cascade protected. Technical 13 (talk) 16:41, 25 November 2013 (UTC)
- File:Pictogram voting comment.svg Note: The module name is "Unsubst", implying a reversal of "subst"; "subst" is a verb, being Wiki shorthand for substitute; so the present participle would be "substing", and may be used in a phrase like "it is substing", hence I think that "isSubsting" is a reasonable name for an identifier, such as a function returning a Boolean result. --Redrose64 (talk) 17:22, 25 November 2013 (UTC)
- File:Red information icon with gradient background.svg Not done: As Redrose64 explained, isSubsting is the correct spelling. Where are you getting this error? Given that we haven't been inundated by people complaining that every maintenance tag (e.g. Template:Citation needed) is giving script errors, I am skeptical that you're seeing this here on enwiki. On non-WMF wikis, do note that you will need an extremely recent version of Scribunto (or you will have to cherry-pick gerrit:93019). Anomie⚔ 18:09, 25 November 2013 (UTC)
You can avoid using |$N=
You can get the template name from Template:Code — Keφr 08:59, 27 March 2014 (UTC)
- I retract that. It does not seem to work. Shame, really. — Keφr 09:28, 27 March 2014 (UTC)
- Oh wait, the proper code is Template:Code, and it does work. (And above, I actually meant Template:Code, which does not.) — Keφr 09:50, 27 March 2014 (UTC)
- Sandbox version, needs review and deploy. Template:Ping any final comments? Or should we do this thing? My only comment is that I was worried about the expensive mw.title.new until I realized that only gets called on subst so it'd only be a problem if someone adds ~500 substed maintenance tags in one edit (if even that). Anomie⚔ 10:38, 27 March 2014 (UTC)
- This is ready to go now, as far as I can see. However, I did tweak the error messages, as they were showing the #invoke call as
{{#invoke:Unsubst|unsubst}}, when actually it's just{{#invoke:Unsubst|}}. As for the expensive mw.title.new, I agree that if it only gets called on subst then it shouldn't be a problem. — Mr. Stradivarius ♪ talk ♪ 12:20, 27 March 2014 (UTC)- Template:Ping Is $N still deliberately in specialParams? (Do we need specialParams at all anymore?) Jackmcbarn (talk) 22:21, 27 March 2014 (UTC)
- Mr. Stradivarius restored it in [1], and I agree with his reasoning. Anomie⚔ 20:23, 29 March 2014 (UTC)
- Ah, I was under the impression that that was done now. Anyway, looks good then. Jackmcbarn (talk) 01:35, 30 March 2014 (UTC)
- I've updated the module. — Mr. Stradivarius ♪ talk ♪ 01:54, 30 March 2014 (UTC)
- Ah, I was under the impression that that was done now. Anyway, looks good then. Jackmcbarn (talk) 01:35, 30 March 2014 (UTC)
- Mr. Stradivarius restored it in [1], and I agree with his reasoning. Anomie⚔ 20:23, 29 March 2014 (UTC)
- Template:Ping Is $N still deliberately in specialParams? (Do we need specialParams at all anymore?) Jackmcbarn (talk) 22:21, 27 March 2014 (UTC)
- This is ready to go now, as far as I can see. However, I did tweak the error messages, as they were showing the #invoke call as
- Sandbox version, needs review and deploy. Template:Ping any final comments? Or should we do this thing? My only comment is that I was worried about the expensive mw.title.new until I realized that only gets called on subst so it'd only be a problem if someone adds ~500 substed maintenance tags in one edit (if even that). Anomie⚔ 10:38, 27 March 2014 (UTC)
- Oh wait, the proper code is Template:Code, and it does work. (And above, I actually meant Template:Code, which does not.) — Keφr 09:50, 27 March 2014 (UTC)
mw.isSubsting not working
I have a local wikipedia copy and get the 'Lua error in Module:Unsubst atline 18: attempt to call field 'isSubsting' (a nill value)' error and I have changed the Unsubst module to the new one but still get the error, is there anything else I need to do?
- Yes, you need to upgrade Scribunto to the latest version. Wikipedia uses the cutting-edge version of Scribunto, so you will need to go to the download page and select "master (latest development version)" from the drop-down menu. Earlier versions of Scribunto don't have the mw.isSubsting function. Although it is called the "latest development version", it should be stable enough to use in production. (If it's good enough for Wikipedia, it's probably good enough for you.) Hope this helps. — Mr. Stradivarius ♪ talk ♪ 12:19, 22 April 2014 (UTC)
- Also, if you don't want to upgrade, then you can use the old version of the module. That will work just fine, but you will need to specify the
$N(template name) parameter in the #invoke text, whereas in the latest version this is not necessary. — Mr. Stradivarius ♪ talk ♪ 12:25, 22 April 2014 (UTC)- Just installed the "master" version of Scribunto and it works :) Thanks very much. — Preceding unsigned comment added by 195.217.192.7 (talk) 14:01, 22 April 2014 (UTC)
- Also, if you don't want to upgrade, then you can use the old version of the module. That will work just fine, but you will need to specify the
Protected edit request on 22 August 2014
Template:Edit protected Please make these changes. Jackmcbarn (talk) 15:04, 22 August 2014 (UTC)
- File:Yes check.svg Done — Mr. Stradivarius ♪ talk ♪ 15:48, 22 August 2014 (UTC)
template invocation name override
Using this module imposes a time penalty. Not surprising, that. I have been experimenting with a module to translate {{Literatur}} (a template that attempts to translate de.wiki's Vorlage:Literatur to a {{citation}} template). In its current form, {{Literatur}} is always subst'd so I tweaked {{citation/new}} (the sandbox) to use this module. At Template:Slink I was queried about the time penalty. My simple experiments show that there is a significant time penalty for no benefit.
In that discussion, I wondered if the translator module might call a special substable version of {{citation}} so I created {{citation/subst}} which uses this module and then modified the translator module to call that template. The substitution worked as it should except that the substituted template name was {{citation/subst}}. In that discussion at WT:CS1, I also wondered if this module might be tweaked to support a template invocation name override parameter. I have Template:Diff to support |$template-name=. {{citation/subst}} uses this parameter to set the template name to citation/new and when a {{Literatur/sandbox}} template is subst'd, the result is an invocation of {{citation/new}}.
If there are no objections, I will update the live module from the sandbox. Comments, of course, are welcome.
—Trappist the monk (talk) 18:06, 20 August 2021 (UTC)
- Trappist the monk, I was just about to ask the same question. it looks like there are no objections, so I would suggest you go ahead and make the change. thank you. Frietjes (talk) 14:58, 8 October 2021 (UTC)
- done
- —Trappist the monk (talk) 18:22, 8 October 2021 (UTC)
Question about sigs in this template
I'm looking to add a signature option to Template:T using this template so that if someone adds the template, a bot can subst the call and return the original template call plus the user's signature (or maybe even just a timestamp). However, I am concerned that adding in something dynamic like a timestamp will cause issues if the template is substed. Basically, I'm not sure how to code it so that it gives accurate information that stays static after substing. Example:
{{dashboard.wikiedu.org assignment | course = Wikipedia:Example | assignments = [[User:Primefac]] | start_date = 2022-01-24 | end_date = 2022-05-13 }}- Template:Dashboard.wikiedu.org assignment
Substing the template call would ideally give something like
- Template:Dashboard.wikiedu.org assignment 08:16, 16 March 2022 (UTC)
This is primarily to allow for archiving when the course is over (because at current, sections like this won't ever be archived). Please let me know how far off the mark I am. Thanks! Primefac (talk) 08:17, 16 March 2022 (UTC)
- The module already has a magic value
__DATE__that is replaced with the current month and year when adding the parameter while substing. This is used in maintenance templates. Anomie⚔ 11:44, 16 March 2022 (UTC)
Square brackets
When I read the documentation I incorrectly assumed that the square brackets were a required part of the syntax, i.e. |$aliases=[œuf>egg,melt>cheese] but actually it should be |$aliases=œuf>egg,melt>cheese Perhaps the wording can be made clearer? — Martin (MSGJ · talk) 11:53, 17 July 2024 (UTC)
Substituted wrapper templates
A common way this module is used with wrapper templates which are supposed to be replaced, e.g.
{{SAFESUBST:<noinclude />#invoke:Unsubst|main
|Senegal=yes|subst=
|$template-name=WikiProject Africa
|$flags=override,remove-empty
|$aliases=importance>Senegal-importance
|$B={{WikiProject Africa
|class={{{class|}}}
|Senegal=yes
|Senegal-importance={{{importance|}}}
|category={{{category|}}}
}}
}}
It seems to me there could be a simpler way to do this, rather than (a) having to pass all known parameters to the target template, and (b) specifying the target template twice effectively. Could we consider an additional flag for wrapper which could do this? — Martin (MSGJ · talk) 12:02, 17 July 2024 (UTC)
- That doesn't seem like a common use for this module to me. Or if it is, people have been doing some weird stuff with it. Seems like you'd do better with a different module that requires
$template-namebut doesn't take a$Boption. Anomie⚔ 02:29, 18 July 2024 (UTC)
Page protections and code architecture
This module seems really poorly architected. I do not mean to slight anyone that has worked on this as it is a very useful concept and I realize it was sort of organically developed but this lack of architectural foresight now has significant implications that I want to point out. This module is heavily used to prevent template substitutions but in its 12 million plus transclusions it is basically doing nothing except getting out of the way (i.e., yielding its |$B=), however, the majority of the logic in this module comes into play during substitutions (which by definition go away at page save time) and yet the entire module is fully protected from any changes by anyone but administrators.
It seems to me it would be much more useful to develop a module that does the unsubst'ing and another module that checks for substitution and either gets out of the way or loads (on demand) the unsubst'ing module to generate a template invocation that us not Template:Codeed. The "get out of the way under normal transclusion" module can be a fully protected stub module transcluded upon millions of pages while the unsubst'ing module can be (mostly) unprotected because it is transcluded nowhere (because that is what substitution means).
In any event, I wanted to record my thoughts on the subject until someone comes up with a better solution (which might be me if I get the time since I am thinking about this). —Uzume (talk) 16:04, 12 October 2024 (UTC)
- @Uzume I would be happy to port over my completely different implementation at wikt:Module:unsubst which indeed isn't transcluded on any pages, despite protecting templates which are invoked many millions of times.
- Template:Pb
- The way it works for module-based templates is to have something like this at the top level in the modules which need to be protected, which means it's never called if it's not needed:
if mw.isSubsting() then return require("Module:unsubst") end
- There are two issues which need to be considered in doing this, though:
- I haven't got a ready-made template wrapper which does this for non-Lua templates, but it wouldn't be especially difficult to write one.
- The if-block implementation assumes that the module it's in is only ever called via
#invoke(i.e. that it's not called from other modules, which would result in breakage), which fits Wiktionary's module architecture, but may not be suitable in all Wikipedia modules. However, this shouldn't be too difficult to adapt as appropriate.
- Theknightwho (talk) 23:07, 4 August 2025 (UTC)
- @Theknightwho: I haven't thought about this for a while now but thanks for the feedback. Even though we sort of already have the key requirement in
{{ifsubst}}and it should not be that hard to implement a template based on that that either calls Template:Code or returns the "body" or an error which could be protected and should not need much further development freeing the module to do just the wikitext template invocation construction, that won't really work as the wikitext generation module needs access to the parent frame which would be lost if there was another template in between. To that end, we Template:Em need a single "get out of the way" module that would then be able to do something like the code you provided above. I always like reading your code even when I am confused by how you write it. For example, wikt:Module:pages#L-101 could be simplified to justif type(val) ~= "table" thenbecause it is not an error to call Template:Code on Template:Code (or any value; it does throw an error if no value is provided though sotype(fn())might be dangerous; a clear difference using expression lists and varargs vs. assignment and function parameters where empty values are implicitly converted to Template:Code). The same logic can be applied to simplify wikt:Module:pages#L-108--L-109 too. I often prefer to not test for Template:Code but just check something is the type I expect and move on. I doubt the comparison prior to the call to Template:Code buys you much in terms of speed. I know Lua employs string interning (sort of like memoization) for the creation of all strings which are immutable. This means every string is compared to all the others via hash tables at creation time and that for every string with a certain value there is only a single instance. That makes Template:Code and Template:Code very fast for strings (i.e., literally only a reference comparison since interning guarantees no two strings can be equal unless they are the same reference). Since the results of Template:Code are severely limited, I imagine such string construction overhead is minimal and probably based upon literals. Anyway, I got off on a tangent. Thanks for the pointer to your wikt:Module:unsubst implementation. I think I meant to look at that anyway. —Uzume (talk) 01:51, 5 August 2025 (UTC) - The problem with your wikt:Module:unsubst is that it allows transclusions with its Template:Mlx syntax so that transclusion stub will eventually get used and eventually the module will end up protected like this one is either due to a large number of transclusions and/or sensitive ones (via a cascade).
- I was thinking of a super simple stub similar to your Template:Code stub like:
if mw.isSubsting() then local frame= mw.getCurrentFrame() return require("Module:" .. frame.args[''] or mw.wikibase.getSitelink('Q15243885')) end local mt = {} function mt:__index(key) return function(frame) return key end end return setmetatable({}, mt)
- And maybe call this Module:Unsubststub (or perhaps with your nomenclature Module:Unsubstme). This would allow something similar to your wikt:Module:unsubst but without the Template:Code transclusion stub (instead always generating an error during transclusions) and this stub code is simple and flexible enough that protections due to high transclusion counts, etc. would not be an issue. It would also allow for potentially different kinds of unsubsting wikitext generation modules to be used for different formats, etc. (e.g., this module vs. Module:Unsubst-infobox, etc.) I appreciate your impressive wikt:Module:template parser but it is a little heavy compared to this module (although it does seem to only be called during the substing path so the impact is to page save and not to page render). —Uzume (talk) 16:31, 5 August 2025 (UTC)
- @Theknightwho: I haven't thought about this for a while now but thanks for the feedback. Even though we sort of already have the key requirement in