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.