tl,dr: Remove the ability of EditPage::getCurrentContent to change other stuff unexpectedly and function only as a getter
Will working through the EditPage class for T157658: Factor out a backend from EditPage / T20654: EditPage.php needs rewrite: Separate DB and UI logic, I discovered that calling EditPage::getCurrentContent from within the class (i.e. $this->getCurrentContent()) does more than documented:
/** * Get the current content of the page. This is basically similar to * WikiPage::getContent( Revision::RAW ) except that when the page doesn't exist an empty * content object is returned instead of null. * * @since 1.21 * @return Content */
Thus, calling it at the wrong time can break things.
History:
The overwriting was added by @daniel in 2012 in [1] as part of reworking EditPage to use the content object - work in horrible progress. At the time, it included a comment #FIXME: nasty side-effect! A few months later, in [2] the comment was changed to # nasty side-effect, but needed for consistency, which is how it remained until T139249 replaced it with Content models should always be the same since we error out if they are different before this point. (the current comment)
[1] https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/c6eaef668133657fa1dc06b33643e2eed5a8a3aa%5E%21/#F2
[2] https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/a1f145591b343f8e278603de84fc0f926960cf28%5E%21/#F0
Prior tasks:
In T139249: Show changes button on edit page does not work when using a non-default format with a content model that supports multiple formats, logging was added whenever the content model and format were being overwritten
In T145044: Clicking undo on an edit that changed the content model results in a MWException, undoes were exempted from the model and format being overwritten
Currently, when these overwrites occur, debug logs are created in the editpage channel. Are there any recent entries of Overriding content model from current edit ... or Current revision content format unsupported. Overriding ...? If not, I propose that the overwriting be removed. According to the inline comment, the content model (and format) should already be the same when they need to be.