Content deleted Content added
duh duh duh! |
m Reverted edit by 175.157.255.223 (talk) to last version by Anomie |
||
(107 intermediate revisions by 43 users not shown) | |||
Line 1:
{{WikiProject banner shell|
{{WikiProject Redirect}}
}}
== Why am I confused? ==
At [[Wikipedia:Village_pump_(technical)#Is_it_possible_to_resolve_a_redirect_in_template.3F|WP:VPT §Is it possible to resolve a redirect in template?]] you wrote:
:... <code><nowiki>[[{{#invoke:redirect|main|WP:AFC}}]]</nowiki></code> gets you [[{{#invoke:redirect|main|WP:AFC}}]] ...
So I visited [[Module:Redirect]] and found this:
:<code>---- This module accepts the name of a single page. It determines if the page is a redirect; if so it looks up the page, extracts the target, and returns the target name as text.</code>
So, why, he asks, are there two parameters? In the example you gave both <code>main</code> and <code>WP:AFC</code>. I tried your module with the redirect page from the WT:VPT conversation:
:<code><nowiki>[[{{#invoke:redirect|RNAS_Kirkwall|WP:AFC}}]]</nowiki></code> → [[{{#invoke:redirect|RNAS_Kirkwall|WP:AFC}}]]
:<code><nowiki>[[{{#invoke:redirect|main|RNAS_Kirkwall}}]]</nowiki></code> → [[{{#invoke:redirect|main|RNAS_Kirkwall}}]]
Why are two parameters necessary? And, surely there is a better error message than '''{{red|Script error}}'''.
—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 17:12, 18 March 2013 (UTC)
:It occurred to me to also wonder if the first parameter could be empty:
::<code><nowiki>[[{{#invoke:redirect||RNAS_Kirkwall}}]]</nowiki></code> → [[{{#invoke:redirect||RNAS_Kirkwall}}]]
:Apparently not. So what about meaningless text?
::<code><nowiki>[[{{#invoke:redirect|sdjadrsgjlk|RNAS_Kirkwall}}]]</nowiki></code> → [[{{#invoke:redirect|sdjadrsgjlk|RNAS_Kirkwall}}]]
:Again, apparently not. So what about the name of a real article?
::<code><nowiki>[[{{#invoke:redirect|UP Aerospace|RNAS_Kirkwall}}]]</nowiki></code> → [[{{#invoke:redirect|UP Aerospace|RNAS_Kirkwall}}]]
:Nope. Is "main" some sort of secret word?
:—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 17:34, 18 March 2013 (UTC)
::<nowiki>{{#invoke:}}</nowiki> takes two parameters: the first is the module name (''redirect'' in this case), the second the function to use from that module (''main'' in this case, as specified by the line "<code>function p.main(frame)</code>" in the module). So the third parameter given to #invoke is the first parameter given to the function. In that way modules can make more than one functions available.
::To get more information on the script error, you have click it. [[User:MrBlueSky|MrBlueSky]] ([[User talk:MrBlueSky|talk]]) 14:40, 19 March 2013 (UTC)
:::Thank you. I've learned a bit here.
:::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 15:16, 19 March 2013 (UTC)
::::Thanks for answering that! I've gotten used to using these module talk pages for anything ''but'' talking, and this is the first I noticed the conversation... [[User:Wnt|Wnt]] ([[User talk:Wnt|talk]]) 20:44, 19 March 2013 (UTC)
== Redirect types and categories ==
I am working on building a module to hold the matrix of the {{tl|redr}} codes and associated categories, and also to have logic that automatically detects the correct codes for a redirect. See [[Wikipedia:Lua_requests#Redirect_categorisation]] and especially the especially [[User:John Vandenberg/AutoCategoriseRedirect]] where I am doing some initial prototyping. The easiest to automatically detect are [[WP:Shortcuts]] and [[:Category:Cross-namespace redirects]], and those are the ones I am most interested in automatically detecting. {{ping|Wnt}}, if you think any of the functionality I am working on would benefit this module, and the current uses, some code sharing needs to be organised (the code could be put in this module, or in a separate module that this modules uses), as the automatic redirect type detection should use the 'Redirect' module to extract the redirect target. <span style="font-variant:small-caps">[[User:John Vandenberg|John Vandenberg]] <sup>'''([[User talk:John Vandenberg|chat]])'''</sup></span> 00:41, 22 January 2014 (UTC)
: Well, actually at the moment I can't edit the module on account of it being protected (Mr. Stradivarius did say I could get template editor status, but I procrastinated about picking out a more secure password). He actually rewrote a lot of the highest-level code in the module anyway, and should be good to ask. Also, I wonder about -- I don't really know -- how much time it takes to require a routine out of another module. I don't understand how you're going to get your module called from uncategorized redirects, but if you end up tagging a very large number of them, even a tiny delay for opening another module could add up. And, if someone ever goes in and edits the required Module:Redirect, it'll affect all those pages. There's also a little bit of optimization that can be done by combining the two modules: right now, you do an #invoke:Page|namespace and an invoke of this module, each of which make an expensive call to mw.title.new(), and both would have to be adapted if they're to share it. So I'm thinking you might want to just copy the code, as inelegant as that may be. [[User:Wnt|Wnt]] ([[User talk:Wnt|talk]]) 07:53, 22 January 2014 (UTC)
::I'll implement the new module slowly using this module, on only a few pages of each type, so that changes dont have a large impact. If there is a performance issue, I'll switch to calling the relevant functions directly. <span style="font-variant:small-caps">[[User:John Vandenberg|John Vandenberg]] <sup>'''([[User talk:John Vandenberg|chat]])'''</sup></span> 10:32, 26 January 2014 (UTC)
== Flag to resolve soft redirects and redirects at RfD ==
When a redirect is listed at RfD, it looks like [[User:John Vandenberg/testcases/Redirect/1]] (as documented poorly at [[mw:Help:Redirects]]), which the mediawiki software determines is not a 'redirect', and this module doesnt parse and extract the redirect target. It would be nice if {{tl|RFDnote}} and other functions could ask for the redirect target using this module, knowing that it is currently not an active redirect. Likewise, it would be nice if this module could extract the target from {{tl|soft redirect}}, {{tl|wiktionary redirect}}, etc. I think one 'soft=yes' flag would be sufficient to support any 'semi'-redirect page. I'm happy to put up a code mod in the sandbox if others think this is appropriate. Otherwise I'll write a SoftRedirect Module ;-) <span style="font-variant:small-caps">[[User:John Vandenberg|John Vandenberg]] <sup>'''([[User talk:John Vandenberg|chat]])'''</sup></span> 09:51, 26 January 2014 (UTC)
== Protected edit request on 15 April 2014 ==
{{edit protected|<!-- Page to be edited -->|answered=yes}}
<!-- Begin request -->
Please make [https://en.wikipedia.org/w/index.php?title=Module:Redirect/sandbox&diff=604357992&oldid=596960183 these changes], so that <nowiki>{{#invoke:redirect|main|{{TALKPAGENAME}}}}</nowiki> works right when the page name contains apostrophes or other characters escaped by {{tlf|TALKPAGENAME}}.
<!-- End request -->
[[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 21:13, 15 April 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> 06:25, 16 April 2014 (UTC)
::{{ping|Mr. Stradivarius}} [https://en.wikipedia.org/w/index.php?title=Module:Redirect/sandbox&diff=608926039&oldid=608825255 This change] will re-break this if it goes live. See the last test in [[Module talk:Redirect/sandbox testcases]]. (Unrelated: Why does this module have a /testcases and a /sandbox testcases?) [[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 16:10, 17 May 2014 (UTC)
:::{{ping|Jackmcbarn}} I've moved the sandbox test cases to [[Module:Redirect/testcases]]. I've also switched to doing the canonicalisation purely with title objects. This makes things easier coding-wise, but it does mean that we have one more expensive function call for each call to the module. Is this likely to cause problems anywhere? — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 04:55, 18 May 2014 (UTC)
::::{{ping|Mr. Stradivarius}} I don't think that will cause problems. [[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 17:30, 18 May 2014 (UTC)
== Query ==
{{tracked|T71441}}
{{ping|Wnt|Mr. Stradivarius}} just wondering if there might be any possibility of a module which would detect a disambiguation page? There is some logic associated with [[Template:Disambig editintro]] which will make it display automatically on such a page; I don't know if it can be exploited here. Thanks — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 09:15, 13 January 2016 (UTC)
:{{ping|MSGJ}} I had this idea back in 2014, but after talking about it on IRC it looks like it wouldn't be feasible. There's a Phabricator ticket about it at [[phab:T71441]]. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 09:40, 13 January 2016 (UTC)
::Oh well - pity! But paradoxes must be avoided at all costs ;) — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 09:51, 13 January 2016 (UTC)
:::I think there's actually a way to do this. I've elaborated on the ticket. [[User:Kaldari|Kaldari]] ([[User talk:Kaldari|talk]]) 21:18, 31 October 2016 (UTC)
== Protected edit request on 30 March 2017 ==
{{Edit template-protected|answered=yes}}
[https://en.wikipedia.org/w/index.php?title=Module%3ARedirect%2Fsandbox&type=revision&diff=772947654&oldid=772947233 Sandbox diffs]
Edits allow for the fragment to be included when requesting the target of a redirect, but only when the {{para|fulltext}} parameter is set, meaning no changes are required to templates that already use the module as-is.
Example:
* <code><nowiki>{{#invoke:Redirect|main|MOS:SEASON}}</nowiki></code>: {{#invoke:Redirect|main|MOS:SEASON}}
* <code><nowiki>{{#invoke:Redirect/sandbox|main|MOS:SEASON}}</nowiki></code>: {{#invoke:Redirect/sandbox|main|MOS:SEASON}}
----
* <code><nowiki>{{#invoke:Redirect|main|MOS:SEASON|fulltext=}}</nowiki></code>: {{#invoke:Redirect|main|MOS:SEASON|fulltext=}}
* <code><nowiki>{{#invoke:Redirect/sandbox|main|MOS:SEASON|fulltext=}}</nowiki></code>: {{#invoke:Redirect/sandbox|main|MOS:SEASON|fulltext=}}
----
* <code><nowiki>{{#invoke:Redirect|main|MOS:SEASON|fulltext=y}}</nowiki></code>: {{#invoke:Redirect|main|MOS:SEASON|fulltext=y}}
* <code><nowiki>{{#invoke:Redirect/sandbox|main|MOS:SEASON|fulltext=y}}</nowiki></code>: {{#invoke:Redirect/sandbox|main|MOS:SEASON|fulltext=y}}
-- '''[[User:AlexTheWhovian|<span style="color:#1632E0;text-shadow:1px 1px 8px #324A6E;">Alex</span>]]'''''[[User talk:AlexTheWhovian#top|<sup><span style="color:#1632E0">TW</span></sup>]]'' 10:03, 30 March 2017 (UTC)
:[https://en.wikipedia.org/w/index.php?oldid=772947233 URL 1] is the "old" part of your ''sandbox diffs'' link, and [https://en.wikipedia.org/w/index.php?oldid=772947654 URL 2] is the "new". Do I understand rightly that URL 1 is the current version of the module page, and that you're asking that we copy the content of URL 2 to the module? [[User:Nyttend|Nyttend]] ([[User talk:Nyttend|talk]]) 00:54, 3 April 2017 (UTC)
:PS, [[User:AlexTheWhovian|AlexTheWhovian]], I meant to ping you in the first edit but forgot. [[User:Nyttend|Nyttend]] ([[User talk:Nyttend|talk]]) 00:55, 3 April 2017 (UTC)
::{{re|Nyttend}} My bad. What I'm looking to be implemented is what is in the sandbox as it stands now. -- '''[[User:AlexTheWhovian|<span style="color:#1632E0;text-shadow:1px 1px 8px #324A6E;">Alex</span>]]'''''[[User talk:AlexTheWhovian#top|<sup><span style="color:#1632E0">TW</span></sup>]]'' 00:57, 3 April 2017 (UTC)
:::Done. They didn't make me an admin because I understand this kind of coding — as always, any admin should revert me without question if I made some sort of mistake. [[User:Nyttend|Nyttend]] ([[User talk:Nyttend|talk]]) 01:03, 3 April 2017 (UTC)
::::Thank you! Now I can proceed with my related projects. I've tested the code thoroughly, and the edits only add onto the previous version of the code; any article using the code should remain exactly the same as it was. Cheers for that. -- '''[[User:AlexTheWhovian|<span style="color:#1632E0;text-shadow:1px 1px 8px #324A6E;">Alex</span>]]'''''[[User talk:AlexTheWhovian#top|<sup><span style="color:#1632E0">TW</span></sup>]]'' 01:04, 3 April 2017 (UTC)
== Protected edit request on 26 June 2017 ==
{{edit fully-protected|Module:Redirect|answered=yes}}
For Testing [[User:SoumyaSahu|SoumyaSahu]] ([[User talk:SoumyaSahu|talk]]) 10:43, 26 June 2017 (UTC)
:{{not done}} Unclear request. If you want to modify test to the module, you may do so at [[Module:Redirect/sandbox]]. -- '''[[User:AlexTheWhovian|<span style="color:#1632E0;text-shadow:1px 1px 8px #324A6E;">Alex</span>]]'''''[[User talk:AlexTheWhovian#top|<sup><span style="color:#1632E0">TW</span></sup>]]'' 10:50, 26 June 2017 (UTC)
== cross project calls ==
Is there a way to show if a page in another project is a redirect and find the actual article? --[[User:Traveler100|Traveler100]] ([[User talk:Traveler100|talk]]) 11:31, 17 February 2018 (UTC)
* <nowiki>[[{{#invoke:redirect|main|voy:YYZ}}]]</nowiki> gives [[{{#invoke:redirect|main|voy:YYZ}}]] but want [[voy:Toronto Pearson International Airport]].
== Why parse the page content? ==
Hi. Why does this module parse the page text to find the redirect target? Why not use Title.redirectTarget instead? I guess Title.redirectTarget wasn't available when this was implemented, but now that it's there, it should be used instead. [[User:Qwertyytrewqqwerty|Qwertyytrewqqwerty]] ([[User talk:Qwertyytrewqqwerty|talk]]) 14:28, 3 March 2018 (UTC)
:Or maybe there's some good reason for it to work like that. [[User:AlexTheWhovian|AlexTheWhovian]], any thoughts on this?
:I have a version that uses Title.redirectTarget here: <s>[[es:Módulo:Redirect]]</s> [[es:Módulo:Redirección]] (no testcases, though). [[User:Qwertyytrewqqwerty|Qwertyytrewqqwerty]] ([[User talk:Qwertyytrewqqwerty|talk]]) 10:04, 9 March 2018 (UTC).
:I've [https://en.wikipedia.org/w/index.php?title=Special:ComparePages&page1=Module%3ARedirect&page2=Module%3ARedirect%2Fsandbox&diffmode=source sandboxed it] [[User:Galobtter|Galobtter]] ([[User talk:Galobtter|pingó mió]]) 11:41, 31 March 2018 (UTC)
:: Somebody sumbit an edit request!. [[User:Pppery|{{3x|p}}ery]] ([[User talk:Pppery|talk]]) 00:34, 15 May 2018 (UTC)
<!-- Apparently not a high priority since no updates for not than two years -->
== Expensive call? ==
Could someone add to the documentation that this module call is expensive (or not expensive)? - 15:58, 21 March 2018 (UTC)
== redirected files ==
{{phabricator|T193162}}
<code><nowiki>{{#invoke:redirect|isRedirect|File:IMAGE.jpg}}</nowiki></code> gives "{{#invoke:redirect|isRedirect|File:IMAGE.jpg}}" (blank), despite the fact that [[:File:IMAGE.jpg]] is a redirect to [[:File:IMAGE (Explorer 78).jpg]]. I created [[phabricator:T193162]] about this issue, but wanted to alert you that this module is also affected. --[[User:Jarekt|Jarekt]] ([[User talk:Jarekt|talk]]) 13:15, 26 April 2018 (UTC)
: [[User:Jarekt|Jarekt]], do you think this could be related to another strange behaviour (possibly related to isRedirect) causing spurious transclusions being reported in various places? See here: [[User talk:Paine Ellsworth#Interesting transclusion effect - any idea?]]
: Thanks and greetings. --[[User:Matthiaspaul|Matthiaspaul]] ([[User talk:Matthiaspaul|talk]]) 07:27, 30 July 2018 (UTC)
== Template-protected edit request on 11 February 2019 ==
{{edit template-protected|Module:Redirect|answered=yes}}
Kindly add me to the list. User: Shevonsilva [[User:Shevonsilva|Shevonsilva]] ([[User talk:Shevonsilva|talk]]) 22:48, 11 February 2019 (UTC)
:{{not done}} [[User:Shevonsilva]], this is the module, not the Wikiproject page, the module do not contain any user name list. If you would like to add your name to the project, you need to go to [[Wikipedia:WikiProject_Redirect#Participants]] and add your name there. -- [[User:VulpesVulpes825|VulpesVulpes825]] ([[User talk:VulpesVulpes825|Talk]]) 00:02, 12 February 2019 (UTC)
== Module redirection ==
There is not a warning system in ¨Wikipedia or WikiMedia to say: this module exists with other name (ie. taken the information from Wikidata), as Wikimedia Commons does when you try to upload an existing image.
So, what to do when creating a module, when one thinks it did not exist (and exist with other translated name)?.
Can be used temporally an <nowiki>{{#invoke:}}</nowiki> to the other module?. --[[User:BoldLuis|BoldLuis]] ([[User talk:BoldLuis|talk]]) 20:01, 14 May 2020 (UTC)
== Protected edit request on 7 September 2021 ==
{{edit fully-protected|Module:Redirect|answered=y}}
Please apply [[Special:Diff/980359053/1042912439|these changes]], originally written by [[User:Galobtter]]. This will make it so the redirect target is just taken from the table returned by {{code|mw.title.new}} using the {{code|redirectTarget}} property instead of having to find it in the wikitext of the redirect, saving an expensive parser function call. These changes cause a test case to fail, but that can be disregarded because they make it (and a few more) obsolete anyway. – [[User talk:Rummskartoffel|<span style="background:linear-gradient(90deg,#e40303,#ff8c00,#ffed00,#008026,#004dff,#750787);color:transparent;background-clip:text;-webkit-background-clip:text;">Rummskartoffel</span>]] 11:58, 7 September 2021 (UTC)
:{{done}}. {{ping|Rummskartoffel}} is it the testContentPercentInsideAmpersandCanonicalisation test you were referring to above? — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 05:34, 10 September 2021 (UTC)
::I restored function <code>p.getTargetFromText</code> because it is used by [[Module:RfD]] and the missing function was causing errors. In general, it is difficult to know if <code>p.Anything</code> is used elsewhere and it's safest to assume it is. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 07:50, 10 September 2021 (UTC)
::@[[User:MSGJ|MSGJ]]: Yes, that's the one. Since <code>getTargetFromText</code> is still used I guess these tests aren't obsolete after all, but should be changed to test that function directly. I might take a shot at that later. – [[User talk:Rummskartoffel|<span style="background:linear-gradient(90deg,#e40303,#ff8c00,#ffed00,#008026,#004dff,#750787);color:transparent;background-clip:text;-webkit-background-clip:text;">Rummskartoffel</span>]] 11:28, 10 September 2021 (UTC)
== Section is stripped ==
Not a redirect: <code><nowiki>WikiPedia#section</nowiki></code> → {{#invoke:Redirect|main|!!#section}}<br />
Redirect: <code><nowiki>{{#invoke:Redirect|main|WikiPedia#section}}</nowiki></code> → {{#invoke:Redirect|main|WikiPedia#section}}<br />
Pinging last editor @[[User:Johnuniq|Johnuniq]]. ― [[User:Qwerfjkl|<span style="background:#1d9ffc; color:white; padding:5px; box-shadow:darkgray 2px 2px 2px;">Qwerfjkl</span>]][[User talk:Qwerfjkl|<span style="background:#79c0f2;color:white; padding:2px; box-shadow:darkgray 2px 2px 2px;">talk</span>]] 18:47, 21 February 2022 (UTC)
:I was here only to fix an error which I tracked to this module. I might have a look later but as I know nothing about this module I would need to be told exactly what should happen with the above examples which I infer are wrong. Are the examples in the documentation correct? [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 23:41, 21 February 2022 (UTC)
:
:I'm not wholly convinced that there is anything really wrong with the module. [[!!]] is not a redirect page and it doesn't have a section that the <code>#section</code> fragment can link to. [[WikiPedia]] is a redirect to [[Wikipedia]]. The redirect page does not have a section that the <code>#section</code> fragment can link to; because 'WikiPedia' is a redirect, the module correctly returns the target page [[Wikipedia]]. Yeah, the module documentation says: {{tq| If page-name does not exist or is not a redirect then page-name is returned.}} If that is taken literally then perhaps it is broken. The fragments disappear at [[Module:Redirect#L-8|line 8]].
:—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 00:28, 22 February 2022 (UTC)
::@[[User:Trappist the monk|Trappist the monk]]: I apologise if I was unclear with my example, I just typed <code><nowiki>#section</nowiki></code> because I was in a hurry. The example <code><nowiki>{{#invoke:Redirect|main|WikiPedia#History}}</nowiki></code> → {{#invoke:Redirect|main|WikiPedia#History}} better demonstrates how the section is stripped when the redirect is followed, and likewise, if the page isn't a redirect, the section is still stripped:<br /><code><nowiki>{{#invoke:Redirect|main|Wikiedia#History}}</nowiki></code> → {{#invoke:Redirect|main|Wikipedia#History}}<br />While the module isn't broken ''per se'', it causes a problem at [[WP:AFCRC]] (from {{tl|Request redirect}}), and it would be nice if the module was <s>fixed</s> improved. Thank you for taking the time to respond to my hastily-added examples. ― [[User:Qwerfjkl|<span style="background:#1d9ffc; color:white; padding:5px; box-shadow:darkgray 2px 2px 2px;">Qwerfjkl</span>]][[User talk:Qwerfjkl|<span style="background:#79c0f2;color:white; padding:2px; box-shadow:darkgray 2px 2px 2px;">talk</span>]] 20:44, 22 February 2022 (UTC)
:::I looked in {{tlx|request redirect}} which you are apparently blaming for whatever issue it is that has arisen at [[WP:AFCRC]]. {{tlx|request redirect}} does not invoke [[Module:Redirect]]. Do you really mean {{tlx|request redirect/post}}? That template does invoke module:redirect. Without some sort of indication of what the problem really is and where it lies, and some sort of definitive test case that can illustrate problem and confirm the fix, I am not willing to make any changes to Module:redirect. Perhaps some other editor is.
:::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 00:08, 23 February 2022 (UTC)
::::I do mean {{tlx|Request redirect/post}}, specifically:<code><nowiki>
*Target of redirect: {{safesubst<noinclude/>:u2w|1={{safesubst<noinclude/>:#if: {{safesubst<noinclude/>:#invoke:redirect|isRedirect|{{{target|{{{2|}}}}}}}} | <!-- Is redirect, follow --> {{safesubst<noinclude/>:#invoke:redirect|main|{{safesubst<noinclude/>:trimbr|1={{{target|{{{2|}}}}}}}}}} | {{safesubst<noinclude/>:trimbr|1={{{target|{{{2|}}}}}}}} }} |error=no}}</nowiki></code><br />The problem is that if the "target of redirect" requested has a section, it is stripped e.g. Wikipedia#History → Wikipedia, which isn't helpful. The template checks if the target is a redirect first, to minimise section stripping errors. ― [[User:Qwerfjkl|<span style="background:#1d9ffc; color:white; padding:5px; box-shadow:darkgray 2px 2px 2px;">Qwerfjkl</span>]][[User talk:Qwerfjkl|<span style="background:#79c0f2;color:white; padding:2px; box-shadow:darkgray 2px 2px 2px;">talk</span>]] 07:16, 23 February 2022 (UTC)
:::::I have simplified the above mess to what I think are the essentials:
::::::<code><nowiki>{{#if: {{#invoke:redirect|isRedirect|{{{target}}}}} | <!-- Is redirect, follow --> {{#invoke:redirect|main|{{{target}}}}} | {{{target}}} }}</nowiki></code>
:::::replacing <code><nowiki>{{{target}}}</nowiki></code> with the 'target' you suggest above ('Wikipedia#History'):
::::::<code><nowiki>{{#if: {{#invoke:redirect|isRedirect|Wikipedia#History}} | <!-- Is redirect, follow --> {{#invoke:redirect|main|Wikipedia#History}} | Wikipedia#History }}</nowiki></code>
:::::::{{#if: {{#invoke:redirect|isRedirect|Wikipedia#History}} | <!-- Is redirect, follow --> {{#invoke:redirect|main|Wikipedia#History}} | Wikipedia#History }}
:::::That result because [[Wikipedia]] is not a redirect.
:::::
:::::Changing to 'WikiPedia#History':
::::::<code><nowiki>{{#if: {{#invoke:redirect|isRedirect|WikiPedia#History}} | <!-- Is redirect, follow --> {{#invoke:redirect|main|WikiPedia#History}} | WikiPedia#History }}</nowiki></code>
:::::::{{#if: {{#invoke:redirect|isRedirect|WikiPedia#History}} | <!-- Is redirect, follow --> {{#invoke:redirect|main|WikiPedia#History}} | WikiPedia#History }}
:::::That result because [[WikiPedia]] is a redirect where the target is specified as 'Wikipedia'.
:::::
:::::The purpose of [[Module:Redirect]] <code>main()</code> is to return <code><{{var|target}}></code> from the redirect's <code><nowiki>#REDIRECT [[</nowiki><{{var|target}}>]]</code>. If <code><{{var|target}}></code> does not contain a <code><{{var|#fragment}}></code> then module:redirect does not return a fragment. There are two ways for module:redirect to get a target from a redirect page:
::::::<code>p.getTargetFromText (text)</code> where <code>text</code> is the unparsed content of a redirect page – for WikiPedia, that is the <code><nowiki>#REDIRECT [[Wikipedia]]</nowiki></code> and the {{tlx|Redirect category shell}} template. This function is standalone so is not called by <code>main()</code>. To see this in action, enter this in a Scribuntu debug console {{small|(contents of WikiPedia all run-together here for convenience)}}:
:::::::<code><nowiki>=p.getTargetFromText ('#REDIRECT [[Wikipedia]] {{Redirect category shell|1={{R from incorrect capitalisation}}{{R from CamelCase}}}}')</nowiki></code>
:::::For the other way, module:redirect creates a title object and then queries the object to fetch the target. This is how <code>main()</code> gets the redirect target. To see this in action enter this in the debug console:
::::::<code>=mw.title.new ('WikiPedia').redirectTarget</code>
:::::Just for completeness, try this:
::::::<code>=mw.title.new ('WikiPedia#History').redirectTarget</code>
:::::All of those return 'Wikipedia' because that is the target specified in 'WikiPedia'.
:::::
:::::If {{tlx|Request redirect/post}} wants to apply a fragment, it is that template's responsibility to do so.
:::::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 15:32, 23 February 2022 (UTC)
::::::I agree that retaining the section is not the primary function of the module, I was just curious if it was possible/desirable to do so. As you advise to handle this in {{tlx|Request redirect/post}}, I'll implement that.. ― [[User:Qwerfjkl|<span style="background:#1d9ffc; color:white; padding:5px; box-shadow:darkgray 2px 2px 2px;">Qwerfjkl</span>]][[User talk:Qwerfjkl|<span style="background:#79c0f2;color:white; padding:2px; box-shadow:darkgray 2px 2px 2px;">talk</span>]] 16:19, 23 February 2022 (UTC)
:Note that redirects can themselves point to specific sections of pages; in such a case I'd assume (but don't have any examples handy to actually test) that the module will return the target page, with the section intact. If the module preserves any section passed in when the title passed in is a redirect, it would have to correctly handle that case. (I'm not completely sure how MediaWiki handles a link-with-section to a redirect that points to a specific section of a page, but it makes the most sense to me that in that case, MediaWiki would ignore the section on the link and only use the section targeted by the redirect.) <span class=nowrap>「[[User:Dinoguy1000|<span style=color:#00f>ディノ</span><span style=color:#080>奴</span>]][[Special:Contributions/Dinoguy1000|<span style=color:#F90>千?!</span>]]」<sup>[[User talk:Dinoguy1000#top|☎ Dinoguy1000]]</sup></span> 02:14, 25 February 2022 (UTC)
::I have created a redirect of my sandbox that redirects to this discussion ([[User:Trappist the monk/sandbox]] has <code><nowiki>#REDIRECT [[Module_talk:Redirect#Section_is_stripped]]</nowiki></code>).
::
::If you use the same form of invoke that is used in {{tlx|Request redirect/post}} you get:
:::<code><nowiki>{{#invoke:redirect|main|User:Trappist the monk/sandbox}}</nowiki></code> → {{#invoke:redirect|main|User:Trappist the monk/sandbox}}
::But, if you tell the invoke to return the full text of the redirect, you get:
:::<code><nowiki>{{#invoke:redirect|main|User:Trappist the monk/sandbox|fulltext=yes}}</nowiki></code> → {{#invoke:redirect|main|User:Trappist the monk/sandbox|fulltext=yes}}
::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 14:17, 25 February 2022 (UTC)
:::Interesting... if I add a section to the link to your sandbox page, it overrides the section in the target of the redirect: [[User:Trappist the monk/sandbox#Foobar]]. This is opposite to what I expected would happen. <span class=nowrap>「[[User:Dinoguy1000|<span style=color:#00f>ディノ</span><span style=color:#080>奴</span>]][[Special:Contributions/Dinoguy1000|<span style=color:#F90>千?!</span>]]」<sup>[[User talk:Dinoguy1000#top|☎ Dinoguy1000]]</sup></span> 08:34, 26 February 2022 (UTC)
::::I don't know why that is but I do know that it has nothing to do with [[Module:redirect]] because <code><nowiki>[[User:Trappist the monk/sandbox#Foobar]]</nowiki></code> is a generic, everyday, wikilink. Just as a test, I added a section §Foobar to my sandbox. That did not change anything; [[User:Trappist the monk/sandbox#Foobar]] redirects to the top of this page. Perhaps ask at [[WP:VPT]]?
::::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 18:50, 26 February 2022 (UTC)
:::::My point with it was that, if this module is changed to preserve sections on input, then it would have to handle the case where a section is passed in, but the input title is a redirect that includes a section itself. The obvious way to handle this case is to mirror what MediaWiki does. Beyond this, I have no particular opinion on the functionality in general. <span class=nowrap>「[[User:Dinoguy1000|<span style=color:#00f>ディノ</span><span style=color:#080>奴</span>]][[Special:Contributions/Dinoguy1000|<span style=color:#F90>千?!</span>]]」<sup>[[User talk:Dinoguy1000#top|☎ Dinoguy1000]]</sup></span> 12:08, 27 February 2022 (UTC)
== Exception for redirects that intentionally have Wikidata objects? ==
I have utilzed this nice module in {{tlp|Get QID|<Wikipedia page title>}} to follow redirects. Then Get QID still works if a page is moved.
However, there are redirects that intentionally have their own Wikidata objects. See [[:Category:Wikidata_redirects]]. In that case I want that template to give the QID of the source page, and not of the redirect destination page. Should I implement that in the template as an ugly work-around, or could this module take care of that problem?
For example, <nowiki>{{Q|{{get QID|388282 ʻAkepa}}}}</nowiki> gives <s>{{Q|18678271}}</s> {{Q|{{get QID|388282 ʻAkepa}}}}. I want it to result in {{Q|Q32037018}}.
Meaning: <nowiki>[[{{#invoke:redirect|main|388282 ʻAkepa}}]]</nowiki> now gives [[{{#invoke:redirect|main|388282 ʻAkepa}}]], but my question is if it can make an exception because the page belongs to the above mentioned category, and respond with [[388282 ʻAkepa]] ?
[[User:Tomastvivlaren|Tomastvivlaren]] ([[User talk:Tomastvivlaren|talk]]) 10:40, 1 March 2022 (UTC)
:I solved the problem temporarily using ugly template code in {{tl|Get QID}}.[[User:Tomastvivlaren|Tomastvivlaren]] ([[User talk:Tomastvivlaren|talk]]) 17:16, 1 March 2022 (UTC)
== Protected edit request on 16 April 2023 ==
{{edit fully-protected|Module:Redirect|answered=yes}}
This might be a little excessive for an edit to a fully protected module, but:
I would like to simplify the following (lines 103-107, in function <code>p.luaIsRedirect</code>):
<syntaxhighlight lang="lua">
if titleObj.isRedirect then
return true
else
return false
end
</syntaxhighlight>
to:
<syntaxhighlight lang="lua">
return titleObj.isRedirect
</syntaxhighlight>
because <code>titleObj.isRedirect</code> will only ever yield "true" or "false".
([https://en.wikipedia.org/wiki/Special:ComparePages?page1=Module%3ARedirect&rev1=1043472510&page2=Module%3ARedirect%2Fsandbox&rev2=1150203250&action=&unhide=&diffmode=source diff]) {{'''[[User:Lemondoge|Lemondoge]]'''|[[User talk:Lemondoge|Talk]]|[[Special:Contributions/Lemondoge|Contributions]]}} 21:43, 16 April 2023 (UTC)
:Has this been tested? Scibunto manual does not explicitly say that isRedirect will be true or false. — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 07:38, 17 April 2023 (UTC)
:@Lemondoge: I have noticed your edits to sandbox modules that I monitor. Thanks for the tweaks and thanks for finding the bug noted [[Template talk:Navbox#Short-circuit in ternary expression at line 143|here]]. However, I am not sure there is any benefit from optimizing code unless done as part of a significant effort by someone deeply invested in the particular module. Take this edit request—you are probably correct but who knows and who cares? It can be very challenging to verify rearrangements to boolean expressions. The original here is bulletproof. More importantly, it is easily seen to be bulletproof. I would leave it as is. It's not particularly important, but the edit request would result in uncertainty about what return values can occur while the original code removes any doubt. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 07:59, 17 April 2023 (UTC)
:: Aye, fair enough. {{Withdrawn}} {{'''[[User:Lemondoge|Lemondoge]]'''|[[User talk:Lemondoge|Talk]]|[[Special:Contributions/Lemondoge|Contributions]]}} 12:43, 17 April 2023 (UTC)
|