From eb5d3a83a73d175ab36d515acc0ffc02e208c34c Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 23 Apr 2012 11:31:13 +0200 Subject: [PATCH] preserve content model and format in xml dump, use in import --- includes/Export.php | 8 ++++++++ includes/Import.php | 48 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/includes/Export.php b/includes/Export.php index 73b07c3556..f98da1df7b 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -594,6 +594,14 @@ class XmlDumpWriter { $out .= " " . Xml::elementClean( 'comment', null, strval( $row->rev_comment ) ) . "\n"; } + if ( $row->rev_content_model ) { + $out .= " " . Xml::element('model', null, strval( $row->rev_content_model ) ) . "\n"; + } + + if ( $row->rev_content_format ) { + $out .= " " . Xml::element('format', null, strval( $row->rev_content_format ) ) . "\n"; + } + $text = ''; if ( $row->rev_deleted & Revision::DELETED_TEXT ) { $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n"; diff --git a/includes/Import.php b/includes/Import.php index 9ebc34c91b..e8f32d794d 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -578,7 +578,7 @@ class WikiImporter { $this->debug( "Enter revision handler" ); $revisionInfo = array(); - $normalFields = array( 'id', 'timestamp', 'comment', 'minor', 'text' ); + $normalFields = array( 'id', 'timestamp', 'comment', 'minor', 'model', 'format', 'text' ); $skip = false; @@ -623,6 +623,12 @@ class WikiImporter { if ( isset( $revisionInfo['text'] ) ) { $revision->setText( $revisionInfo['text'] ); } + if ( isset( $revisionInfo['model'] ) ) { + $revision->setModel( $revisionInfo['model'] ); + } + if ( isset( $revisionInfo['text'] ) ) { + $revision->setFormat( $revisionInfo['format'] ); + } $revision->setTitle( $pageInfo['_title'] ); if ( isset( $revisionInfo['timestamp'] ) ) { @@ -972,6 +978,8 @@ class WikiRevision { var $timestamp = "20010115000000"; var $user = 0; var $user_text = ""; + var $model = null; + var $format = null; var $text = ""; var $comment = ""; var $minor = false; @@ -1028,6 +1036,20 @@ class WikiRevision { $this->user_text = $ip; } + /** + * @param $model + */ + function setModel( $model ) { + $this->model = $model; + } + + /** + * @param $format + */ + function setFormat( $format ) { + $this->format = $format; + } + /** * @param $text */ @@ -1156,6 +1178,28 @@ class WikiRevision { return $this->text; } + /** + * @return string + */ + function getModel() { + if ( is_null( $this->model ) ) { + $this->model = $this->getTitle()->getContentModelName(); + } + + return $this->model; + } + + /** + * @return string + */ + function getFormat() { + if ( is_null( $this->model ) ) { + $this->format = ContentHandler::getForTitle( $this->getTitle() )->getDefaultFormat(); + } + + return $this->format; + } + /** * @return string */ @@ -1295,6 +1339,8 @@ class WikiRevision { # Insert the row $revision = new Revision( array( 'page' => $pageId, + 'content_model' => $this->getModel(), + 'content_format' => $this->getFormat(), 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, -- 2.20.1