Merge "Ensure users are able to edit the page after changing the content model"
[lhc/web/wiklou.git] / includes / import / WikiRevision.php
index d4db765..1e866f3 100644 (file)
@@ -319,7 +319,7 @@ class WikiRevision {
         * @deprecated Since 1.21, use getContent() instead.
         */
        function getText() {
-               ContentHandler::deprecated( __METHOD__, '1.21' );
+               wfDeprecated( __METHOD__, '1.21' );
 
                return $this->text;
        }
@@ -574,7 +574,7 @@ class WikiRevision {
                if ( !$this->getTitle() ) {
                        wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
                                $this->timestamp . "\n" );
-                       return;
+                       return false;
                }
                # Check if it exists already
                // @todo FIXME: Use original log ID (better for backups)
@@ -594,7 +594,7 @@ class WikiRevision {
                        wfDebug( __METHOD__
                                . ": skipping existing item for Log:{$this->type}/{$this->action}, timestamp "
                                . $this->timestamp . "\n" );
-                       return;
+                       return false;
                }
                $log_id = $dbw->nextSequenceValue( 'logging_log_id_seq' );
                $data = [
@@ -610,6 +610,8 @@ class WikiRevision {
                        'log_params' => $this->params
                ];
                $dbw->insert( 'logging', $data, __METHOD__ );
+
+               return true;
        }
 
        /**
@@ -640,22 +642,24 @@ class WikiRevision {
 
                # Get the file source or download if necessary
                $source = $this->getFileSrc();
-               $flags = $this->isTempSrc() ? File::DELETE_SOURCE : 0;
-               if ( !$source ) {
+               $autoDeleteSource = $this->isTempSrc();
+               if ( !strlen( $source ) ) {
                        $source = $this->downloadSource();
-                       $flags |= File::DELETE_SOURCE;
+                       $autoDeleteSource = true;
                }
-               if ( !$source ) {
+               if ( !strlen( $source ) ) {
                        wfDebug( __METHOD__ . ": Could not fetch remote file.\n" );
                        return false;
                }
+
+               $tmpFile = new TempFSFile( $source );
+               if ( $autoDeleteSource ) {
+                       $tmpFile->autocollect();
+               }
+
                $sha1File = ltrim( sha1_file( $source ), '0' );
                $sha1 = $this->getSha1();
                if ( $sha1 && ( $sha1 !== $sha1File ) ) {
-                       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;
                }
@@ -665,8 +669,9 @@ class WikiRevision {
                # Do the actual upload
                if ( $archiveName ) {
                        $status = $file->uploadOld( $source, $archiveName,
-                               $this->getTimestamp(), $this->getComment(), $user, $flags );
+                               $this->getTimestamp(), $this->getComment(), $user );
                } else {
+                       $flags = 0;
                        $status = $file->upload( $source, $this->getComment(), $this->getComment(),
                                $flags, false, $this->getTimestamp(), $user );
                }