Page MenuHomePhabricator

There should be a way to reliably validate a JSON content + title combination
Closed, ResolvedPublic

Description

Often, we want to validate a JSON content (or, in the MCR world, slot) object in a way that depends on the title. A common example is MediaWiki:*.json confiugration pages - there are usually some validity criteria for a config page beyond just being valid JSON, we want to prevent users from accidentally breaking the config page, but we don't want to define a separate content type for every configuration page so we'll have to check the page title and invoke the validation logic based on that.

Currently, there are two mechanisms in MediaWiki for validating page content

  • EditFilterMergedContent, which runs when a page is saved via the edit page or the edit form. The problem with it is that there are many ways for a sufficiently privileged user to change a page without making an edit (page move with "delete target" flag, revert/restore, import etc.) so it isn't really reliable.
  • ContentHandler::validateSave() / Content::isValid(), but those can only be changed by defining a new content type, which is cumbersome both for the developer and for the user. (Also, Content::isValid() does not have access to the page identity, although ContentHandler::validateSave() does.)

It would be good to have a mechanism that works like ContentHandler::validateSave() but can be hooked into. Maybe just add a new hook to JsonContentHandler::validateSave()? Not sure how much use case there is for this kind of thing for other content types.

Details

Event Timeline

Tgr renamed this task from There should be a way to reliably validate a content + title combination to There should be a way to reliably validate a JSON content + title combination.Jul 18 2022, 6:29 PM
Tgr updated the task description. (Show Details)

Change 822733 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/core@master] Customise error message for invalid JSON, add hook

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

Tgr assigned this task to SD0001.

Thank you @SD0001!

Change 822733 merged by jenkins-bot:

[mediawiki/core@master] Customise error message for invalid JSON, add hook

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