jenkins-bot has submitted this change and it was merged.
Change subject: Move details of import logs into log params
......................................................................
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
---
M autoload.php
M includes/DefaultSettings.php
A includes/logging/ImportLogFormatter.php
M includes/specials/SpecialImport.php
M languages/i18n/en.json
M languages/i18n/qqq.json
A tests/phpunit/includes/logging/ImportLogFormatterTest.php
7 files changed, 182 insertions(+), 13 deletions(-)
Approvals:
Nikerabbit: Looks good to me, approved
TTO: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/autoload.php b/autoload.php
index 15f1b10..1b51308 100644
--- a/autoload.php
+++ b/autoload.php
@@ -560,6 +560,7 @@
'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 bf6e245..759d5b6 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -7020,8 +7020,8 @@
'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 0000000..a2a899b
--- /dev/null
+++ b/includes/logging/ImportLogFormatter.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Formatter for import log entries.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
2.0 or later
+ * @since 1.27
+ */
+
+/**
+ * This class formats import log entries.
+ *
+ * @since 1.27
+ */
+class ImportLogFormatter extends LogFormatter {
+ protected function getMessageKey() {
+ $key = parent::getMessageKey();
+ $params = $this->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 e2bc629..5ca90ed 100644
--- a/includes/specials/SpecialImport.php
+++ b/includes/specials/SpecialImport.php
@@ -596,30 +596,29 @@
"</li>\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 c4e7d92..745487f 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 34240d4..0edb205 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 0000000..5e67c6b
--- /dev/null
+++ b/tests/phpunit/includes/logging/ImportLogFormatterTest.php
@@ -0,0 +1,123 @@
+<?php
+
+class ImportLogFormatterTest extends LogFormatterTestCase {
+
+ /**
+ * 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 provideUploadLogDatabaseRows() {
+ return array(
+ // Current format
+ array(
+ array(
+ 'type' => '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 );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/252255
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaa57da0fc3e20c33c94fd850cd02db96fdb32dac
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: TTO <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits