Module talk:Transcluder
Edit request in re nofollow
I added a
Pinging Sophivorus as this is their module.
|
![]() | This edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
This is a change to some of the regexes. Ive noticed that for some reason, the onlyinclude tag is case sensitive. For example, transclusing the content on this revision of my page would return the content 13</onlyincludE>
(Yes, even the commented onlyinclude took effect. Not gonna ask). Do note however that includeonly and noinclude are not case sensitive. (Try transcluding this revision of my page and the results are perfectly normal). Implemented on the sandbox. Aidan9382 (talk) 10:39, 19 May 2022 (UTC)
Respecting the order in getParameters
Hey! I had recently come across a situation in which I needed the parameters of a template parsed, but with the order tracked due to later processing reasons, so I had to add a specialised local version of this module's getParameters which did so. I was wondering, do you think it would be worth it to include the order as one of the returns? For backwards compatability reasons, it'd need to be the 3rd value returned as to not ruin the function of current templates that dont need or want the order, but I think it might be worth having this as an option. An example of how this works is in the sandbox. Aidan9382 (talk) 15:25, 7 October 2022 (UTC)
- @Aidan9382 I just deployed your changes, thanks! Sophivorus (talk) 15:11, 2 December 2022 (UTC)
overuse of ucfirst/lcfirst
the local function matchFlag
local function matchFlag(value, flags)
if not value then return false end
value = tostring(value)
local lang = mw.language.getContentLanguage()
for flag in pairs(flags) do
if value == tostring(flag)
or lang:lcfirst(value) == flag
or lang:ucfirst(value) == flag
or ( not tonumber(flag) and mw.ustring.match(value, flag) ) then
return true
end
end
end
could benefit from having invariants removed from the for loop eg
local function matchFlag(value, flags)
if not value then return false end
value = tostring(value)
local lang = mw.language.getContentLanguage()
local lcvalue = lang:lcfirst(value)
local ucvalue = lang:ucfirst(value)
for flag in pairs(flags) do
if value == tostring(flag)
or lcvalue == flag
or ucvalue == flag
or ( not tonumber(flag) and mw.ustring.match(value, flag) ) then
return true
end
end
end
This is a function that is used frequently within this module. Desb42 (talk) 14:01, 2 December 2022 (UTC)
- @Desb42 I just deployed your changes, thanks! Sophivorus (talk) 15:11, 2 December 2022 (UTC)
Another ucfirst/lcfirst change
The following function can be improved (I believe)
local function removeSelfLinks(text)
local lang = mw.language.getContentLanguage()
local page = escapeString(mw.title.getCurrentTitle().prefixedText)
text = text
:gsub('%[%[(' .. lang:ucfirst(page) .. ')%]%]', '%1')
:gsub('%[%[(' .. lang:lcfirst(page) .. ')%]%]', '%1')
:gsub('%[%[' .. lang:ucfirst(page) .. '|([^]]+)%]%]', '%1')
:gsub('%[%[' .. lang:lcfirst(page) .. '|([^]]+)%]%]', '%1')
return text
end
by moving the uc/lcfirst to
local function removeSelfLinks(text)
local lang = mw.language.getContentLanguage()
local page = escapeString(mw.title.getCurrentTitle().prefixedText)
local ucpage = lang:ucfirst(page)
local lcpage = lang:lcfirst(page)
text = text
:gsub('%[%[(' .. ucpage .. ')%]%]', '%1')
:gsub('%[%[(' .. lcpage .. ')%]%]', '%1')
:gsub('%[%[' .. ucpage .. '|([^]]+)%]%]', '%1')
:gsub('%[%[' .. lcpage .. '|([^]]+)%]%]', '%1')
return text
end
A slightly more controversial change is to check if the text contains '[[' at all
local function removeSelfLinks(text)
if text:find('%[%[') then -- any links at all?
local lang = mw.language.getContentLanguage()
local page = escapeString(mw.title.getCurrentTitle().prefixedText)
local ucpage = lang:ucfirst(page)
local lcpage = lang:lcfirst(page)
text = text
:gsub('%[%[(' .. ucpage .. ')%]%]', '%1')
:gsub('%[%[(' .. lcpage .. ')%]%]', '%1')
:gsub('%[%[' .. ucpage .. '|([^]]+)%]%]', '%1')
:gsub('%[%[' .. lcpage .. '|([^]]+)%]%]', '%1')
end
return text
end
Desb42 (talk) 16:43, 2 December 2022 (UTC)
- @Desb42 Deployed, thanks again! Sophivorus (talk) 13:42, 23 January 2023 (UTC)
Confusing escape logic in getParameters
Hey! I've recently been trying to diagnose an issue within a separate module that relies on Transcluder, and I've pinned the issue down to the getParameters
function. I'm specifically looking at link processing in a template here, so unsure if this effects subtemplate processing too. The main issue here appears to be escapeString( mw.ustring.gsub(link, '%%', '%%%%') )
on this line which was added in this revision. This appears to be over-escaping the string (turning something like "[[:File:20200324 Global average temperature - NASA-GISS HadCrut NOAA Japan BerkeleyE.svg#Pairwise correlation|pairwise correlations exceeding 98%]]
" into "%[%[:File:20200324 Global average temperature %- NASA%-GISS HadCrut NOAA Japan BerkeleyE%.svg#Pairwise correlation|pairwise correlations exceeding 98%%%%%]%]
", even though escaping "%
" should really lead to "%%
", not "%%%%
", and this causes the code to treat the wikilink's pipe like a parameter pipe as it's never escaped properly. @Sophivorus: was this intentional and fixed some other bug, or is this safe to just plainly revert? (And if the latter, could you do so?) Thanks. Aidan9382 (talk) 13:52, 18 January 2023 (UTC)
- Note: After some testing, it seems this is required or else it does some weird capturing logic, but this does need some fixing per the above bit. Once I've found a proper solution I'll post an edit request. Aidan9382 (talk) 08:39, 23 January 2023 (UTC)
Edit request
![]() | This edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
Changes are on the sandbox. This implements 2 fixes for getParameters()
- Fixes the way
%
is handled when hiding pipes in wikilinks (previously, if a % was present, the link would fail to gsub, leading to pipes in the link not being escaped and instead being interpreted like the start of a new parameter), which fixes the issue described above - Escapes
=
in subtemplates and links while processing parameters to avoid accidentally treating them as defining parameters (e.g. thinking[[Page|String=with equals]]
means"[[Page|String" = "with equals]]"
instead of1="[[Page|String=with equals]]"
)
I've tested the fix using Template:Transclude lead excerpt/testcases to ensure nothing broke and my sandbox to ensure the fix actually fixes anything. These are testable further using the Debug Console while editing and the code on said sandbox (look inside the collapsable box). Thanks. Aidan9382 (talk) 10:11, 23 January 2023 (UTC)
Completed. Editor Aidan9382, thank you sincerely for your edits! Have you considered getting the TE bit? P.I. Ellsworth , ed. put'r there 12:49, 23 January 2023 (UTC)
- @Aidan9382 Thanks for the bug report and the fixes! Sorry for not replying on time, I guess I'm not as active as before. If I recall correctly, the double escaping %%%% you removed used to fix this issue with URLs that contain % characters, but after your fix, the issue doesn't seem to have reappeared, so we're good. BTW, if you decide to request the template-editor permission, you have my support, cheers! Sophivorus (talk) 12:52, 23 January 2023 (UTC)
- To editor Sophivorus: No problems, and glad to hear it hasn't caused any other issues. I imagine URLs should would work fine, as its only escaped so it can be gsubbed safely (meaning it basically immediately unescapes), but if it turns out something does crop up, I'll be sure to refine it further (though hopefully that won't happen).
- To editor Paine Ellsworth: Thanks for implementing this. I have, though I'm just a little short on the guidelines. Once I'm past that though, I probably will, especially if Module:Excerpt/portals starts picking up more transclusions (its close to the 5k TE protection, and it seems I can't get away from it just yet). Aidan9382 (talk) 13:00, 23 January 2023 (UTC)
- Didn't realize – it seems like you've been around for longer. Learning a lot from you. Happy New Year and Best of Everything to You and Yours! P.I. Ellsworth , ed. put'r there 13:10, 23 January 2023 (UTC)
- @Aidan9382 Thanks for the bug report and the fixes! Sorry for not replying on time, I guess I'm not as active as before. If I recall correctly, the double escaping %%%% you removed used to fix this issue with URLs that contain % characters, but after your fix, the issue doesn't seem to have reappeared, so we're good. BTW, if you decide to request the template-editor permission, you have my support, cheers! Sophivorus (talk) 12:52, 23 January 2023 (UTC)
Numerical keys in getParameters
Hey! Currently, when getParameters receives a numerical key, the type it returns can vary. For example, if a template went like {{ABC|X|Y}}
, getParameters would return {[1]="X", [2]="Y"}
, but if the keys were explicitly defined like {{ABC|1=X|2=Y}}
, you would instead get {["1"]="X", ["2"]="Y"}
. Should this be standardised to always be a string/number, and which? Aidan9382 (talk) 10:41, 21 February 2023 (UTC)
- @Aidan9382 Agree! I guess I'd favor numbers rather than strings, per being cleaner? However, if you decide to implement it yourself, feel free to choose whichever you like. You may want to know that the master module has several testcases that you can make use of and extend. As to me, I've taken note of the issue and will implement it eventually, someday, if you don't do it before. I usually work by "streaks", so it may take me some time but eventually I'll do a catch up with this and several other ideas I got in mind. Cheers! Sophivorus (talk) 14:39, 21 February 2023 (UTC)
- @Sophivorus: if you want it numerical, I've theorised it on the sandbox (note that it specifically matches integers >=1, not all numbers like
-1.5
). I'm wondering if it's worth having an __index metatable that would automatically try to find the numerical index if given a string, purely to make working on the parameters with template inputs to be more convenient since they always give strings (wouldn't be overly complicated to implement), but I'm undecided - though I think keeping it numerical either way is preferable, since that allows foripairs
to be used, which is probably helpful. Thoughts? Aidan9382 (talk) 17:02, 21 February 2023 (UTC)- On second thought, I think just forcing numerical is fine. It would definitely be more natural to reference numerical parameters using a number, and so forcing strings is probably the wrong move (and likely no good for backwards compatability too). The metatable is probably overkill - on the rare occasion someone needs to work with template inputs in such a specific way that this sort of key type consistency is required, that can be handled pretty easily on that module's end (like here). Aidan9382 (talk) 15:22, 1 March 2023 (UTC)
- @Sophivorus: if you want it numerical, I've theorised it on the sandbox (note that it specifically matches integers >=1, not all numbers like
Avoid interpreting no-value keys as numerical index values in getParameters
![]() | This edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
Somehow keep finding more bugs to do with getParameters. Currently, if getParameters is presented with a situation like {{Test|A=|B= |C=}}
, it'll return {[1]="A", [2]="C" ["B"]=""}
. The behaviour of B goes as expected, but A and C are interpreted as numerical indexes. This is because of the check seeing if its an empty string after a concatenation not considering that the given value could've just been empty. I've changed it in the sandbox to properly account for this.
(When implementing the changes, avoid implementing the changes on lines 289-291 on the sandbox, as that bit is to do with the discussion above and not this bugfix). Aidan9382 (talk) 12:58, 23 February 2023 (UTC)
- Nevermind, I can implement it myself now.
Done, I suppose. Aidan9382 (talk) 08:53, 24 February 2023 (UTC)
- To editor Aidan9382: the TE bit couldn't have happened to a better editor! Gonna miss your TERs
Congrats! P.I. Ellsworth , ed. put'er there 20:05, 24 February 2023 (UTC)
- Appreciated! Wasn't even expecting to get it this soon, but it ended up coming to me. Hopefully gonna get around to handling some edit requests myself at some point once I've got a good idea on how to handle em. Aidan9382 (talk) 21:02, 24 February 2023 (UTC)
- To editor Aidan9382: the TE bit couldn't have happened to a better editor! Gonna miss your TERs
Square brackets retained despite links=no parameter.
I recently used {{excerpt|Frenemies (podcast)|Label 1=Frenemies|links=no|hat=no}}
This may well an error of implementation on my part but it returned the following paragraph with open square brackets at the start of the first (parent page) wikilinked term.

The H3 Podcast is a live commentary podcast hosted by Ethan Klein. The show airs on YouTube and started in 2016.
The H3 Podcast is among the most listened-to podcasts in the United States. According to the 2023 U.S. Podcast Report by Triton Digital, the podcast was among the 100 most downloaded podcasts in 2023.[1] The podcast ranked 22nd in Edison Research's list of shows with the largest weekly audience in the third quarter of 2023.[2]
References
|
---|
References
|
I manually pasted the content into the article, but I thought I'd bring it up in-case it is a bug. Pabsoluterince (talk) 12:45, 2 August 2023 (UTC)
- @Pabsoluterince You might want to post this over at Module talk:Transcluder, as that's the module that actually handles retrieving the text and removing the wikilinks. --Ahecht (TALK
PAGE) 13:47, 2 August 2023 (UTC) - At Module:Transcluder#L-584,
[^|]
should probably become[^%]|]
, so it doesn't mistake[[Link1]] and [[Link2|Pipetext]]
for a single wikilink to article called "Link1]] and [[Link2
". I can't verify this easily, because previewing a module change without template editor privilege requires a lot of tedious copying to titles we can edit. On reflection, doesn't that whole block require a lot of % escapes for magic characters such as [ and ]? Certes (talk) 13:48, 2 August 2023 (UTC)- I've added the missing %] to Module:Transcluder/sandbox, which seems to fix the problem. I've also created an older version which adds further missing % signs to escape other magic characters in character sets. Looking at Template:Excerpt/testcases with either version shows lots of invisible differences. I think, but am not sure, that these are all adding &editintro=Template:Excerpt/editintro to the [edit] links on one side only and differing [numbers] on the citations. Certes (talk) 14:41, 2 August 2023 (UTC)
- The differences in testcases were already present. A simple copy-paste without formatting shows the same differences [sic] before and after my change. Certes (talk) 14:48, 2 August 2023 (UTC)
- @Pabsoluterince Bugfix deployed @Certes Thanks as always. As to your older version with further bugfixes, I'll take a closer look asap, but I believe that sometimes escaping with % is not necessary when the regex structure can only mean that the character must be escaped, as in
[^]]
, which doesn't need to be[^%]]
, cheers! Sophivorus (talk) 15:27, 2 August 2023 (UTC)
- @Pabsoluterince Bugfix deployed @Certes Thanks as always. As to your older version with further bugfixes, I'll take a closer look asap, but I believe that sometimes escaping with % is not necessary when the regex structure can only mean that the character must be escaped, as in
- The differences in testcases were already present. A simple copy-paste without formatting shows the same differences [sic] before and after my change. Certes (talk) 14:48, 2 August 2023 (UTC)
- I've added the missing %] to Module:Transcluder/sandbox, which seems to fix the problem. I've also created an older version which adds further missing % signs to escape other magic characters in character sets. Looking at Template:Excerpt/testcases with either version shows lots of invisible differences. I think, but am not sure, that these are all adding &editintro=Template:Excerpt/editintro to the [edit] links on one side only and differing [numbers] on the citations. Certes (talk) 14:41, 2 August 2023 (UTC)
This module isn't documented elsewhere
This is a very useful module, but it isn't mentioned in Help:Transclusion or Help:Labeled section transclusion. Should these pages be updated to describe it?
- Both of them mention {{Excerpt}}, which is the easiest way to access Module:Transcluder's functions unless you're writing another Lua module. Those help pages are more about how to use transclusion than internal implementation details, so I think that's the right level to link at. Perhaps the links could be more prominent. Certes (talk) 10:58, 1 September 2023 (UTC)
Support {{R}}
Is there a way to support references tagged by {{R}}? It's a trending practice in Chinese Wikipedia that they use {{R}} everywhere for references. Also, it would be great if {{R}} is counted as references instead of templates. SuperGrey (talk) 04:15, 17 March 2025 (UTC)
- I added the support to {{R}} in zh:Special:Diff/86472428 (Chinese Wikipedia). Still, it still doesn't support all the parameters in {{R}} but only the ref names and page numbers (used {{Rp}} instead). SuperGrey (talk) 10:00, 17 March 2025 (UTC)
Portal di Ensiklopedia Dunia