Page MenuHomePhabricator

Merge all redirect constraints into one class
Closed, ResolvedPublic

Description

Per my comment on gerrit:

This is almost identical to 1175259, and I hate implementing the same changes twice... maybe it would be a good idea to merge all redirect constraint classes (including InvalidRedirectTargetConstraint from patch 1175254) into one class, e.g. "RedirectConstraint"? This would reduce quite a lot of code duplication, both in EditPage.php (where wpAllowedDoubleRedirectTarget and wpAllowedBrokenRedirectTarget could be simplified to one variable like wpAllowedInvalidRedirectTarget) as well as in the constraint classes and the unit tests, which are basically identical.

The various error messages could then be built from within the constraint class by saving the type of problem the redirect has in a variable and overriding getLegacyStatus() (per T384399; which is currently only done for BrokenRedirectConstraint)

The implementation of the SelfRedirectConstraint, BrokenRedirectConstraint and the DoubleRedirectConstraint is almost identical. After fixing T395767: BrokenRedirectConstraint allows changing broken redirect target to another non-existent page without error, I submitted a second patchset for T395768: DoubleRedirectConstraint fails to re-validate when redirect target changes between redirect pages, and noticed that the patchsets are almost identical. The addition of a fourth redirect constraint in T384578: Check Title::isValidRedirectTarget on redirect creation would cause even more code duplication.
Therefore, the three currently existing redirect constraints should be merged into one class, and the implementation of T384578 should also be added to this class in a separate patchset.

Details

Event Timeline

Just noticed that SelfRedirectConstraint could probably also be merged into that new class.

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

[mediawiki/core@master] Merge all redirect constraints into one

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

Merging all 4 of these makes sense.

Change #1176231 merged by jenkins-bot:

[mediawiki/core@master] editpage: merge all redirect constraints into one

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

SomeRandomDeveloper renamed this task from Merge BrokenRedirectConstraint and DoubleRedirectConstraint into one class to Merge all redirect constraints into one class.Aug 7 2025, 10:02 PM
SomeRandomDeveloper closed this task as Resolved.
SomeRandomDeveloper updated the task description. (Show Details)