From 4f60a37d4e88d525d383b4c3fd43aaecbb912a68 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Mon, 4 Aug 2014 21:35:18 +0200 Subject: [PATCH] Migrate import log to new log system There is no need for an extra formatter class, because at the moment there is nothing extra to format. This allows use of gender on Special:Log. Old messages are kept for use in IRC. A test was added to ensure an unchanged IRC message. The new log message for import-interwiki is used from I3ca8b21bce49b41cac7109efb8056ca4469b88d7 to avoid "transwiki jargon". Bug: T57404 Change-Id: I590075b203548c071a98c1eaa4b1bc9250f60e22 --- includes/DefaultSettings.php | 4 +-- includes/logging/LogFormatter.php | 13 ++++++++++ includes/specials/SpecialImport.php | 12 ++++++--- languages/i18n/en.json | 2 ++ languages/i18n/qqq.json | 6 +++-- .../includes/changes/RecentChangeTest.php | 25 +++++++++++++++++++ 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 8a4769d1c4..80af4aec6b 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -6689,8 +6689,6 @@ $wgLogActions = array( 'protect/modify' => 'modifiedarticleprotection', 'protect/unprotect' => 'unprotectedarticle', 'protect/move_prot' => 'movedarticleprotection', - 'import/upload' => 'import-logentry-upload', - 'import/interwiki' => 'import-logentry-interwiki', ); /** @@ -6725,6 +6723,8 @@ $wgLogActionsHandlers = array( 'block/reblock' => 'BlockLogFormatter', 'suppress/block' => 'BlockLogFormatter', 'suppress/reblock' => 'BlockLogFormatter', + 'import/upload' => 'LogFormatter', + 'import/interwiki' => 'LogFormatter', ); /** diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index ce6e0adbf0..267a3194b8 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -363,6 +363,19 @@ class LogFormatter { break; } break; + + case 'import': + switch ( $entry->getSubtype() ) { + case 'upload': + $text = wfMessage( 'import-logentry-upload' ) + ->rawParams( $target )->inContentLanguage()->escaped(); + break; + case 'interwiki': + $text = wfMessage( 'import-logentry-interwiki' ) + ->rawParams( $target )->inContentLanguage()->escaped(); + break; + } + break; // case 'suppress' --private log -- aaron (so we know who to blame in a few years :-D) // default: } diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index aa9b0f4263..af86964772 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -546,7 +546,6 @@ class ImportReporter extends ContextSource { "\n" ); - $log = new LogPage( 'import' ); if ( $this->mIsUpload ) { $detail = $this->msg( 'import-logentry-upload-detail' )->numParams( $successCount )->inContentLanguage()->text(); @@ -554,7 +553,7 @@ class ImportReporter extends ContextSource { $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->reason; } - $log->addEntry( 'upload', $title, $detail, array(), $this->getUser() ); + $action = 'upload'; } else { $interwiki = '[[:' . $this->mInterwiki . ':' . $foreignTitle->getFullText() . ']]'; @@ -564,9 +563,16 @@ class ImportReporter extends ContextSource { $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text() . $this->reason; } - $log->addEntry( 'interwiki', $title, $detail, array(), $this->getUser() ); + $action = 'interwiki'; } + $logEntry = new ManualLogEntry( 'import', $action ); + $logEntry->setTarget( $title ); + $logEntry->setComment( $detail ); + $logEntry->setPerformer( $this->getUser() ); + $logid = $logEntry->insert(); + $logEntry->publish( $logid ); + $comment = $detail; // quick $dbw = wfGetDB( DB_MASTER ); $latest = $title->getLatestRevID(); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index a81a89e17a..b40dadb58d 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3472,6 +3472,8 @@ "logentry-block-reblock": "$1 {{GENDER:$2|changed}} block settings for {{GENDER:$4|$3}} with an expiry time of $5 $6", "logentry-suppress-block": "$1 {{GENDER:$2|blocked}} {{GENDER:$4|$3}} with an expiry time of $5 $6", "logentry-suppress-reblock": "$1 {{GENDER:$2|changed}} block settings for {{GENDER:$4|$3}} with an expiry time of $5 $6", + "logentry-import-upload": "$1 {{GENDER:$2|imported}} $3 by file upload", + "logentry-import-interwiki": "$1 {{GENDER:$2|imported}} $3 from another wiki", "logentry-merge-merge": "$1 {{GENDER:$2|merged}} $3 into $4 (revisions up to $5)", "logentry-move-move": "$1 {{GENDER:$2|moved}} page $3 to $4", "logentry-move-move-noredirect": "$1 {{GENDER:$2|moved}} page $3 to $4 without leaving a redirect", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 1761b1873e..6ac333cb8b 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2505,9 +2505,9 @@ "import-rootpage-nosubpage": "Used on [[Special:Import]], when the import namespace does not support subpages. Parameters:\n* $1 is a namespace name.", "importlogpage": "{{doc-logpage}}", "importlogpagetext": "This text appears at the top of the [{{canonicalurl:Special:Log|type=import}} import log] special page.", - "import-logentry-upload": "This is the text of an entry in the Import log (and Recent Changes), after hour (and date, only in the Import log) and sysop name:\n* $1 is the name of the imported file", + "import-logentry-upload": "{{ignored}}This is ''logentry'' message only used on IRC.\n* $1 is the name of the imported file", "import-logentry-upload-detail": "Used as success message and log entry. Parameters:\n* $1 - number of succeeded revisions\nSee also:\n* {{msg-mw|Import-logentry-interwiki-detail}}", - "import-logentry-interwiki": "Used as action listed in the log. Parameters:\n* $1 - page title", + "import-logentry-interwiki": "{{ignored}}This is ''logentry'' message only used on IRC. Parameters:\n* $1 - page title", "import-logentry-interwiki-detail": "Used as success message and log entry. Parameters:\n* $1 - number of succeeded revisions\n* $2 - interwiki name\nSee also:\n* {{msg-mw|Import-logentry-upload-detail}}", "javascripttest": "Title of the special page [[Special:JavaScriptTest]].\n\nSee also:\n* {{msg-mw|Javascripttest|title}}\n* {{msg-mw|Javascripttest-pagetext-noframework|summary}}\n* {{msg-mw|Javascripttest-pagetext-unknownframework|error message}}", "javascripttest-backlink": "{{optional}}\nUsed as subtitle in [[Special:JavaScriptTest]]. Parameters:\n* $1 - page title", @@ -3637,6 +3637,8 @@ "logentry-block-reblock": "{{Logentry|[[Special:Log/block]]}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string\n\nCf. {{msg-mw|Reblock-logentry}}", "logentry-suppress-block": "{{Logentry}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string", "logentry-suppress-reblock": "{{Logentry}}\n* $4 - user name for gender or empty string for autoblocks\n* $5 - the block duration, localized and formatted with the english tooltip\n* $6 - block detail flags or empty string", + "logentry-import-upload": "{{Logentry|[[Special:Log/import]]}}", + "logentry-import-interwiki": "{{Logentry|[[Special:Log/import]]}}", "logentry-merge-merge": "{{Logentry|[[Special:Log/merge]]}}\n* $4 - the page into which the content is merged\n* $5 - a timestamp of limit\n\nThe log and its associated special page 'MergeHistory' is not enabled by default.\n\nPlease note that the parameters in a log entry will appear in the log only in the default language of the wiki. View [[Special:Log]] for examples on translatewiki.net with English default language.", "logentry-move-move": "{{Logentry|[[Special:Log/move]]}}\nParameter $4, the target page, is also not visible to parser functions.", "logentry-move-move-noredirect": "{{Logentry|[[Special:Log/move]]}}\nParameter $4, the target page, is also not visible to parser functions.", diff --git a/tests/phpunit/includes/changes/RecentChangeTest.php b/tests/phpunit/includes/changes/RecentChangeTest.php index e00a45a2c1..b3cb7b529e 100644 --- a/tests/phpunit/includes/changes/RecentChangeTest.php +++ b/tests/phpunit/includes/changes/RecentChangeTest.php @@ -48,6 +48,8 @@ class RecentChangeTest extends MediaWikiTestCase { * - protect/unprotect * - upload/upload * - merge/merge + * - import/upload + * - import/interwiki * * As well as the following Auto Edit Summaries: * - blank @@ -265,6 +267,29 @@ class RecentChangeTest extends MediaWikiTestCase { ); } + /** + * @covers LogFormatter::getIRCActionText + */ + public function testIrcMsgForLogTypeImport() { + $sep = $this->context->msg( 'colon-separator' )->text(); + + # import/upload + $this->assertIRCComment( + $this->context->msg( 'import-logentry-upload', 'SomeTitle' )->plain() . $sep . $this->user_comment, + 'import', 'upload', + array(), + $this->user_comment + ); + + # import/interwiki + $this->assertIRCComment( + $this->context->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() . $sep . $this->user_comment, + 'import', 'interwiki', + array(), + $this->user_comment + ); + } + /** * @todo Emulate these edits somehow and extract * raw edit summary from RecentChange object -- 2.20.1