Wctaiwan has uploaded a new change for review. https://gerrit.wikimedia.org/r/237988
Change subject: [WIP] Handle revisions with different content models in EditPage ...................................................................... [WIP] Handle revisions with different content models in EditPage Disable editing and serialize using the default format if the revision has a different content model from the current one. Bug: T73163 Change-Id: If28de7a3612d414a4366e3d493598244c0754b90 --- M includes/EditPage.php M languages/i18n/en.json M languages/i18n/qqq.json 3 files changed, 36 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/88/237988/1 diff --git a/includes/EditPage.php b/includes/EditPage.php index 05e0ac0..66fda60 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -537,6 +537,15 @@ return; } + $revision = $this->mArticle->getRevisionFetched(); + if ( $revision && $revision->getContentModel() !== $this->contentModel ) { + $this->displayViewSourcePage( + $this->getContentObject(), + wfMessage( 'contentmodelediterror' )->plain() + ); + return; + } + $this->isConflict = false; // css / js subpages of user pages get a special treatment $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage(); @@ -647,6 +656,20 @@ throw new PermissionsError( $action, $permErrors ); } + $this->displayViewSourcePage( + $content, + $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) + ); + } + + /** + * Display a read-only View Source page + * @param Content $content content object + * @param $errorMessage additional error message to display + */ + protected function displayViewSourcePage( Content $content, $errorMessage = '' ) { + global $wgOut; + Hooks::run( 'EditPage::showReadOnlyForm:initial', array( $this, &$wgOut ) ); $wgOut->setRobotPolicy( 'noindex,nofollow' ); @@ -658,8 +681,10 @@ $wgOut->addHTML( $this->editFormPageTop ); $wgOut->addHTML( $this->editFormTextTop ); - $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) ); - $wgOut->addHTML( "<hr />\n" ); + if ( $errorMessage !== '' ) { + $wgOut->addWikiText( $errorMessage ); + $wgOut->addHTML( "<hr />\n" ); + } # If the user made changes, preserve them when showing the markup # (This happens when a user is blocked during edit, for instance) @@ -667,7 +692,13 @@ $text = $this->textbox1; $wgOut->addWikiMsg( 'viewyourtext' ); } else { - $text = $this->toEditText( $content ); + try { + $text = $this->toEditText( $content ); + } catch ( MWException $e ) { + # Serialize using the default format if the content model is not supported + # (e.g. for an old revision with a different model) + $text = $content->serialize(); + } $wgOut->addWikiMsg( 'viewsourcetext' ); } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 5859365..6704afb 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -689,6 +689,7 @@ "permissionserrors": "Permission error", "permissionserrorstext": "You do not have permission to do that, for the following {{PLURAL:$1|reason|reasons}}:", "permissionserrorstext-withaction": "You do not have permission to $2, for the following {{PLURAL:$1|reason|reasons}}:", + "contentmodelediterror": "You cannot edit this revision because it has a content model different from that of the current revision.", "recreate-moveddeleted-warn": "<strong>Warning: You are recreating a page that was previously deleted.</strong>\n\nYou should consider whether it is appropriate to continue editing this page.\nThe deletion and move log for this page are provided here for convenience:", "moveddeleted-notice": "This page has been deleted.\nThe deletion and move log for the page are provided below for reference.", "log-fulllog": "View full log", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index d3b5a99..3652df8 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -862,6 +862,7 @@ "permissionserrors": "Used as title of error message.\n\nSee also:\n* {{msg-mw|loginreqtitle}}\n{{Identical|Permission error}}", "permissionserrorstext": "This message is \"without action\" version of {{msg-mw|Permissionserrorstext-withaction}}.\n\nParameters:\n* $1 - the number of reasons that were found why ''the action'' cannot be performed", "permissionserrorstext-withaction": "This message is \"with action\" version of {{msg-mw|Permissionserrorstext}}.\n\nParameters:\n* $1 - the number of reasons that were found why the action cannot be performed\n* $2 - one of the action-* messages (for example {{msg-mw|action-edit}}) or other such messages tagged with {{tl|doc-action}} in their documentation\n\nPlease report at [[Support]] if you are unable to properly translate this message. Also see [[phab:T16246]] (now closed) for background.", + "contentmodelediterror": "Error message shown when trying to edit an old revision with a content model different from that of the current revision", "recreate-moveddeleted-warn": "Warning shown when creating a page which has already been deleted. See for example [[Test]].", "moveddeleted-notice": "Shown on top of a deleted page in normal view modus ([{{canonicalurl:Test}} example]).", "log-fulllog": "Used as link text.", -- To view, visit https://gerrit.wikimedia.org/r/237988 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If28de7a3612d414a4366e3d493598244c0754b90 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Wctaiwan <wctai...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits