View text source at Wikipedia
Module:Transcluder is permanently protected from editing because it is a heavily used or highly visible module. 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.
|
This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
I added a |nofollow=
to disable following redirects. See Module:Transcluder/sandbox. This has two main uses:
{{subst:#invoke:Transcluder|main|User:Psihedelisto|nofollow=y}}
.Pinging Sophivorus as this is their module. Psiĥedelisto (talk • contribs) please always ping! 02:01, 19 July 2020 (UTC)
only
didn't work on more than 1 element for meHere, called there. — 𝐆𝐮𝐚𝐫𝐚𝐩𝐢𝐫𝐚𝐧𝐠𝐚 (talk) 22:11, 24 May 2021 (UTC)
I'm trying my hand at it in the sandbox, but still gotta debug. — 𝐆𝐮𝐚𝐫𝐚𝐩𝐢𝐫𝐚𝐧𝐠𝐚 (talk) 21:16, 30 May 2021 (UTC)
ustring is a lot slower.[1] The reason is that
Scribunto implements mw.ustring by using Lua to replace the regex library which is a breathtaking accomplishment but which makes it slower than using plain strings.[2] Mr._Stradivarius also says that
using mw.ustring has the drawback of having to cross back and forth between Lua and PHP all the time, which reduces the performance by quite a bit.[3] — 𝐆𝐮𝐚𝐫𝐚𝐩𝐢𝐫𝐚𝐧𝐠𝐚 (talk) 02:21, 31 May 2021 (UTC)
For an example of problems, see Electoral results for the district of Parramatta (which is currently showing a million "time allocated for running scripts has expired" errors). That is solved by removing all the mw.ustring stuff but the bigger question is why articles are using this guaranteed-to-fail method of padding articles. Johnuniq (talk) 05:26, 18 July 2021 (UTC)
@Sophivorus: I edited mw:Module:Transcluder to fix a couple of problems and copied that module to Module:Transcluder. That means "non" is accepted as "no" which frankly is not a problem but if it were, it can be removed later. Having the two modules the same is simpler now. mw:Module:Transcluder/testcases is showing one problem, namely testReferences:
acfgk
acfgk<ref name="l" />
I think the test text for that is the following (from mw:Module:Transcluder/test#References).
a<ref>b</ref>c<ref name="d">e</ref>f<ref name="d" />g<ref name="h" group="i">j</ref>k<ref name="l" />
I cannot see why the code would ever remove <ref name="l" />
. It only removes <ref name="d" />
because there is another ref with name="d"
. Any ideas? Johnuniq (talk) 09:43, 20 July 2021 (UTC)
if flags and not truthy(flags) then text = mw.ustring.gsub(text, '<%s*[Rr][Ee][Ff][^>/]*>.-<%s*/%s*[Rr][Ee][Ff]%s*>', '') text = mw.ustring.gsub(text, '<%s*[Rr][Ee][Ff][^>/]*/%s*>', '') return references, text end
Unfortunately, function getNamespaces is not performing as intended the function
local function getNamespaces(name) local namespaces = mw.site.namespaces[name].aliases table.insert(namespaces, mw.site.namespaces[name].name) table.insert(namespaces, mw.site.namespaces[name].canonicalName) return namespaces end
Although 'namespaces' is a local variable, the table.insert is actually adding to the global values
A test
function p.td() tab = getNamespaces('Category') mw.log(#tab) tab = getNamespaces('Category') mw.log(#tab) tab = getNamespaces('Category') mw.log(#tab) end
returns 2, 4, 6
I think mw.clone() would help eg
local namespaces = mw.clone(mw.site.namespaces[name].aliases)
Desb42 (talk) 10:06, 24 November 2021 (UTC)
namespaces
as a pointer to the aliases
table in mw.site.namespaces and unexpectedly it allows that table to be modified (presumably it's only a temporary table so the modifications have no effect). The function should be a bit smarter and not add duplicates—in this example both .name
and .canonicalName
are "Category" and getNamespaces returns a table including both. I'll have a look later to see if a fix would be warranted (that is, how is getNamespaces used?). I checked for changes since I last looked at the module and there is another problem: local min, max = string.match
is no longer adequate now that en dash and em dash have been included in the regex. One fix would be to use ustring.match. It might be better (I haven't thought about it yet) to instead use gsub to replace en/em dashes with a hyphen before doing the match. Johnuniq (talk) 02:59, 25 November 2021 (UTC)
'^(%d+)%s*[-–—]s*(%d+)$'
has a typo that would make it almost never work—the second s
should be %s
. I can't (quickly) work out what to do about the returned flags
table—for a range like 3-5
the table would have numeric keys 3, 4, 5 but for a plain number such as 3
the table would have a string key '3'. Finally, the function should use tonumber first rather than looking for a range then setting min, max to the same value if the text is a number rather than a range. Johnuniq (talk) 04:26, 25 November 2021 (UTC)
Those working on the module need to decide whether input 3-5
should result in keys that are numbers while input 3
gives a key that is a string. It doesn't make sense for them to be different although quirks in the code could possibly make it work. To illustrate the difference:
t = {} t[1] = 'My key is a number' t['1'] = 'My key is a string' for i, v in ipairs(t) do ... end -- processes t[1] only
Johnuniq (talk) 23:13, 27 November 2021 (UTC)
3-5
', but in for i = min, max do flags[i] = true end
, i
can only be a number and min
, max
will be automatically converted to numbers if possible. I think your code would work but I edited mw:Module:Transcluder to show what I recommend. There is very little practical difference but I think checking for input "3
" before checking for "3-5
" is cleaner. The line
min = tonumber(range:match('^%s*(%d+)%s*$'))
min = tonumber(range)
1.2e1
(which tonumber regards as 12) or broken input like 1.2
(which would give a non-integer key). Johnuniq (talk) 06:17, 1 December 2021 (UTC)I have just created Module:Sandbox/Desb42/Transcluder to test out a number of ideas
Desb42 (talk) 16:27, 27 November 2021 (UTC)
I noticed the MediaWiki version is slightly out of data with the English WP version:[4] fgnievinski (talk) 03:01, 29 January 2022 (UTC)
On Platform Engineering Team/SOPs/Intake Process the last section is failing with this error when attempting to transclude "intake" from another page. I traced this to the second sub call on line 443, which is string.sub(text, suffix)
. Perhaps someone here will know what causes this and how to repair the module and/or the page using it (If the latter, perhaps we can handle the issue and render a more helpful error). Krinkle (talk) 03:26, 5 February 2022 (UTC)
string.match
at line 438 and it fails if the pattern is not found. At any rate, in your application someone has gone to trouble of using a labeled section transclusion although they included an extra heading which may or may not have been wanted. At mw:Platform Engineering Team/SOPs/Intake Process#Platform Operations and Dumps the {{excerpt}} should be replaced with the following which has a much lower overhead.{{#section:Platform Engineering Team/Platform Operations and Dumps|intake}}
Hello, over at wikispecies, Felis catus (this version) is using this module to display a vernacular name where on enwiki "Featured article" or equivalent would display. However, if one chooses French (fr) as one's language from the language selector, the Vernacular name is displaying the entries both for fr=Chat domestique and frr=Kaat; how do you ensure only (fr=) Chat domestique is displayed?
<indicator name="vernacular pagename">[ {{{style|<span style="border-bottom:1px dotted">}}}{{#invoke:Transcluder|main|{{BASEPAGENAME}}|only=parameters|parameters={{Uselang}}}}</span> ]</indicator>
Thank you, Maculosae tegmine lyncis (talk) 09:30, 15 March 2022 (UTC)
{{#invoke:Transcluder|main|{{BASEPAGENAME}}|only=parameters|parameters=^{{Uselang}}$}}
. That is, use a regular expression with ^ and $ to indicate the start and end of the parameter. Cheers! Sophivorus (talk) 15:20, 2 December 2022 (UTC)This edit request has been answered. Set the |answered= or |ans= 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)
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)
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)
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)
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)
This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
Changes are on the sandbox. This implements 2 fixes for getParameters()
%
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=
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 of 1="[[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)
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)
-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 for ipairs
to be used, which is probably helpful. Thoughts? Aidan9382 (talk) 17:02, 21 February 2023 (UTC)
This edit request has been answered. Set the |answered= or |ans= 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)
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.
An editor has nominated this article for deletion. You are welcome to participate in the deletion discussion, which will decide whether or not to retain it. |
Frenemies is a podcast hosted by Trisha Paytas and Ethan Klein on the H3 Podcast. Running from September 15, 2020 to June 8, 2021, the podcast focused on discussing personal experiences, pop culture, internet drama and mental health.[1] It consisted of 39 episodes and two accompanying vlogs. Paytas and Klein's friendship was occasionally tumultuous, leading to episodes that were incomplete due to a verbal argument.[2] The podcast came to an end during its 39th episode, after a dispute with Paytas and Klein about podcast revenue[3] and production ownership.[4] Despite this, Frenemies gained recognition in the podcasting realm and found a place in numerous Top 50 lists,[5][6] frequently pulling in millions of viewers per episode.[4][7]
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)
[^|]
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)
[^]]
, which doesn't need to be [^%]]
, cheers! Sophivorus (talk) 15:27, 2 August 2023 (UTC)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?