Move details of import logs into log params
authorumherirrender <umherirrender_de.wp@web.de>
Tue, 10 Nov 2015 18:56:19 +0000 (19:56 +0100)
committerumherirrender <umherirrender_de.wp@web.de>
Wed, 11 Nov 2015 17:34:18 +0000 (18:34 +0100)
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
includes/DefaultSettings.php
includes/logging/ImportLogFormatter.php [new file with mode: 0644]
includes/specials/SpecialImport.php
languages/i18n/en.json
languages/i18n/qqq.json
tests/phpunit/includes/logging/ImportLogFormatterTest.php [new file with mode: 0644]

index 15f1b10..1b51308 100644 (file)
@@ -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',
index bf6e245..759d5b6 100644 (file)
@@ -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 (file)
index 0000000..a2a899b
--- /dev/null
@@ -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;
+       }
+}
index e2bc629..5ca90ed 100644 (file)
@@ -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 );
 
index c4e7d92..745487f 100644 (file)
        "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",
index 34240d4..0edb205 100644 (file)
        "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 (file)
index 0000000..5e67c6b
--- /dev/null
@@ -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 );
+       }
+}