Page MenuHomePhabricator

Improve double redirect handling by stopping and throwing error on redirect page
Open, Needs TriagePublicFeature

Description

Steps to replicate the issue

  • Go to a test/sandbox wiki.
  • Create a redirect from [[Bar]] to [[Qux]].
  • Create a redirect from [[Foo]] to [[Bar]]. Ignore any errors.
  • Go to https://nameofwiki/wiki/Foo.

What happens?

MediaWiki follows the first redirect, from [[Foo]] to [[Bar]], but then stops because [[Bar]] is also a redirect.

  • No error is thrown — the user is left to figure out what went wrong.
  • The user may want to fix the double redirect if their wiki has no bots performing this task. This requires them to return to Foo with &redirect=no, usually via the “redirected from” message, manually edit the page, and replace the target.

What should happen?

The problematic page is not [[Bar]], which functions without an issue, and where the wiki stops, but [[Foo]]. It makes little sense to throw an error on [[Bar]]. Therefore, an error should be thrown on [[Foo]]. The message can look something like those you get if you try to create a double redirect:

⚠️ This page is a double redirect page. It redirects to {{{1}}}, which in turn redirects to {{{2}}}. For technical reasons, it does not function. Consider replacing this page's redirect target with {{{2}}}.

To generate and see that error, the redirection needs to stop on [[Foo]], not [[Bar]] as it does now. To achieve that, the redirector needs to first check if its target is itself a redirect, and stop if that's the case.

If similar logic to that in redirectconstraint is followed, we can also deal here with redirect loops: (Foo->Bar->Foo).

And we can also at this point check for target page (non)existence, and self-redirects, and show errors for them. T396336: Self-redirect gives blue link to itself but probably shouldn't..

How to implement

Changes to be made to includes / Page / RedirectStore.php

To check if the target is a redirect, MediaWiki needs to check Title::isRedirect() before only following the redirect if it's NOT a redirect.

This should run and be able to generate errors even if &redirect=no is appended to the URL.

Impact

  • MediaWiki has to stop somewhere; stopping on [[Foo]] is equally as inconvenient for the casual visitor as stopping on [[Bar]].
  • There might be performance implications for checking Title::isRedirect() each time a redirect is accessed. This is the only potential disbenefit, but 1 action doesn't seem to be a great burden.
  • Otherwise, the actual impact on Wikimedia Foundation wikis is minimal, since WMF wikis have bots to fix double redirects. This proposal mainly affects third-party wikis that lack such bots.
  • There may be some negative feedback due to the change from current behaviour because it’s “always been done this way,” but that's not a great reason for doing something — people will get used to this system fairly quickly.

Programming principles

This aligns with key programming and software design principles:

  • Clarity and precision: Errors should be reported as close as possible to their cause, making it clear where the problem originates. This simplifies debugging and reduces user confusion.
  • Single Source of Truth (SSOT): The problematic redirect resides in [[Foo]], which causes an invalid state by pointing to another redirect. Reporting the error on [[Foo]] preserves the principle that each error or piece of data should have a single authoritative source or location for truth. This reduces duplication of error handling and maintains system consistency. For more on SSOT, see https://en.wikipedia.org/wiki/Single_source_of_truth.
  • Fail fast and early: Detecting and reacting to the problem immediately on the page causing it prevents cascading errors and harder-to-trace issues downstream.
  • User experience: Users expect that errors relate to the page they accessed. Reporting the error on [[Foo]] aligns with user expectations and facilitates appropriate corrective actions.

This is very similar to the logic needed for the RedirectConstraint.

Event Timeline

MediaWiki follows the first redirect, from [[Foo]] to [[Bar]], but then stops because [[Bar]] is also a redirect.

Stops with which outcome?
I get (Redirected from Redirect1) - Redirect to: NextRedirectPage

MediaWiki has to stop somewhere

Why, if it is not a circular redirect? MediaWiki could also redirect from Foo to Bar to Qux.

This aligns with key programming and software design principles:

Was that list created via some LLM?

The problematic redirect resides in [[Foo]], which causes an invalid state by pointing to another redirect.

"invalid state" of what exactly?

How is "throwing error on redirect page" more user-friendly than the current behavior (offering a link to click to get to the page they wanted to go to)?

How is "throwing error on redirect page" more user-friendly than the current behavior (offering a link to click to get to the page they wanted to go to)?

This is clearly explained in the summary.

MediaWiki follows the first redirect, from [[Foo]] to [[Bar]], but then stops because [[Bar]] is also a redirect.

Stops with which outcome?

You must be familiar with this behaviour. It just stops.

I get (Redirected from Redirect1) - Redirect to: NextRedirectPage

Indeed

MediaWiki has to stop somewhere

Why, if it is not a circular redirect? MediaWiki could also redirect from Foo to Bar to Qux.

Because this is the behaviour that was decided on. $wgMaxRedirects might have been set higher at some point, but it's been removed (https://www.mediawiki.org/wiki/Manual:$wgMaxRedirects).

This aligns with key programming and software design principles:

Was that list created via some LLM?

The problematic redirect resides in [[Foo]], which causes an invalid state by pointing to another redirect.

"invalid state" of what exactly?

The invalid state of the redirect.

How is "throwing error on redirect page" more user-friendly than the current behavior (offering a link to click to get to the page they wanted to go to)?

This is clearly explained in the summary.

No it isn't.

How is "throwing error on redirect page" more user-friendly than the current behavior (offering a link to click to get to the page they wanted to go to)?

This is clearly explained in the summary.

No it isn't.

I have explained why it is so, and I think the explanation is as clear as it could be. If my reasoning is somehow flawed, then I'd be grateful if you would be so kind as to point out where that might be.

If you believe that "This is clearly explained in the summary" then you may want to point to where it is explained in the summary.
I see a lot of text and bullet points which look AI-created but not really a clear advantage for users. Thanks.

If you believe that "This is clearly explained in the summary" then you may want to point to where it is explained in the summary.
I see a lot of text and bullet points which look AI-created but not really a clear advantage for users. Thanks.

See my previous point. It is hardly conducive to civil discourse when you fail to address points well made and just wave your hands around saying "this isn't good enough for me!"