From d1cf0443290224491587de8897032a085973b17b Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 12 Dec 2012 12:47:40 +0100 Subject: [PATCH] (bug 42787) Make import robust against corrupt content. This catches serialization exceptions caused by corrupt or mis-reported non-text content. Change-Id: I28ef70f716b1aade1b837ca480c49b1826fa9e26 --- includes/Import.php | 12 ++++++++++-- languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 6 ++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/includes/Import.php b/includes/Import.php index 201746661b..bd9ce25cbc 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -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() ); + } } /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index cd3ef1abea..124ce9c1d5 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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}}: $1', 'import-rootpage-invalid' => 'Given root page is an invalid title.', 'import-rootpage-nosubpage' => 'Namespace "$1" of the root page does not allow subpages.', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index c8428d6e7f..d2730fe915 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -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: -- 2.20.1