aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorumherirrender <umherirrender_de.wp@web.de>2015-11-10 19:56:19 +0100
committerumherirrender <umherirrender_de.wp@web.de>2015-11-11 18:34:18 +0100
commitdc78d4d12c7a7b2e0135add4e634ff4a51ead5e1 (patch)
tree6aea508817d55807a670af44900d3dbfcf288878
parent5cb16e7711354fb3a39913d5a38d55367751d81b (diff)
downloadmediawikicore-dc78d4d12c7a7b2e0135add4e634ff4a51ead5e1.tar.gz
mediawikicore-dc78d4d12c7a7b2e0135add4e634ff4a51ead5e1.zip
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
-rw-r--r--autoload.php1
-rw-r--r--includes/DefaultSettings.php4
-rw-r--r--includes/logging/ImportLogFormatter.php42
-rw-r--r--includes/specials/SpecialImport.php21
-rw-r--r--languages/i18n/en.json2
-rw-r--r--languages/i18n/qqq.json2
-rw-r--r--tests/phpunit/includes/logging/ImportLogFormatterTest.php123
7 files changed, 182 insertions, 13 deletions
diff --git a/autoload.php b/autoload.php
index 15f1b10ebfac..1b51308b44d7 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 bf6e245d724c..759d5b6abc0b 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 000000000000..a2a899b09759
--- /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 e2bc62903c25..5ca90ed78615 100644
--- a/includes/specials/SpecialImport.php
+++ b/includes/specials/SpecialImport.php
@@ -596,30 +596,29 @@ class ImportReporter extends ContextSource {
"</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 c4e7d92bba1b..745487f79339 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 34240d44f2e6..0edb205301ad 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 000000000000..5e67c6bb7f26
--- /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 );
+ }
+}