EditPage: Check $wgContentHandlerUseDB
authorKunal Mehta <legoktm@gmail.com>
Sat, 20 Jun 2015 04:32:30 +0000 (21:32 -0700)
committerKunal Mehta <legoktm@gmail.com>
Mon, 22 Jun 2015 16:51:52 +0000 (09:51 -0700)
Reject any edits that attempt to change the content model of a page if
$wgContentHandlerUseDB is false.

Change-Id: Ic2e0ed8f74c3a54864793a457a452f72fe637f73

includes/EditPage.php
languages/i18n/en.json
languages/i18n/qqq.json

index 4e470e9..3600fb2 100644 (file)
@@ -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( '<div class="error">' . $status->getWikiText() . '</div>' );
                                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 ) {
index 7bcf987..2518295 100644 (file)
        "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.<br />\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).\n<strong>Do not submit copyrighted work without permission!</strong>",
        "editpage-head-copy-warn": "-",
        "editpage-tos-summary": "-",
+       "editpage-cannot-use-custom-model": "The content model of this page cannot be changed.",
        "longpage-hint": "-",
        "longpageerror": "<strong>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}}.</strong>\nIt cannot be saved.",
        "readonlywarning": "<strong>Warning: The database has been locked for maintenance, so you will not be able to save your edits right now.</strong>\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",
index 1035d7b..a7c04ec 100644 (file)
        "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* <tt>$1</tt>: 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* <tt>$2</tt>: 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",