(bug 42787) Make import robust against corrupt content.
authordaniel <daniel.kinzler@wikimedia.de>
Wed, 12 Dec 2012 11:47:40 +0000 (12:47 +0100)
committerdaniel <daniel.kinzler@wikimedia.de>
Wed, 12 Dec 2012 11:47:40 +0000 (12:47 +0100)
This catches serialization exceptions caused by corrupt or mis-reported
non-text content.

Change-Id: I28ef70f716b1aade1b837ca480c49b1826fa9e26

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

index 2017466..bd9ce25 100644 (file)
@@ -252,8 +252,16 @@ class WikiImporter {
         * @return bool
         */
        public function importRevision( $revision ) {
-               $dbw = wfGetDB( DB_MASTER );
-               return $dbw->deadlockLoop( array( $revision, 'importOldRevision' ) );
+               try {
+                       $dbw = wfGetDB( DB_MASTER );
+                       return $dbw->deadlockLoop( array( $revision, 'importOldRevision' ) );
+               } catch ( MWContentSerializationException $ex ) {
+                       $this->notice( 'import-error-unserialize',
+                               $revision->getTitle()->getPrefixedText(),
+                               $revision->getID(),
+                               $revision->getModel(),
+                               $revision->getFormat() );
+               }
        }
 
        /**
index cd3ef1a..124ce9c 100644 (file)
@@ -3524,6 +3524,7 @@ Please try again.',
 'import-error-interwiki'     => 'Page "$1" is not imported because its name is reserved for external linking (interwiki).',
 'import-error-special'       => 'Page "$1" is not imported because it belongs to a special namespace that does not allow pages.',
 'import-error-invalid'       => 'Page "$1" is not imported because its name is invalid.',
+'import-error-unserialize'   => 'Revision $2 of page "$1" could not be unserialized. The revision was reported to use content model $3 serialized as $4.',
 'import-options-wrong'       => 'Wrong {{PLURAL:$2|option|options}}: <nowiki>$1</nowiki>',
 'import-rootpage-invalid'    => 'Given root page is an invalid title.',
 'import-rootpage-nosubpage'  => 'Namespace "$1" of the root page does not allow subpages.',
index c8428d6..d2730fe 100644 (file)
@@ -3421,6 +3421,12 @@ See also:
 * $1 is a page name.
 See also:
 * {{msg-mw|import-error-edit}}',
+'import-error-unserialize'   => 'Import error message displayed when a revision could not be unserialized.
+This may happen if the content got corrupted or the serialization format is mis-reported. Parameters:
+* $1 is the name of the page the offending revision belongs to.
+* $2 is the ID of the offending revision, as reported in the dump that is being imported.
+* $3 is the content model reported for the offending revision in the dump that is being imported.
+* $4 is the serialization format reported for the offending revision in the dump that is being imported.',
 'import-options-wrong' => 'Used on [[Special:Import]], when one of the options has an error.',
 'import-rootpage-invalid' => 'Used on [[Special:Import]], when the root page is invalid.',
 'import-rootpage-nosubpage' => 'Used on [[Special:Import]], when the import namespace does not support subpages. Parameters: