From 84c46d38b7385c97fc3c1e865e3d7ba29f07520f Mon Sep 17 00:00:00 2001 From: MGChecker Date: Mon, 1 Oct 2018 20:05:44 +0200 Subject: [PATCH] Add separate log action for file reverts This change s adds 'revert' as a separate log action for file reverts, as it allows special formatting of log entries and revisions in UI and filtering for file reverts specifically. Even though there are no log entries with this log action right now, it does seem that this was intended as some point, as there are corresponding test cases in UploadLogFormatterTest, and is listed in $wgLogActionsHandlers and https://www.mediawiki.org/wiki/API:Logevents as well. Furthermore, the i18n message 'logentry-upload-revert' already existed before this change. Because this functionality can not be provided by tags, the 'mw-undo' tag is not suited for this use case. However, it could be added additionally to all log entries with this log action.. Bug: T60209 Change-Id: Ie1ccd8053dc5de58b2297a8460219f0233aab968 --- includes/DefaultSettings.php | 1 + includes/actions/RevertAction.php | 5 ++++- includes/filerepo/file/LocalFile.php | 19 +++++++++++++++---- includes/logging/LogFormatter.php | 1 + languages/i18n/en.json | 3 ++- languages/i18n/qqq.json | 1 + .../logging/UploadLogFormatterTest.php | 4 ++-- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 62592081a5..073e539547 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -7933,6 +7933,7 @@ $wgActionFilteredLogs = [ 'upload' => [ 'upload' => [ 'upload' ], 'overwrite' => [ 'overwrite' ], + 'revert' => [ 'revert' ], ], ]; diff --git a/includes/actions/RevertAction.php b/includes/actions/RevertAction.php index 68a032573a..8a5d7c9046 100644 --- a/includes/actions/RevertAction.php +++ b/includes/actions/RevertAction.php @@ -136,7 +136,10 @@ class RevertAction extends FormAction { 0, false, false, - $this->getUser() + $this->getUser(), + [], + true, + true ); } diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 789d7c5215..a3d1624205 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1303,12 +1303,13 @@ class LocalFile extends File { * (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 + * @param bool $revert If this file upload is a revert * @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 = [], - $createNullRevision = true + $createNullRevision = true, $revert = false ) { if ( $this->getRepo()->getReadOnlyReason() !== false ) { return $this->readOnlyFatalStatus(); @@ -1366,7 +1367,8 @@ class LocalFile extends File { $timestamp, $user, $tags, - $createNullRevision + $createNullRevision, + $revert ); if ( !$uploadStatus->isOK() ) { if ( $uploadStatus->hasMessage( 'filenotfound' ) ) { @@ -1425,11 +1427,12 @@ class LocalFile extends File { * @param string[] $tags * @param bool $createNullRevision Set to false to avoid creation of a null revision on file * upload, see T193621 + * @param bool $revert If this file upload is a revert * @return Status */ function recordUpload2( $oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = [], - $createNullRevision = true + $createNullRevision = true, $revert = false ) { global $wgActorTableSchemaMigrationStage; @@ -1602,8 +1605,16 @@ class LocalFile extends File { $wikiPage = new WikiFilePage( $descTitle ); $wikiPage->setFile( $this ); + // Determine log action. If reupload is done by reverting, use a special log_action. + if ( $revert === true ) { + $logAction = 'revert'; + } elseif ( $reupload === true ) { + $logAction = 'overwrite'; + } else { + $logAction = 'upload'; + } // Add the log entry... - $logEntry = new ManualLogEntry( 'upload', $reupload ? 'overwrite' : 'upload' ); + $logEntry = new ManualLogEntry( 'upload', $logAction ); $logEntry->setTimestamp( $this->timestamp ); $logEntry->setPerformer( $user ); $logEntry->setComment( $comment ); diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index b07f20e6d9..6d45ed56ea 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -329,6 +329,7 @@ class LogFormatter { ->rawParams( $target )->inContentLanguage()->escaped(); break; case 'overwrite': + case 'revert': $text = wfMessage( 'overwroteimage' ) ->rawParams( $target )->inContentLanguage()->escaped(); break; diff --git a/languages/i18n/en.json b/languages/i18n/en.json index bf2f19e085..8700cecb29 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3814,7 +3814,7 @@ "logentry-rights-autopromote": "$1 was automatically {{GENDER:$2|promoted}} from $4 to $5", "logentry-upload-upload": "$1 {{GENDER:$2|uploaded}} $3", "logentry-upload-overwrite": "$1 {{GENDER:$2|uploaded}} a new version of $3", - "logentry-upload-revert": "$1 {{GENDER:$2|uploaded}} $3", + "logentry-upload-revert": "$1 {{GENDER:$2|reverted}} $3 to an old version", "log-name-managetags": "Tag management log", "log-description-managetags": "This page lists management tasks related to [[Special:Tags|tags]]. The log contains only actions carried out manually by an administrator; tags may be created or deleted by the wiki software without an entry being recorded in this log.", "logentry-managetags-create": "$1 {{GENDER:$2|created}} the tag \"$4\"", @@ -4070,6 +4070,7 @@ "log-action-filter-suppress-reblock": "User suppression by reblock", "log-action-filter-upload-upload": "New upload", "log-action-filter-upload-overwrite": "Reupload", + "log-action-filter-upload-revert": "Revert", "authmanager-authn-not-in-progress": "Authentication is not in progress or session data has been lost. Please start again from the beginning.", "authmanager-authn-no-primary": "The supplied credentials could not be authenticated.", "authmanager-authn-no-local-user": "The supplied credentials are not associated with any user on this wiki.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 63a112caf4..fab3ddcb30 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -4276,6 +4276,7 @@ "log-action-filter-suppress-reblock": "{{doc-log-action-filter-action|suppress|reblock}}", "log-action-filter-upload-upload": "{{doc-log-action-filter-action|upload|upload}}", "log-action-filter-upload-overwrite": "{{doc-log-action-filter-action|upload|overwrite}}", + "log-action-filter-upload-revert": "{{doc-log-action-filter-action|upload|revert}}", "authmanager-authn-not-in-progress": "Error message when AuthManager session data is lost during authentication, or the user hits the \"continue\" endpoint without an active authentication attempt.", "authmanager-authn-no-primary": "Error message when no AuthenticationProvider handles the AuthenticationRequests for login. This might mean the user needs to fill out all the form fields.", "authmanager-authn-no-local-user": "Error message when authentication somehow succeeds without a username being known. This probably should never happen.", diff --git a/tests/phpunit/includes/logging/UploadLogFormatterTest.php b/tests/phpunit/includes/logging/UploadLogFormatterTest.php index 2b4067f17d..b393949424 100644 --- a/tests/phpunit/includes/logging/UploadLogFormatterTest.php +++ b/tests/phpunit/includes/logging/UploadLogFormatterTest.php @@ -134,7 +134,7 @@ class UploadLogFormatterTest extends LogFormatterTestCase { ], ], [ - 'text' => 'User uploaded File:File.png', + 'text' => 'User reverted File:File.png to an old version', 'api' => [ 'img_sha1' => 'hash', 'img_timestamp' => '2015-01-01T00:00:00Z', @@ -153,7 +153,7 @@ class UploadLogFormatterTest extends LogFormatterTestCase { 'params' => [], ], [ - 'text' => 'User uploaded File:File.png', + 'text' => 'User reverted File:File.png to an old version', 'api' => [], ], ], -- 2.20.1