mark ApiEditPageTest as being slow tests
[lhc/web/wiklou.git] / includes / Export.php
index 36d98d6..45a5366 100644 (file)
@@ -58,6 +58,14 @@ class WikiExporter {
         */
        var $sink;
 
+       /**
+        * Returns the export schema version.
+        * @return string
+        */
+       public static function schemaVersion() {
+               return "0.8";
+       }
+
        /**
         * If using WikiExporter::STREAM to stream a large amount of data,
         * provide a database connection which is not managed by
@@ -75,9 +83,9 @@ class WikiExporter {
         * @param $buffer Int: one of WikiExporter::BUFFER or WikiExporter::STREAM
         * @param $text Int: one of WikiExporter::TEXT or WikiExporter::STUB
         */
-       function __construct( &$db, $history = WikiExporter::CURRENT,
+       function __construct( $db, $history = WikiExporter::CURRENT,
                        $buffer = WikiExporter::BUFFER, $text = WikiExporter::TEXT ) {
-               $this->db =& $db;
+               $this->db = $db;
                $this->history = $history;
                $this->buffer  = $buffer;
                $this->writer  = new XmlDumpWriter();
@@ -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,35 +636,29 @@ class XmlDumpWriter {
 
                $out  = "    <revision>\n";
                $out .= "      " . Xml::element( 'id', null, strval( $row->rev_id ) ) . "\n";
-               if( $row->rev_parent_id ) {
+               if( isset( $row->rev_parent_id ) && $row->rev_parent_id ) {
                        $out .= "      " . Xml::element( 'parentid', null, strval( $row->rev_parent_id ) ) . "\n";
                }
 
                $out .= $this->writeTimestamp( $row->rev_timestamp );
 
-               if ( $row->rev_deleted & Revision::DELETED_USER ) {
+               if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_USER ) ) {
                        $out .= "      " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
                } else {
                        $out .= $this->writeContributor( $row->rev_user, $row->rev_user_text );
                }
 
-               if ( $row->rev_minor_edit ) {
+               if ( isset( $row->rev_minor_edit ) && $row->rev_minor_edit ) {
                        $out .=  "      <minor/>\n";
                }
-               if ( $row->rev_deleted & Revision::DELETED_COMMENT ) {
+               if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_COMMENT ) ) {
                        $out .= "      " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
                } elseif ( $row->rev_comment != '' ) {
                        $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 ) {
+               if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
                        $out .= "      " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
                } elseif ( isset( $row->old_text ) ) {
                        // Raw text from the database may have invalid chars
@@ -669,6 +673,34 @@ class XmlDumpWriter {
                                "" ) . "\n";
                }
 
+               if ( isset( $row->rev_sha1 ) && $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";
@@ -678,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
@@ -726,6 +758,7 @@ class XmlDumpWriter {
 
        /**
         * @param $timestamp string
+        * @param $indent string Default to six spaces
         * @return string
         */
        function writeTimestamp( $timestamp, $indent = "      " ) {
@@ -736,6 +769,7 @@ class XmlDumpWriter {
        /**
         * @param $id
         * @param $text string
+        * @param $indent string Default to six spaces
         * @return string
         */
        function writeContributor( $id, $text, $indent = "      " ) {
@@ -815,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
@@ -1313,6 +1347,7 @@ class DumpNamespaceFilter extends DumpFilter {
        /**
         * @param $sink DumpOutput
         * @param $param
+        * @throws MWException
         */
        function __construct( &$sink, $param ) {
                parent::__construct( $sink );