Follow-up r92220: changed autoblock handling to use PerformRetroactiveAutoblock hook...
[lhc/web/wiklou.git] / includes / Import.php
index 8bd65a6..e1fde33 100644 (file)
@@ -39,13 +39,18 @@ class WikiImporter {
 
        /**
         * Creates an ImportXMLReader drawing from the source provided
-       */
+        */
        function __construct( $source ) {
                $this->reader = new XMLReader();
 
                stream_wrapper_register( 'uploadsource', 'UploadSourceAdapter' );
                $id = UploadSourceAdapter::registerSource( $source );
-               $this->reader->open( "uploadsource://$id" );
+               if (defined( 'LIBXML_PARSEHUGE' ) ) {
+                       $this->reader->open( "uploadsource://$id", null, LIBXML_PARSEHUGE );
+               }
+               else {
+                       $this->reader->open( "uploadsource://$id" );
+               }
 
                // Default callbacks
                $this->setRevisionCallback( array( $this, "importRevision" ) );
@@ -164,7 +169,7 @@ class WikiImporter {
                        // Don't override namespaces
                        $this->mTargetNamespace = null;
                } elseif( $namespace >= 0 ) {
-                       // FIXME: Check for validity
+                       // @todo FIXME: Check for validity
                        $this->mTargetNamespace = intval( $namespace );
                } else {
                        return false;
@@ -1000,9 +1005,11 @@ class WikiRevision {
                if( $user ) {
                        $userId = intval( $user->getId() );
                        $userText = $user->getName();
+                       $userObj = $user;
                } else {
                        $userId = 0;
                        $userText = $this->getUser();
+                       $userObj = new User;
                }
 
                // avoid memory leak...?
@@ -1015,6 +1022,7 @@ class WikiRevision {
                        # must create the page...
                        $pageId = $article->insertOn( $dbw );
                        $created = true;
+                       $oldcountable = null;
                } else {
                        $created = false;
 
@@ -1026,14 +1034,15 @@ class WikiRevision {
                                __METHOD__
                        );
                        if( $prior ) {
-                               // FIXME: this could fail slightly for multiple matches :P
+                               // @todo FIXME: This could fail slightly for multiple matches :P
                                wfDebug( __METHOD__ . ": skipping existing revision for [[" .
                                        $this->title->getPrefixedText() . "]], timestamp " . $this->timestamp . "\n" );
                                return false;
                        }
+                       $oldcountable = $article->isCountable();
                }
 
-               # FIXME: Use original rev_id optionally (better for backups)
+               # @todo FIXME: Use original rev_id optionally (better for backups)
                # Insert the row
                $revision = new Revision( array(
                        'page'       => $pageId,
@@ -1044,47 +1053,27 @@ class WikiRevision {
                        'timestamp'  => $this->timestamp,
                        'minor_edit' => $this->minor,
                        ) );
-               $revId = $revision->insertOn( $dbw );
+               $revision->insertOn( $dbw );
                $changed = $article->updateIfNewerOn( $dbw, $revision );
 
-               # To be on the safe side...
-               $tempTitle = $GLOBALS['wgTitle'];
-               $GLOBALS['wgTitle'] = $this->title;
-
-               if ( $created ) {
-                       wfDebug( __METHOD__ . ": running onArticleCreate\n" );
-                       Article::onArticleCreate( $this->title );
-               } elseif( $changed ) {
-                       wfDebug( __METHOD__ . ": running onArticleEdit\n" );
-                       Article::onArticleEdit( $this->title );
+               if ( $changed !== false ) {
+                       wfDebug( __METHOD__ . ": running updates\n" );
+                       $article->doEditUpdates( $revision, $userObj, array( 'created' => $created, 'oldcountable' => $oldcountable ) );
                }
 
-               wfDebug( __METHOD__ . ": running updates\n" );
-               $article->editUpdates(
-                       $this->getText(),
-                       $this->getComment(),
-                       $this->minor,
-                       $this->timestamp,
-                       $revId,
-                       true,
-                       null,
-                       $created );
-
-               $GLOBALS['wgTitle'] = $tempTitle;
-
                return true;
        }
 
        function importLogItem() {
                $dbw = wfGetDB( DB_MASTER );
-               # FIXME: this will not record autoblocks
+               # @todo FIXME: This will not record autoblocks
                if( !$this->getTitle() ) {
                        wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
                                $this->timestamp . "\n" );
                        return;
                }
                # Check if it exists already
-               // FIXME: use original log ID (better for backups)
+               // @todo FIXME: Use original log ID (better for backups)
                $prior = $dbw->selectField( 'logging', '1',
                        array( 'log_type' => $this->getType(),
                                'log_action'    => $this->getAction(),
@@ -1096,7 +1085,7 @@ class WikiRevision {
                                'log_params'    => $this->params ),
                        __METHOD__
                );
-               // FIXME: this could fail slightly for multiple matches :P
+               // @todo FIXME: This could fail slightly for multiple matches :P
                if( $prior ) {
                        wfDebug( __METHOD__ . ": skipping existing item for Log:{$this->type}/{$this->action}, timestamp " .
                                $this->timestamp . "\n" );
@@ -1153,6 +1142,10 @@ class WikiRevision {
                }
                $sha1 = $this->getSha1();
                if ( $sha1 && ( $sha1 !== sha1_file( $source ) ) ) {
+                       if ( $flags & File::DELETE_SOURCE ) {
+                               # Broken file; delete it if it is a temporary file
+                               unlink( $source );
+                       }
                        wfDebug( __METHOD__ . ": Corrupt file $source.\n" );
                        return false;
                }
@@ -1190,7 +1183,7 @@ class WikiRevision {
                        return false;
                }
 
-               // @todo Fixme!
+               // @todo FIXME!
                $src = $this->getSrc();
                $data = Http::get( $src );
                if( !$data ) {
@@ -1250,7 +1243,9 @@ class ImportStreamSource {
        }
 
        static function newFromFile( $filename ) {
-               $file = @fopen( $filename, 'rt' );
+               wfSuppressWarnings();
+               $file = fopen( $filename, 'rt' );
+               wfRestoreWarnings();
                if( !$file ) {
                        return Status::newFatal( "importcantopen" );
                }