Merge "Update OOjs UI to v0.1.0-pre (48980881f3)"
[lhc/web/wiklou.git] / includes / Export.php
index 4c71eb9..dee0a86 100644 (file)
@@ -41,7 +41,7 @@ class WikiExporter {
        public $dumpUploadFileContents = false;
 
        /** @var string */
-       protected $author_list = "";
+       public $author_list = "";
 
        const FULL = 1;
        const CURRENT = 2;
@@ -56,20 +56,20 @@ class WikiExporter {
        const STUB = 1;
 
        /** @var int */
-       protected $buffer;
+       public $buffer;
 
        /** @var int */
-       protected $text;
+       public $text;
 
        /** @var DumpOutput */
-       protected $sink;
+       public $sink;
 
        /**
         * Returns the export schema version.
         * @return string
         */
        public static function schemaVersion() {
-               return "0.8";
+               return "0.9";
        }
 
        /**
@@ -267,7 +267,7 @@ class WikiExporter {
                        if ( $this->buffer == WikiExporter::STREAM ) {
                                $prev = $this->db->bufferResults( false );
                        }
-                       $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
+                       $result = null; // Assuring $result is not undefined, if exception occurs early
                        try {
                                $result = $this->db->select( array( 'logging', 'user' ),
                                        array( "{$logging}.*", 'user_name' ), // grab the user name
@@ -275,8 +275,7 @@ class WikiExporter {
                                        __METHOD__,
                                        array( 'ORDER BY' => 'log_id', 'USE INDEX' => array( 'logging' => 'PRIMARY' ) )
                                );
-                               $wrapper = $this->db->resultObject( $result );
-                               $this->outputLogStream( $wrapper );
+                               $this->outputLogStream( $result );
                                if ( $this->buffer == WikiExporter::STREAM ) {
                                        $this->db->bufferResults( $prev );
                                }
@@ -286,8 +285,8 @@ class WikiExporter {
 
                                // Freeing result
                                try {
-                                       if ( $wrapper ) {
-                                               $wrapper->free();
+                                       if ( $result ) {
+                                               $result->free();
                                        }
                                } catch ( Exception $e2 ) {
                                        // Already in panic mode -> ignoring $e2 as $e has
@@ -377,16 +376,15 @@ class WikiExporter {
                                $prev = $this->db->bufferResults( false );
                        }
 
-                       $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
+                       $result = null; // Assuring $result is not undefined, if exception occurs early
                        try {
                                wfRunHooks( 'ModifyExportQuery',
                                                array( $this->db, &$tables, &$cond, &$opts, &$join ) );
 
                                # Do the query!
                                $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
-                               $wrapper = $this->db->resultObject( $result );
                                # Output dump results
-                               $this->outputPageStream( $wrapper );
+                               $this->outputPageStream( $result );
 
                                if ( $this->buffer == WikiExporter::STREAM ) {
                                        $this->db->bufferResults( $prev );
@@ -397,8 +395,8 @@ class WikiExporter {
 
                                // Freeing result
                                try {
-                                       if ( $wrapper ) {
-                                               $wrapper->free();
+                                       if ( $result ) {
+                                               $result->free();
                                        }
                                } catch ( Exception $e2 ) {
                                        // Already in panic mode -> ignoring $e2 as $e has
@@ -467,7 +465,7 @@ class WikiExporter {
        }
 
        /**
-        * @param array $resultset
+        * @param ResultWrapper $resultset
         */
        protected function outputLogStream( $resultset ) {
                foreach ( $resultset as $row ) {
@@ -481,16 +479,6 @@ class WikiExporter {
  * @ingroup Dump
  */
 class XmlDumpWriter {
-       /**
-        * Returns the export schema version.
-        * @deprecated since 1.20; use WikiExporter::schemaVersion() instead
-        * @return string
-        */
-       function schemaVersion() {
-               wfDeprecated( __METHOD__, '1.20' );
-               return WikiExporter::schemaVersion();
-       }
-
        /**
         * Opens the XML output stream's root "<mediawiki>" element.
         * This does not include an xml directive, so is safe to include
@@ -507,8 +495,17 @@ class XmlDumpWriter {
                return Xml::element( 'mediawiki', array(
                        'xmlns'              => "http://www.mediawiki.org/xml/export-$ver/",
                        'xmlns:xsi'          => "http://www.w3.org/2001/XMLSchema-instance",
+                       /*
+                        * When a new version of the schema is created, it needs staging on mediawiki.org.
+                        * This requires a change in the operations/mediawiki-config git repo.
+                        *
+                        * Create a changeset like https://gerrit.wikimedia.org/r/#/c/149643/ in which
+                        * you copy in the new xsd file.
+                        *
+                        * After it is reviewed, merged and deployed (sync-docroot), the index.html needs purging.
+                        * echo "http://www.mediawiki.org/xml/index.html" | mwscript purgeList.php --wiki=aawiki
+                        */
                        'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
-                               #TODO: how do we get a new version up there?
                                "http://www.mediawiki.org/xml/export-$ver.xsd",
                        'version'            => $ver,
                        'xml:lang'           => $wgLanguageCode ),
@@ -523,6 +520,7 @@ class XmlDumpWriter {
        function siteInfo() {
                $info = array(
                        $this->sitename(),
+                       $this->dbname(),
                        $this->homelink(),
                        $this->generator(),
                        $this->caseSetting(),
@@ -540,6 +538,14 @@ class XmlDumpWriter {
                return Xml::element( 'sitename', array(), $wgSitename );
        }
 
+       /**
+        * @return string
+        */
+       function dbname() {
+               global $wgDBname;
+               return Xml::element( 'dbname', array(), $wgDBname );
+       }
+
        /**
         * @return string
         */
@@ -670,12 +676,30 @@ class XmlDumpWriter {
                        $out .= "      " . Xml::elementClean( 'comment', array(), strval( $row->rev_comment ) ) . "\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;
+                       $title = Title::makeTitle( $row->page_namespace, $row->page_title );
+                       $content_model = ContentHandler::getDefaultModelFor( $title );
+               }
+
+               $content_handler = ContentHandler::getForModelID( $content_model );
+
+               if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) {
+                       $content_format = strval( $row->rev_content_format );
+               } else {
+                       // probably using $wgContentHandlerUseDB = false;
+                       $content_format = $content_handler->getDefaultFormat();
+               }
+
                $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
                        $text = strval( Revision::getRevisionText( $row ) );
+                       $text = $content_handler->exportTransform( $text, $content_format );
                        $out .= "      " . Xml::elementClean( 'text',
                                array( 'xml:space' => 'preserve', 'bytes' => intval( $row->rev_len ) ),
                                strval( $text ) ) . "\n";
@@ -695,26 +719,7 @@ class XmlDumpWriter {
                        $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 ) );
@@ -1353,10 +1358,10 @@ class DumpNotalkFilter extends DumpFilter {
  */
 class DumpNamespaceFilter extends DumpFilter {
        /** @var bool */
-       protected $invert = false;
+       public $invert = false;
 
        /** @var array */
-       protected $namespaces = array();
+       public $namespaces = array();
 
        /**
         * @param DumpOutput $sink
@@ -1420,13 +1425,13 @@ class DumpNamespaceFilter extends DumpFilter {
  * @ingroup Dump
  */
 class DumpLatestFilter extends DumpFilter {
-       protected $page;
+       public $page;
 
-       protected $pageString;
+       public $pageString;
 
-       protected $rev;
+       public $rev;
 
-       protected $revString;
+       public $revString;
 
        /**
         * @param object $page
@@ -1553,23 +1558,3 @@ class DumpMultiWriter {
                return $filenames;
        }
 }
-
-/**
- * @param string $string
- * @return string
- * @todo FIXME: Only used in OAI extension. Move over there.
- */
-function xmlsafe( $string ) {
-       wfProfileIn( __FUNCTION__ );
-
-       /**
-        * The page may contain old data which has not been properly normalized.
-        * Invalid UTF-8 sequences or forbidden control characters will make our
-        * XML output invalid, so be sure to strip them out.
-        */
-       $string = UtfNormal::cleanUp( $string );
-
-       $string = htmlspecialchars( $string );
-       wfProfileOut( __FUNCTION__ );
-       return $string;
-}