From 6f44e5b690109a60e68db72a2c4dd88969aeb0a8 Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Mon, 7 May 2018 15:41:53 +0200 Subject: [PATCH] Add setting to control the creation of NullRevision on upload When uploading multiple file revisions with fitting text revisions to core the UploadRevisionImporter will create a unwanted NullRevision on the file page. This NullRevision originates from LocalFile:upload() and is added there in recordUpload2 as part of the normal upload process. There it is meant to leave a hint on the text revision history. This whole area is in need of heavy refactoring. But since the issue is blocking the current implementation of the FileImporter extension, a parameter is added to control the creation of that NullRevision. Bug: T193621 Change-Id: I57c947eb63a7627ab1eec850cdf5e076f5f62df5 --- includes/filerepo/file/LocalFile.php | 15 +++++++++++---- .../ImportableUploadRevisionImporter.php | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index cff1044870..a213633472 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1300,11 +1300,14 @@ class LocalFile extends File { * @param User|null $user User object or null to use $wgUser * @param string[] $tags Change tags to add to the log entry and page revision. * (This doesn't check $user's permissions.) + * @param bool $createNullRevision Set to false to avoid creation of a null revision on file + * upload, see T193621 * @return Status On success, the value member contains the * archive name, or an empty string if it was a new file. */ function upload( $src, $comment, $pageText, $flags = 0, $props = false, - $timestamp = false, $user = null, $tags = [] + $timestamp = false, $user = null, $tags = [], + $createNullRevision = true ) { if ( $this->getRepo()->getReadOnlyReason() !== false ) { return $this->readOnlyFatalStatus(); @@ -1361,7 +1364,8 @@ class LocalFile extends File { $props, $timestamp, $user, - $tags + $tags, + $createNullRevision ); if ( !$uploadStatus->isOK() ) { if ( $uploadStatus->hasMessage( 'filenotfound' ) ) { @@ -1419,10 +1423,13 @@ class LocalFile extends File { * @param string|bool $timestamp * @param null|User $user * @param string[] $tags + * @param bool $createNullRevision Set to false to avoid creation of a null revision on file + * upload, see T193621 * @return Status */ function recordUpload2( - $oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = [] + $oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = [], + $createNullRevision = true ) { global $wgCommentTableSchemaMigrationStage, $wgActorTableSchemaMigrationStage; @@ -1662,7 +1669,7 @@ class LocalFile extends File { $formatter->setContext( RequestContext::newExtraneousContext( $descTitle ) ); $editSummary = $formatter->getPlainActionText(); - $nullRevision = Revision::newNullRevision( + $nullRevision = $createNullRevision === false ? null : Revision::newNullRevision( $dbw, $descId, $editSummary, diff --git a/includes/import/ImportableUploadRevisionImporter.php b/includes/import/ImportableUploadRevisionImporter.php index b64114cf87..95a171b8a7 100644 --- a/includes/import/ImportableUploadRevisionImporter.php +++ b/includes/import/ImportableUploadRevisionImporter.php @@ -17,6 +17,11 @@ class ImportableUploadRevisionImporter implements UploadRevisionImporter { */ private $enableUploads; + /** + * @var bool + */ + private $shouldCreateNullRevision = true; + /** * @param bool $enableUploads * @param LoggerInterface $logger @@ -29,6 +34,16 @@ class ImportableUploadRevisionImporter implements UploadRevisionImporter { $this->logger = $logger; } + /** + * Setting this to false will deactivate the creation of a null revision as part of the upload + * process logging in LocalFile::recordUpload2, see T193621 + * + * @param bool $shouldCreateNullRevision + */ + public function setNullRevisionCreation( $shouldCreateNullRevision ) { + $this->shouldCreateNullRevision = $shouldCreateNullRevision; + } + /** * @return StatusValue */ @@ -100,7 +115,9 @@ class ImportableUploadRevisionImporter implements UploadRevisionImporter { $flags, false, $importableRevision->getTimestamp(), - $user + $user, + [], + $this->shouldCreateNullRevision ); } -- 2.20.1