Page MenuHomePhabricator

Check edit constraints on page preview
Open, Needs TriagePublicFeature

Description

Feature summary
Since T326056: Show a warning on creating double redirect was resolved, when creating a double redirect, you are shown a warning when clicking publish. It would be useful if this same warning was also shown when previewing.

In fact, it would be useful if all relevant constraints were checked when previewing.

Some constraints are ⛔critical, because you can't save a page if a constraint is violated. Others are merely ⚠️advisory because they can display a warning that can be overridden.

Some of these constraints are not mutually exclusive, meaning that more than one constraint might be triggered by a particularly non-compliant page. If more than one constraint is violated, the response should note this. Critical constraints should also be prioritised over advisory constraints.

We think that the spam blacklist from Extension:SpamBlackList will also run if the "vanilla" spam checklist is also checked.

See also T396437: Edit constraints not checked when converting content model to wikitext, and T19467: Edit conflict notification on Preview/Show Changes (check for edit conflicts).

Notes
Edit constraints are located in includes / editpage / Constraint:

Constraint NameSummary⚠️Advisory/⛔Critical?Should be checked on preview?Status
AccidentalRecreationConstraint.phpMake sure user doesn't accidentally recreate a page deleted after they started editing.⚠️Advisory except if the user lacks the userrights required to create pages in that namespace, which makes it ⛔Critical.✅Yes - good idea
AuthorizationConstraint.phpVerify authorization to edit the page (user rights, rate limits, blocks).⛔Critical❓Yes? But maybe not the rate limits though? If user is blocked, do they get another message?
ChangeTagsConstraint.phpVerify user can add change tags.⛔Critical?❓Yes?
ContentModelChangeConstraint.phpVerify user permissions if changing content model.⛔Critical?❓Maybe? Is this even possible with preview?
DefaultTextConstraint.phpDon't save a new page if it's blank or if it's a MediaWiki: message with content equivalent to default.⚠️Advisory✅Yes - good idea
EditFilterMergedContentHookConstraint.phpVerify EditFilterMergedContent hook.❓Unclear❓Maybe? What does this do?
ExistingSectionEditConstraint.phpFor existing-section edits, disallow certain auto summaries (which?) under specific conditions (which?).⚠️Advisory?✅Yes, probably
ImageRedirectConstraint.phpVerify user permissions: If creating a redirect in the file namespace, must have upload rights.⛔Critical✅Yes - good idea
LinkPurgeRateLimitConstraint.phpVerify that the user doesn't exceed linkpurge limits, which are unusual and special.⛔Critical?❓No?
MissingCommentConstraint.phpDo not allow the user to post an empty comment (only used for new section).⚠️Advisory?✅Yes - good idea
NewSectionMissingSubjectConstraint.phpFor a new section, do not allow the user to post with an empty subject (section title) unless they explicitly choose to.⚠️Advisory?✅Yes - good idea
PageSizeConstraint.phpVerify the page isn't larger than the maximum allowed size.⛔Critical✅Yes - good idea
ReadOnlyConstraint.phpVerify the site is not in read-only mode.⛔Critical❓Maybe? Is another sitewide warning given?
RedirectConstraint.phpVerify the page does not redirect to problematic or invalid targets.⚠️Advisory✅Yes - good idea✅Patched
SimpleAntiSpamConstraint.phpVerify simple anti-spam measure using an extra hidden text field.⛔Critical❓Maybe not? Does this need to be?
SpamRegexConstraint.phpVerify summary and text do not match spam regexes.⛔Critical✅Yes - good idea
UnicodeConstraint.phpVerify Unicode constraint (that the text is valid Unicode).⛔Critical✅Yes - good idea

But note the following are utility and interface files (not actual constraints):

File NameSummaryRole / PurposeStatus
EditConstraintFactory.phpConstructs and initializes constraint objects based on context.Factory / BuilderCore utility
EditConstraintRunner.phpHandles execution and aggregation of all edit constraints.Execution ManagerCore utility
IEditConstraint.phpDefines the interface that all constraints must implement.Interface DefinitionInterface

Event Timeline

The warning is created due to an edit constraint (DoubleRedirectConstraint) failing, and as far as I am aware, edit constraints are only checked when a page is saved (internalAttemptSave). So an implementation for this would probably involve rewriting parts of EditPage so edit constraints are checked when a preview is being shown. Then, other constraints could/should probably be checked as well.

It would make sense if the edit was checked for everything else that can (and does) go wrong at the same time as well, such as spam links.

Bugreporter2 renamed this task from Show warning about creating a double redirect also on preview to Check edit constraints on page preview.May 28 2025, 7:27 AM
Bugreporter2 updated the task description. (Show Details)

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

[mediawiki/core@master] EditPage: check RedirectConstraint on preview

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

The patch I uploaded implements this for RedirectConstraint (as a proof of concept, and to keep the patch small; more constraints can be added in follow-ups).

image.png (262×971 px, 29 KB)

image.png (341×987 px, 38 KB)

Test wiki created on Patch demo by SomeRandomDeveloper using patch(es) linked to this task:
https://a83780d28d.catalyst.wmcloud.org/w/

Thanks for looking at this @SomeRandomDeveloper!

Good idea to break it down. Some of the constraints may need tweaking to get them to work with preview. Might it be a good idea to create subtasks?

Good idea to break it down. Some of the constraints may need tweaking to get them to work with preview. Might it be a good idea to create subtasks?

I think that would be overkill. I would rather spend time on writing the actual patches than on creating more tasks.

Good idea to break it down. Some of the constraints may need tweaking to get them to work with preview. Might it be a good idea to create subtasks?

I think that would be overkill. I would rather spend time on writing the actual patches than on creating more tasks.

OK. I've added to the table above to try to keep track of things.

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

[mediawiki/core@master] Display the preview note as a notice instead of a warning

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

Change #1225122 merged by jenkins-bot:

[mediawiki/core@master] editpage: Check RedirectConstraint on preview

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

Test wiki on Patch demo by SomeRandomDeveloper using patch(es) linked to this task was deleted:

https://a83780d28d.catalyst.wmcloud.org/w/

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

[mediawiki/core@master] editpage: Use StatusValue for preview warnings and errors

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

Untagging SpamBlacklist because that extension seems to rely on hooks that are run in an edit constraint (EditFilterMergedContentHookConstraint) and in EditPage, so it's likely no change to the extension is necessary.

Change #1227448 merged by jenkins-bot:

[mediawiki/core@master] editpage: Display the preview note as a notice instead of a warning

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

Change #1228256 merged by jenkins-bot:

[mediawiki/core@master] editpage: Use StatusValue for preview warnings and errors

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