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.