Follow-up r92220: changed autoblock handling to use PerformRetroactiveAutoblock hook...
[lhc/web/wiklou.git] / includes / Import.php
index 3a2c19c..e1fde33 100644 (file)
@@ -45,7 +45,12 @@ class WikiImporter {
 
                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" ) );
@@ -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;
 
@@ -1031,6 +1039,7 @@ class WikiRevision {
                                        $this->title->getPrefixedText() . "]], timestamp " . $this->timestamp . "\n" );
                                return false;
                        }
+                       $oldcountable = $article->isCountable();
                }
 
                # @todo FIXME: Use original rev_id optionally (better for backups)
@@ -1044,34 +1053,14 @@ 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;
        }
 
@@ -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;
                }
@@ -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" );
                }