Page MenuHomePhabricator

Check Title::isValidRedirectTarget on redirect creation
Closed, ResolvedPublicFeature

Description

On redirect creation, the following checks are now made:

  1. To see if it's a self-redirect (T29683)
  2. To see if it's a redirect to a red link (T326057)
  3. To see if it's a redirect to another redirect (T326056).

One final one check is relevant here; check Title::isValidRedirectTarget to avoid:

  1. Linking to invalid special pages like [[special:LogOut]].
  2. Entering a link to an impossible page, e.g. #REDIRECT [[..]]
  3. Entering an empty link (i.e. #REDIRECT [[]])

The list of which pages are valid/invalid may have something to do with whether $wgDisableHardRedirects is set or not. Wikipedia doesn't use the default here, for some reason, so it may be best to test it on a different wiki.

Event Timeline

Change #1175254 had a related patch set uploaded (by SomeRandomDeveloper; author: SomeRandomDeveloper):

[mediawiki/core@master] Add a warning when trying to create a redirect to an invalid target

https://gerrit.wikimedia.org/r/1175254

Change #1175254 merged by jenkins-bot:

[mediawiki/core@master] RedirectConstraint: warn for redirects pointing to an invalid redirect target

https://gerrit.wikimedia.org/r/1175254

This has been implemented, except for

Entering a link to an impossible page, e.g. #REDIRECT [[..]]
Entering an empty link (i.e. #REDIRECT [[]])

since it is not covered by Title::isValidRedirectTarget, as .. and empty strings are not valid titles.
I personally don't think this should be handled by an edit constraint, as e.g. creating a link to .. using [[..]] doesn't result in a warning either, but instead just doesn't parse the link syntax. If you still think this functionality is relevant, then please open a separate task for it.

I haven't tested this, but based on https://www.mediawiki.org/wiki/Manual:$wgInvalidRedirectTargets, the following are now prevented:

#REDIRECT [[Filepath]]
#REDIRECT [[Mypage]]
#REDIRECT [[Mytalk]]
#REDIRECT [[Redirect]]
#REDIRECT [[Mylog]]

All of these are valid page names and work pretty well as expected.

Maybe there is something I'm missing here?

Finally, I do think there is a general case for running a linter on edits and throwing an error if things like links to invalid pages are added, or brackets aren't balanced [[like this], or someone accidentally inserts <sub>Subscript text</sub> because they accidentally clicked on the WikiEditor toolbar. Maybe give users the chance to turn it off in preferences if they don't like it.

The issue for Redirects to Special:LogOut is that's rendered as a "soft redirect."

But on WMF wikis all redirects to special pages are rendered as "soft redirects" because $wgDisableHardRedirects=true; (it's false by default) but this blocks two different things, and it needs to be refactored T395326: `$wgDisableHardRedirects` should be split into 2 config settings.

Redirects to special pages should be allowed, but there's a need to fix T326054: Special pages don't display Mediawiki:redirectfrom (aka mw-redirectfrom) when redirected to.

I haven't tested this, but based on https://www.mediawiki.org/wiki/Manual:$wgInvalidRedirectTargets, the following are now prevented:

#REDIRECT [[Filepath]]
#REDIRECT [[Mypage]]
#REDIRECT [[Mytalk]]
#REDIRECT [[Redirect]]
#REDIRECT [[Mylog]]

All of these are valid page names and work pretty well as expected.

Maybe there is something I'm missing here?

Those names are checked against $title->isSpecial( $name ) as the setting only works for special pages, so the "Special:" prefix is omitted. A redirect to "Special:Filepath" would be invalid, one to "Filepath" not.

I haven't tested this, but based on https://www.mediawiki.org/wiki/Manual:$wgInvalidRedirectTargets, the following are now prevented:

#REDIRECT [[Filepath]]
#REDIRECT [[Mypage]]
#REDIRECT [[Mytalk]]
#REDIRECT [[Redirect]]
#REDIRECT [[Mylog]]

All of these are valid page names and work pretty well as expected.

Maybe there is something I'm missing here?

Those names are checked against $title->isSpecial( $name ) as the setting only works for special pages, so the "Special:" prefix is omitted. A redirect to "Special:Filepath" would be invalid, one to "Filepath" not.

OK well at least that make some sense.

For this to be coherent now, T395326: `$wgDisableHardRedirects` should be split into 2 config settings and T326054: Special pages don't display Mediawiki:redirectfrom (aka mw-redirectfrom) when redirected to really need to be fixed. Otherwise on WMF wikis, creating some redirects to special pages are warned that they won't work properly, and they don't work properly, whereas creating other redirects to special pages aren't warned, but do work.