preserve content model and format in xml dump, use in import
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 23 Apr 2012 09:31:13 +0000 (11:31 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 23 Apr 2012 09:31:13 +0000 (11:31 +0200)
includes/Export.php
includes/Import.php

index 73b07c3..f98da1d 100644 (file)
@@ -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";
index 9ebc34c..e8f32d7 100644 (file)
@@ -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,