merged master
[lhc/web/wiklou.git] / includes / Export.php
index 6c47e34..f2b7e11 100644 (file)
@@ -58,6 +58,14 @@ class WikiExporter {
         */
        var $sink;
 
+       /**
+        * Returns the export schema version.
+        * @return string
+        */
+       public static function schemaVersion() {
+               return "0.7"; #FIXME: bump this when pushing ContentHandler additions.
+       }
+
        /**
         * If using WikiExporter::STREAM to stream a large amount of data,
         * provide a database connection which is not managed by
@@ -465,14 +473,16 @@ class WikiExporter {
 class XmlDumpWriter {
        /**
         * Returns the export schema version.
+        * @deprecated in 1.20; use WikiExporter::schemaVersion() instead
         * @return string
         */
        function schemaVersion() {
-               return "0.7";
+               wfDeprecated( __METHOD__, '1.20' );
+               return WikiExporter::schemaVersion();
        }
 
        /**
-        * Opens the XML output stream's root <mediawiki> element.
+        * Opens the XML output stream's root "<mediawiki>" element.
         * This does not include an xml directive, so is safe to include
         * as a subelement in a larger XML stream. Namespace and XML Schema
         * references are included.
@@ -483,12 +493,12 @@ class XmlDumpWriter {
         */
        function openStream() {
                global $wgLanguageCode;
-               $ver = $this->schemaVersion();
+               $ver = WikiExporter::schemaVersion();
                return Xml::element( 'mediawiki', array(
                        'xmlns'              => "http://www.mediawiki.org/xml/export-$ver/",
                        'xmlns:xsi'          => "http://www.w3.org/2001/XMLSchema-instance",
                        'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
-                                               "http://www.mediawiki.org/xml/export-$ver.xsd",
+                                               "http://www.mediawiki.org/xml/export-$ver.xsd", #TODO: how do we get a new version up there?
                        'version'            => $ver,
                        'xml:lang'           => $wgLanguageCode ),
                        null ) .
@@ -572,7 +582,7 @@ class XmlDumpWriter {
        }
 
        /**
-        * Opens a <page> section on the output stream, with data
+        * Opens a "<page>" section on the output stream, with data
         * from the given database row.
         *
         * @param $row object
@@ -604,7 +614,7 @@ class XmlDumpWriter {
        }
 
        /**
-        * Closes a <page> section on the output stream.
+        * Closes a "<page>" section on the output stream.
         *
         * @access private
         * @return string
@@ -614,7 +624,7 @@ class XmlDumpWriter {
        }
 
        /**
-        * Dumps a <revision> section on the output stream, with
+        * Dumps a "<revision>" section on the output stream, with
         * data filled in from the given database row.
         *
         * @param $row object
@@ -626,6 +636,9 @@ class XmlDumpWriter {
 
                $out  = "    <revision>\n";
                $out .= "      " . Xml::element( 'id', null, strval( $row->rev_id ) ) . "\n";
+               if( $row->rev_parent_id ) {
+                       $out .= "      " . Xml::element( 'parentid', null, strval( $row->rev_parent_id ) ) . "\n";
+               }
 
                $out .= $this->writeTimestamp( $row->rev_timestamp );
 
@@ -644,12 +657,6 @@ class XmlDumpWriter {
                        $out .= "      " . Xml::elementClean( 'comment', array(), strval( $row->rev_comment ) ) . "\n";
                }
 
-               if ( $row->rev_sha1 && !( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
-                       $out .= "      " . Xml::element('sha1', null, strval( $row->rev_sha1 ) ) . "\n";
-               } else {
-                       $out .= "      <sha1/>\n";
-               }
-
                $text = '';
                if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
                        $out .= "      " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
@@ -666,6 +673,34 @@ class XmlDumpWriter {
                                "" ) . "\n";
                }
 
+               if ( $row->rev_sha1 && !( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
+                       $out .= "      " . Xml::element('sha1', null, strval( $row->rev_sha1 ) ) . "\n";
+               } else {
+                       $out .= "      <sha1/>\n";
+               }
+
+               if ( isset( $row->rev_content_model ) && !is_null( $row->rev_content_model )  ) {
+                       $content_model = strval( $row->rev_content_model );
+               } else {
+                       // probably using $wgContentHandlerUseDB = false;
+                       // @todo: test!
+                       $title = Title::makeTitle( $row->page_namespace, $row->page_title );
+                       $content_model = ContentHandler::getDefaultModelFor( $title );
+               }
+
+               $out .= "      " . Xml::element('model', null, strval( $content_model ) ) . "\n";
+
+               if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) {
+                       $content_format = strval( $row->rev_content_format );
+               } else {
+                       // probably using $wgContentHandlerUseDB = false;
+                       // @todo: test!
+                       $content_handler = ContentHandler::getForModelID( $content_model );
+                       $content_format = $content_handler->getDefaultFormat();
+               }
+
+               $out .= "      " . Xml::element('format', null, strval( $content_format ) ) . "\n";
+
                wfRunHooks( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
 
                $out .= "    </revision>\n";
@@ -675,7 +710,7 @@ class XmlDumpWriter {
        }
 
        /**
-        * Dumps a <logitem> section on the output stream, with
+        * Dumps a "<logitem>" section on the output stream, with
         * data filled in from the given database row.
         *
         * @param $row object
@@ -723,6 +758,7 @@ class XmlDumpWriter {
 
        /**
         * @param $timestamp string
+        * @param $indent string Default to six spaces
         * @return string
         */
        function writeTimestamp( $timestamp, $indent = "      " ) {
@@ -733,6 +769,7 @@ class XmlDumpWriter {
        /**
         * @param $id
         * @param $text string
+        * @param $indent string Default to six spaces
         * @return string
         */
        function writeContributor( $id, $text, $indent = "      " ) {
@@ -754,7 +791,7 @@ class XmlDumpWriter {
         * @return string
         */
        function writeUploads( $row, $dumpContents = false ) {
-               if ( $row->page_namespace == NS_IMAGE ) {
+               if ( $row->page_namespace == NS_FILE ) {
                        $img = wfLocalFile( $row->page_title );
                        if ( $img && $img->exists() ) {
                                $out = '';
@@ -812,7 +849,7 @@ class XmlDumpWriter {
         * Return prefixed text form of title, but using the content language's
         * canonical namespace. This skips any special-casing such as gendered
         * user namespaces -- which while useful, are not yet listed in the
-        * XML <siteinfo> data so are unsafe in export.
+        * XML "<siteinfo>" data so are unsafe in export.
         *
         * @param Title $title
         * @return string