jenkins-bot has submitted this change and it was merged.
Change subject: Handle revisions with different content models in EditPage
......................................................................
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, 41 insertions(+), 3 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
Siebrand: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/includes/EditPage.php b/includes/EditPage.php
index 8571cd7..81f35f9 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -537,6 +537,20 @@
return;
}
+ $revision = $this->mArticle->getRevisionFetched();
+ // Disallow editing revisions with content models different
from the current one
+ if ( $revision && $revision->getContentModel() !==
$this->contentModel ) {
+ $this->displayViewSourcePage(
+ $this->getContentObject(),
+ wfMessage(
+ 'contentmodelediterror',
+ $revision->getContentModel(),
+ $this->contentModel
+ )->plain()
+ );
+ return;
+ }
+
$this->isConflict = false;
// css / js subpages of user pages get a special treatment
$this->isCssJsSubpage = $this->mTitle->isCssJsSubpage();
@@ -647,6 +661,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 string $errorMessage additional wikitext 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 +686,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 +697,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 8f4ef96..e2440fe 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -692,6 +692,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 its
content model is <code>$1</code>, but the current content model of the page is
<code>$2</code>.",
"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.",
"moveddeleted-notice-recent": "Sorry, this page was recently deleted
(within the last 24 hours).\nThe deletion and move log for the page are
provided below for reference.",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index 95bd205..6a11080 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -865,6 +865,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\n* $1 - content model of the old revision\n* $2 - content model 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]).",
"moveddeleted-notice-recent": "Shown on top of a recently deleted page
in normal view modus ([{{canonicalurl:Test}} example]).",
--
To view, visit https://gerrit.wikimedia.org/r/237988
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If28de7a3612d414a4366e3d493598244c0754b90
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Wctaiwan <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tpt <[email protected]>
Gerrit-Reviewer: Wctaiwan <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits