Module talk:Redirect: Difference between revisions

Content deleted Content added
m Reverted edit by 103.28.116.119 (talk) to last version by Cewbot
 
(26 intermediate revisions by 9 users not shown)
Line 1:
{{WikiProject banner shell|
{{WPRED}}
{{WikiProject Redirect}}
 
}}
== Why am I confused? ==
 
Line 164 ⟶ 165:
:::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 &rarr; Wikipedia, which isn't helpful. The template checks if the target is a redirect first, to minimise section stripping errors. &nbsp;&#8213;&nbsp;[[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>&lt;{{var|target}}></code> from the redirect's <code><nowiki>#REDIRECT [[</nowiki>&lt;{{var|target}}>]]</code>. If <code>&lt;{{var|target}}></code> does not contain a <code>&lt;{{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..&nbsp;&#8213;&nbsp;[[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]) {&#123;'''[[User:Lemondoge|Lemondoge]]'''&#124;[[User talk:Lemondoge|Talk]]&#124;[[Special:Contributions/Lemondoge|Contributions]]&#125;} 21:43, 16 April 2023 (UTC)
 
:Has this been tested? Scibunto manual does not explicitly say that isRedirect will be true or false. &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[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}} {&#123;'''[[User:Lemondoge|Lemondoge]]'''&#124;[[User talk:Lemondoge|Talk]]&#124;[[Special:Contributions/Lemondoge|Contributions]]&#125;} 12:43, 17 April 2023 (UTC)