Module talk:Redirect: Difference between revisions

Content deleted Content added
Line 164:
:::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)
::::<dl><dd><dl><dd><dl><dd>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)