Merge "Introduce ContentHandler::importTransform."
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 27 May 2014 18:26:19 +0000 (18:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 27 May 2014 18:26:19 +0000 (18:26 +0000)
1  2 
includes/Import.php

diff --combined includes/Import.php
@@@ -45,9 -45,7 +45,9 @@@ class WikiImporter 
        function __construct( $source ) {
                $this->reader = new XMLReader();
  
 -              stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' );
 +              if ( !in_array(  'uploadsource', stream_get_wrappers() ) ) {
 +                      stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' );
 +              }
                $id = UploadSourceAdapter::registerSource( $source );
                if ( defined( 'LIBXML_PARSEHUGE' ) ) {
                        $this->reader->open( "uploadsource://$id", null, LIBXML_PARSEHUGE );
         * @return bool
         */
        public function importRevision( $revision ) {
-               if ( !$revision->getContent()->getContentHandler()->canBeUsedOn( $revision->getTitle() ) ) {
+               if ( !$revision->getContentHandler()->canBeUsedOn( $revision->getTitle() ) ) {
                        $this->notice( 'import-error-bad-location',
                                $revision->getTitle()->getPrefixedText(),
                                $revision->getID(),
                if ( isset( $revisionInfo['id'] ) ) {
                        $revision->setID( $revisionInfo['id'] );
                }
-               if ( isset( $revisionInfo['text'] ) ) {
-                       $revision->setText( $revisionInfo['text'] );
-               }
                if ( isset( $revisionInfo['model'] ) ) {
                        $revision->setModel( $revisionInfo['model'] );
                }
                }
                $revision->setTitle( $pageInfo['_title'] );
  
+               if ( isset( $revisionInfo['text'] ) ) {
+                       $handler = $revision->getContentHandler();
+                       $text = $handler->importTransform(
+                               $revisionInfo['text'],
+                               $revision->getFormat() );
+                       $revision->setText( $text );
+               }
                if ( isset( $revisionInfo['timestamp'] ) ) {
                        $revision->setTimestamp( $revisionInfo['timestamp'] );
                } else {
@@@ -1089,6 -1092,9 +1094,9 @@@ class WikiRevision 
        /** @var Content */
        protected $content = null;
  
+       /** @var ContentHandler */
+       protected $contentHandler = null;
        /** @var string */
        public $comment = "";
  
                return $this->text;
        }
  
+       /**
+        * @return ContentHandler
+        */
+       function getContentHandler() {
+               if ( is_null( $this->contentHandler ) ) {
+                       $this->contentHandler = ContentHandler::getForModelID( $this->getModel() );
+               }
+               return $this->contentHandler;
+       }
        /**
         * @return Content
         */
        function getContent() {
                if ( is_null( $this->content ) ) {
-                       $this->content =
-                               ContentHandler::makeContent(
-                                       $this->text,
-                                       $this->getTitle(),
-                                       $this->getModel(),
-                                       $this->getFormat()
-                               );
+                       $handler = $this->getContentHandler();
+                       $this->content = $handler->unserializeContent( $this->text, $this->getFormat() );
                }
  
                return $this->content;
         * @return string
         */
        function getFormat() {
-               if ( is_null( $this->model ) ) {
-                       $this->format = ContentHandler::getForTitle( $this->getTitle() )->getDefaultFormat();
+               if ( is_null( $this->format ) ) {
+                       $this->format = $this->getContentHandler()->getDefaultFormat();
                }
  
                return $this->format;