Page MenuHomePhabricator

BrokenRedirectConstraint allows changing broken redirect target to another non-existent page without error
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue

  • Try to create a redirect to a non-existent page, such as [[Foobar1234567890]].
  • An error is thrown.
  • Change the redirect target to a different non-existent page, such as [[0987654321raboof]] and submit

What happens?:

  • No error is thrown, so a redirect is created to a non-existent page.

What should have happened instead?:

  • An error should have been thrown instead, to prevent creation of a broken redirect to non-existent page (red link).

Tested and confirmed

This has been checked.

Notes

Fix includes / editpage / Constraint / BrokenRedirectConstraint.php

The key condition in checkConstraint() is:

	public function checkConstraint(): string {
		if ( !$this->allowBrokenRedirects ) {
			$newRedirectTarget = $this->newContent->getRedirectTarget();

			if ( $newRedirectTarget !== null && !$newRedirectTarget->isKnown() &&
				!$newRedirectTarget->equals( $this->title ) ) {
				$currentTarget = $this->originalContent->getRedirectTarget();

				// fail if there was no previous content or the previous content contained
				// a redirect to a known page
				if ( !$currentTarget || $currentTarget->isKnown() ) {
					$this->result = self::CONSTRAINT_FAILED;

					return self::CONSTRAINT_FAILED;
				}
			}

		}
		$this->result = self::CONSTRAINT_PASSED;

		return self::CONSTRAINT_PASSED;
	}
}

Event Timeline

Change #1153939 had a related patch set uploaded (by Gerrit Patch Uploader; author: Finchgold):

[mediawiki/core@master] Fixes T395767 BrokenRedirectConstraint allows changing broken redirect target to another non-existent page without error

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

Change #1153939 had a related patch set uploaded (by Pppery; author: Finchgold):

[mediawiki/core@master] BrokenRedirectConstraint: show error when changing from one non-existent page to another non-existent page

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

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

[mediawiki/core@master] BrokenRedirectConstraint: fail if broken target changed between save attempts

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

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

[mediawiki/core@master] BrokenRedirectConstraint: fail if broken target changed between save attempts

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

Testing this patch:

Changing the target between revisions

  1. Create a broken redirect and bypass the warning by clicking save twice
  2. Edit the broken redirect and change the target to another non-existent page
  3. Save the page

Expected: A warning is shown

Changing the target between save attempts

  1. Try to create a broken redirect
  2. After the warning appears, change the target to another non-existent page
  3. Save the page

Expected: A warning is shown

No warning was shown for both of theses cases before.

Change #1153939 abandoned by Bartosz Dziewoński:

[mediawiki/core@master] BrokenRedirectConstraint: show error when changing from one non-existent page to another non-existent page

Reason:

Superseded by https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1175259

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

Change #1175259 merged by jenkins-bot:

[mediawiki/core@master] BrokenRedirectConstraint: fail if target changed but redirect is still broken

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