From dc78d4d12c7a7b2e0135add4e634ff4a51ead5e1 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Tue, 10 Nov 2015 19:56:19 +0100 Subject: [PATCH] Move details of import logs into log params The detail information about the count of revision and the interwiki title get moved into log params. To show the new information an ImportLogFormatter was written, which changes the key for new log items. This allows to show the detail information in the user language. It also decouple the user supplied data from detail information Change-Id: Iaa57da0fc3e20c33c94fd850cd02db96fdb32dac --- autoload.php | 1 + includes/DefaultSettings.php | 4 +- includes/logging/ImportLogFormatter.php | 42 ++++++ includes/specials/SpecialImport.php | 21 ++- languages/i18n/en.json | 2 + languages/i18n/qqq.json | 2 + .../logging/ImportLogFormatterTest.php | 123 ++++++++++++++++++ 7 files changed, 182 insertions(+), 13 deletions(-) create mode 100644 includes/logging/ImportLogFormatter.php create mode 100644 tests/phpunit/includes/logging/ImportLogFormatterTest.php diff --git a/autoload.php b/autoload.php index 15f1b10ebf..1b51308b44 100644 --- a/autoload.php +++ b/autoload.php @@ -560,6 +560,7 @@ $wgAutoloadLocalClasses = array( 'ImageListPager' => __DIR__ . '/includes/specials/SpecialListfiles.php', 'ImagePage' => __DIR__ . '/includes/page/ImagePage.php', 'ImageQueryPage' => __DIR__ . '/includes/specialpage/ImageQueryPage.php', + 'ImportLogFormatter' => __DIR__ . '/includes/logging/ImportLogFormatter.php', 'ImportReporter' => __DIR__ . '/includes/specials/SpecialImport.php', 'ImportSiteScripts' => __DIR__ . '/maintenance/importSiteScripts.php', 'ImportSites' => __DIR__ . '/maintenance/importSites.php', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index bf6e245d72..759d5b6abc 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -7020,8 +7020,8 @@ $wgLogActionsHandlers = array( 'delete/event' => 'DeleteLogFormatter', 'delete/restore' => 'DeleteLogFormatter', 'delete/revision' => 'DeleteLogFormatter', - 'import/interwiki' => 'LogFormatter', - 'import/upload' => 'LogFormatter', + 'import/interwiki' => 'ImportLogFormatter', + 'import/upload' => 'ImportLogFormatter', 'managetags/activate' => 'LogFormatter', 'managetags/create' => 'LogFormatter', 'managetags/deactivate' => 'LogFormatter', diff --git a/includes/logging/ImportLogFormatter.php b/includes/logging/ImportLogFormatter.php new file mode 100644 index 0000000000..a2a899b097 --- /dev/null +++ b/includes/logging/ImportLogFormatter.php @@ -0,0 +1,42 @@ +extractParameters(); + if ( isset( $params[3] ) ) { + // New log items with more details + // Messages: logentry-import-upload-details, logentry-import-interwiki-details + $key .= '-details'; + } + + return $key; + } +} diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index e2bc62903c..5ca90ed786 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -596,30 +596,29 @@ class ImportReporter extends ContextSource { "\n" ); + $logParams = array( '4:number:count' => $successCount ); if ( $this->mIsUpload ) { $detail = $this->msg( 'import-logentry-upload-detail' )->numParams( $successCount )->inContentLanguage()->text(); - if ( $this->reason ) { - $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text() - . $this->reason; - } $action = 'upload'; } else { - $interwiki = '[[:' . $this->mInterwiki . ':' . - $foreignTitle->getFullText() . ']]'; + $interwikiTitleStr = $this->mInterwiki . ':' . $foreignTitle->getFullText(); + $interwiki = '[[:' . $interwikiTitleStr . ']]'; $detail = $this->msg( 'import-logentry-interwiki-detail' )->numParams( $successCount )->params( $interwiki )->inContentLanguage()->text(); - if ( $this->reason ) { - $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text() - . $this->reason; - } $action = 'interwiki'; + $logParams['5:title-link:interwiki'] = $interwikiTitleStr; + } + if ( $this->reason ) { + $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text() + . $this->reason; } $logEntry = new ManualLogEntry( 'import', $action ); $logEntry->setTarget( $title ); - $logEntry->setComment( $detail ); + $logEntry->setComment( $this->reason ); $logEntry->setPerformer( $this->getUser() ); + $logEntry->setParameters( $logParams ); $logid = $logEntry->insert(); $logEntry->publish( $logid ); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index c4e7d92bba..745487f793 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3611,7 +3611,9 @@ "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-upload-details": "$1 {{GENDER:$2|imported}} $3 by file upload ($4 {{PLURAL:$4|revision|revisions}})", "logentry-import-interwiki": "$1 {{GENDER:$2|imported}} $3 from another wiki", + "logentry-import-interwiki-details": "$1 {{GENDER:$2|imported}} $3 from $5 ($4 {{PLURAL:$4|revision|revisions}})", "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 34240d44f2..0edb205301 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3784,7 +3784,9 @@ "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-upload-details": "{{Logentry|[[Special:Log/import]]}}\n* $4 - Number of imported revisions", "logentry-import-interwiki": "{{Logentry|[[Special:Log/import]]}}", + "logentry-import-interwiki-details": "{{Logentry|[[Special:Log/import]]}}\n* $4 - Number of imported revisions\n* $5 - Interwiki title", "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/logging/ImportLogFormatterTest.php b/tests/phpunit/includes/logging/ImportLogFormatterTest.php new file mode 100644 index 0000000000..5e67c6bb7f --- /dev/null +++ b/tests/phpunit/includes/logging/ImportLogFormatterTest.php @@ -0,0 +1,123 @@ + 'import', + 'action' => 'upload', + 'comment' => 'upload comment', + 'namespace' => NS_MAIN, + 'title' => 'ImportPage', + 'params' => array( + '4:number:count' => '1', + ), + ), + array( + 'text' => 'User imported ImportPage by file upload (1 revision)', + 'api' => array( + 'count' => 1, + ), + ), + ), + + // old format - without details + array( + array( + 'type' => 'import', + 'action' => 'upload', + 'comment' => '1 revision: import comment', + 'namespace' => NS_MAIN, + 'title' => 'ImportPage', + 'params' => array(), + ), + array( + 'text' => 'User imported ImportPage by file upload', + 'api' => array(), + ), + ), + ); + } + + /** + * @dataProvider provideUploadLogDatabaseRows + */ + public function testUploadLogDatabaseRows( $row, $extra ) { + $this->doTestLogFormatter( $row, $extra ); + } + + /** + * Provide different rows from the logging table to test + * for backward compatibility. + * Do not change the existing data, just add a new database row + */ + public static function provideInterwikiLogDatabaseRows() { + return array( + // Current format + array( + array( + 'type' => 'import', + 'action' => 'interwiki', + 'comment' => 'interwiki comment', + 'namespace' => NS_MAIN, + 'title' => 'ImportPage', + 'params' => array( + '4:number:count' => '1', + '5:title-link:interwiki' => 'importiw:PageImport', + ), + ), + array( + 'text' => 'User imported ImportPage from importiw:PageImport (1 revision)', + 'api' => array( + 'count' => 1, + 'interwiki_ns' => 0, + 'interwiki_title' => 'importiw:PageImport', + ), + ), + ), + + // old format - without details + array( + array( + 'type' => 'import', + 'action' => 'interwiki', + 'comment' => '1 revision from importiw:PageImport: interwiki comment', + 'namespace' => NS_MAIN, + 'title' => 'ImportPage', + 'params' => array(), + ), + array( + 'text' => 'User imported ImportPage from another wiki', + 'api' => array(), + ), + ), + ); + } + + /** + * @dataProvider provideInterwikiLogDatabaseRows + */ + public function testInterwikiLogDatabaseRows( $row, $extra ) { + // Setup importiw: as interwiki prefix + $this->setMwGlobals( 'wgHooks', array( + 'InterwikiLoadPrefix' => array( + function ( $prefix, &$data ) { + if ( $prefix == 'importiw' ) { + $data = array( 'iw_url' => 'wikipedia' ); + } + return false; + } + ) + ) ); + + $this->doTestLogFormatter( $row, $extra ); + } +} -- 2.20.1