From ed8ef675aa0ab5aa91c2d4deb15221f0b98a4236 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Fri, 19 Jun 2015 21:32:30 -0700 Subject: [PATCH] EditPage: Check $wgContentHandlerUseDB Reject any edits that attempt to change the content model of a page if $wgContentHandlerUseDB is false. Change-Id: Ic2e0ed8f74c3a54864793a457a452f72fe637f73 --- includes/EditPage.php | 22 +++++++++++++++++----- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 4e470e9300..3600fb221a 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -167,6 +167,12 @@ class EditPage { */ const AS_PARSE_ERROR = 240; + /** + * Status: when changing the content model is disallowed due to + * $wgContentHandlerUseDB being false + */ + const AS_CANNOT_USE_CUSTOM_MODEL = 241; + /** * HTML id and name for the beginning of the edit form. */ @@ -1361,6 +1367,7 @@ class EditPage { case self::AS_HOOK_ERROR: return false; + case self::AS_CANNOT_USE_CUSTOM_MODEL: case self::AS_PARSE_ERROR: $wgOut->addWikiText( '
' . $status->getWikiText() . '
' ); return true; @@ -1543,6 +1550,7 @@ class EditPage { */ function internalAttemptSave( &$result, $bot = false ) { global $wgUser, $wgRequest, $wgParser, $wgMaxArticleSize; + global $wgContentHandlerUseDB; $status = Status::newGood(); @@ -1663,11 +1671,15 @@ class EditPage { } } - if ( $this->contentModel !== $this->mTitle->getContentModel() - && !$wgUser->isAllowed( 'editcontentmodel' ) - ) { - $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL ); - return $status; + if ( $this->contentModel !== $this->mTitle->getContentModel() ) { + if ( !$wgContentHandlerUseDB ) { + $status->fatal( 'editpage-cannot-use-custom-model' ); + $status->value = self::AS_CANNOT_USE_CUSTOM_MODEL; + return $status; + } elseif ( !$wgUser->isAllowed( 'editcontentmodel' ) ) { + $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL ); + return $status; + } } if ( $this->changeTags ) { diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 7bcf987bb2..2518295459 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -667,6 +667,7 @@ "copyrightwarning2": "Please note that all contributions to {{SITENAME}} may be edited, altered, or removed by other contributors.\nIf you do not want your writing to be edited mercilessly, then do not submit it here.
\nYou are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see $1 for details).\nDo not submit copyrighted work without permission!", "editpage-head-copy-warn": "-", "editpage-tos-summary": "-", + "editpage-cannot-use-custom-model": "The content model of this page cannot be changed.", "longpage-hint": "-", "longpageerror": "Error: The text you have submitted is {{PLURAL:$1|one kilobyte|$1 kilobytes}} long, which is longer than the maximum of {{PLURAL:$2|one kilobyte|$2 kilobytes}}.\nIt cannot be saved.", "readonlywarning": "Warning: The database has been locked for maintenance, so you will not be able to save your edits right now.\nYou may wish to copy and paste your text into a text file and save it for later.\n\nThe administrator who locked it offered this explanation: $1", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 1035d7b65e..a7c04ec3c1 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -837,6 +837,7 @@ "copyrightwarning2": "Copyright warning displayed under the edit box in editor\n*$1 - license name", "editpage-head-copy-warn": "{{ignored}}Custom copyright warning in the header of an edit page.", "editpage-tos-summary": "{{notranslate}}", + "editpage-cannot-use-custom-model": "Error message shown if the database does not support changing the content model of a page.", "longpage-hint": "{{notranslate}}\n* $1: Size of the textbox formatted for output, using an appropriate unit ({{msg-mw|size-bytes}}, {{msg-mw|size-kilobytes}}, {{msg-mw|size-megabytes}}, {{msg-mw|size-gigabytes}})\n* $2: Size of the textbox in bytes, not formatnum", "longpageerror": "Warning displayed when trying to save a text larger than the maximum size allowed.\n\nParameters:\n* $1 - submitted size (in kilobytes)\n* $2 - maximum size (in kilobytes)", "readonlywarning": "Parameters:\n* $1 - reason", -- 2.20.1