Prevent page moved to different content model.
authordaniel <daniel.kinzler@wikimedia.de>
Fri, 5 Oct 2012 14:08:07 +0000 (16:08 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Fri, 5 Oct 2012 14:08:07 +0000 (16:08 +0200)
Pages should never be moved in a way that would change their content model.
Without this explicite check, that might happen when $wgContentHandlerUseDB
is disabled.

Change-Id: Id1a101f56bee6f13a7259d34019c587e75a4c182

includes/Title.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php

index affffc3..f2531a2 100644 (file)
@@ -3375,7 +3375,7 @@ class Title {
         * @return Mixed True on success, getUserPermissionsErrors()-like array on failure
         */
        public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
-               global $wgUser;
+               global $wgUser, $wgContentHandlerUseDB;
 
                $errors = array();
                if ( !$nt ) {
@@ -3408,6 +3408,15 @@ class Title {
                        $errors[] = array( 'badarticleerror' );
                }
 
+               // Content model checks
+               if ( !$wgContentHandlerUseDB &&
+                               $this->getContentModel() !== $nt->getContentModel() ) {
+                       // can't move a page if that would change the page's content model
+                       $errors[] = array( 'bad-target-model',
+                                                       ContentHandler::getLocalizedName( $this->getContentModel() ),
+                                                       ContentHandler::getLocalizedName( $nt->getContentModel() ) );
+               }
+
                // Image-specific checks
                if ( $this->getNamespace() == NS_FILE ) {
                        $errors = array_merge( $errors, $this->validateFileMoveOperation( $nt ) );
index e96418d..b25d0a5 100644 (file)
@@ -3396,6 +3396,7 @@ cannot move a page over itself.',
 'immobile-target-namespace-iw' => 'Interwiki link is not a valid target for page move.',
 'immobile-source-page'         => 'This page is not movable.',
 'immobile-target-page'         => 'Cannot move to that destination title.',
+'bad-target-model'             => 'The desired destination uses a different content model. Can not convert from $1 to $2.',
 'imagenocrossnamespace'        => 'Cannot move file to non-file namespace',
 'nonfile-cannot-move-to-file'  => 'Cannot move non-file to file namespace',
 'imagetypemismatch'            => 'The new file extension does not match its type',
index a1e4a73..643f6f9 100644 (file)
@@ -3191,6 +3191,10 @@ Parameters:
 'immobile-target-namespace-iw' => "This message appears when attempting to move a page, if a person has typed an interwiki link as a namespace prefix in the input box labelled 'To new title'.  The special page 'Movepage' cannot be used to move a page to another wiki.
 
 'Destination' can be used instead of 'target' in this message.",
+'bad-target-model'             => "This message is shown when attempting to move a page, but the move would change the page's content model.
+This may be the case when \$wgContentHandlerUseDB is set to false, because then a page's content model is derived from the page's title.
+* $1: The localized name of the original page's content model.
+* $2: The localized name of the content model used by the destination title.",
 'fix-double-redirects' => 'This is a checkbox in [[Special:MovePage]] which allows to move all redirects from the old title to the new title.',
 'protectedpagemovewarning' => 'Related message: [[MediaWiki:protectedpagewarning/{{#titleparts:{{PAGENAME}}|1|2}}]]
 {{Related|Semiprotectedpagewarning}}',