Migrate merge log to new log system
authorumherirrender <umherirrender_de.wp@web.de>
Mon, 4 Aug 2014 17:10:51 +0000 (19:10 +0200)
committerSiebrand <siebrand@kitano.nl>
Tue, 21 Oct 2014 16:49:06 +0000 (16:49 +0000)
This allows use of gender on Special:Log
Old message is kept for use in irc,
a test is added to ensure a unchanged irc message.

Change-Id: I0557a0d2751540cf0d7967333ffd767b934011c6

includes/AutoLoader.php
includes/DefaultSettings.php
includes/api/ApiQueryLogEvents.php
includes/logging/LogFormatter.php
includes/logging/LogPage.php
includes/logging/MergeLogFormatter.php [new file with mode: 0644]
includes/specials/SpecialMergeHistory.php
languages/i18n/en.json
languages/i18n/qqq.json
tests/phpunit/includes/changes/RecentChangeTest.php

index a564ce6..6936570 100644 (file)
@@ -716,6 +716,7 @@ $wgAutoloadLocalClasses = array(
        'LogPage' => 'includes/logging/LogPage.php',
        'LogPager' => 'includes/logging/LogPager.php',
        'ManualLogEntry' => 'includes/logging/LogEntry.php',
+       'MergeLogFormatter' => 'includes/logging/MergeLogFormatter.php',
        'MoveLogFormatter' => 'includes/logging/MoveLogFormatter.php',
        'NewUsersLogFormatter' => 'includes/logging/NewUsersLogFormatter.php',
        'PageLangLogFormatter' => 'includes/logging/PageLangLogFormatter.php',
index cd65ffe..af36a64 100644 (file)
@@ -6613,7 +6613,6 @@ $wgLogActions = array(
        'protect/move_prot' => 'movedarticleprotection',
        'import/upload' => 'import-logentry-upload',
        'import/interwiki' => 'import-logentry-interwiki',
-       'merge/merge' => 'pagemerge-logentry',
        'suppress/block' => 'blocklogentry',
        'suppress/reblock' => 'reblock-logentry',
 );
@@ -6640,6 +6639,7 @@ $wgLogActionsHandlers = array(
        'upload/upload' => 'LogFormatter',
        'upload/overwrite' => 'LogFormatter',
        'upload/revert' => 'LogFormatter',
+       'merge/merge' => 'MergeLogFormatter',
 );
 
 /**
index f83fe69..eb5ca4f 100644 (file)
@@ -327,6 +327,17 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                        $params['img_timestamp'] = wfTimestamp( TS_ISO_8601, $params['img_timestamp'] );
                                }
                                break;
+                       case 'merge':
+                               // replace the named parameter with numbered for backward compatibility
+                               if ( isset( $params['4::dest'] ) ) {
+                                       $params[] = $params['4::dest'];
+                                       unset( $params['4::dest'] );
+                               }
+                               if ( isset( $params['5::mergepoint'] ) ) {
+                                       $params[] = $params['5::mergepoint'];
+                                       unset( $params['5::mergepoint'] );
+                               }
+                               break;
                }
                if ( !is_null( $params ) ) {
                        $logParams = array();
index 48a565f..bbe2f42 100644 (file)
@@ -322,6 +322,12 @@ class LogFormatter {
                                                break;
                                }
                                break;
+
+                       case 'merge':
+                               $text = wfMessage( 'pagemerge-logentry' )
+                                       ->rawParams( $target, $parameters['4::dest'], $parameters['5::mergepoint'] )
+                                       ->inContentLanguage()->escaped();
+                               break;
                        // case 'suppress' --private log -- aaron  (so we know who to blame in a few years :-D)
                        // default:
                }
@@ -791,26 +797,6 @@ class LegacyLogFormatter extends LogFormatter {
 
                        return $this->msg( 'parentheses' )->rawParams(
                                $this->context->getLanguage()->pipeList( $links ) )->escaped();
-               // Show unmerge link
-               } elseif ( $type == 'merge' && $subtype == 'merge' ) {
-                       if ( !$this->context->getUser()->isAllowed( 'mergehistory' ) ) {
-                               return '';
-                       }
-
-                       $params = $this->extractParameters();
-                       $revert = Linker::linkKnown(
-                               SpecialPage::getTitleFor( 'MergeHistory' ),
-                               $this->msg( 'revertmerge' )->escaped(),
-                               array(),
-                               array(
-                                       'target' => $params[3],
-                                       'dest' => $title->getPrefixedDBkey(),
-                                       'mergepoint' => $params[4],
-                                       'submitted' => 1 // show the revisions immediately
-                               )
-                       );
-
-                       return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
                }
 
                // Do nothing. The implementation is handled by the hook modifiying the
index b0b23ba..d576d74 100644 (file)
@@ -382,19 +382,6 @@ class LogPage {
                                                . Linker::userToolLinks( $id, $title->getText(), false, Linker::TOOL_LINKS_NOBLOCK );
                                }
                                break;
-                       case 'merge':
-                               $titleLink = Linker::link(
-                                       $title,
-                                       $title->getPrefixedText(),
-                                       array(),
-                                       array( 'redirect' => 'no' )
-                               );
-                               $params[0] = Linker::link(
-                                       Title::newFromText( $params[0] ),
-                                       htmlspecialchars( $params[0] )
-                               );
-                               $params[1] = $lang->timeanddate( $params[1] );
-                               break;
                        default:
                                if ( $title->isSpecialPage() ) {
                                        list( $name, $par ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
diff --git a/includes/logging/MergeLogFormatter.php b/includes/logging/MergeLogFormatter.php
new file mode 100644 (file)
index 0000000..6680873
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Formatter for merge 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.24
+ */
+
+/**
+ * This class formats merge log entries.
+ *
+ * @since 1.24
+ */
+class MergeLogFormatter extends LogFormatter {
+       public function getPreloadTitles() {
+               $params = $this->extractParameters();
+
+               return array( Title::newFromText( $params[3] ) );
+       }
+
+       protected function getMessageParameters() {
+               $params = parent::getMessageParameters();
+               $oldname = $this->makePageLink( $this->entry->getTarget(), array( 'redirect' => 'no' ) );
+               $newname = $this->makePageLink( Title::newFromText( $params[3] ) );
+               $params[2] = Message::rawParam( $oldname );
+               $params[3] = Message::rawParam( $newname );
+               $params[4] = $this->context->getLanguage()->timeanddate( $params[4] );
+               return $params;
+       }
+
+       public function getActionLinks() {
+               if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
+                       || !$this->context->getUser()->isAllowed( 'mergehistory' )
+               ) {
+                       return '';
+               }
+
+               // Show unmerge link
+               $params = $this->extractParameters();
+               $revert = Linker::linkKnown(
+                       SpecialPage::getTitleFor( 'MergeHistory' ),
+                       $this->msg( 'revertmerge' )->escaped(),
+                       array(),
+                       array(
+                               'target' => $params[3],
+                               'dest' => $this->entry->getTarget()->getPrefixedDBkey(),
+                               'mergepoint' => $params[4],
+                               'submitted' => 1 // show the revisions immediately
+                       )
+               );
+
+               return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
+       }
+}
index 43f5a1b..c71ef76 100644 (file)
@@ -469,11 +469,16 @@ class SpecialMergeHistory extends SpecialPage {
                        return false;
                }
                # Update our logs
-               $log = new LogPage( 'merge' );
-               $log->addEntry(
-                       'merge', $targetTitle, $this->mComment,
-                       array( $destTitle->getPrefixedText(), $timestampLimit ), $this->getUser()
-               );
+               $logEntry = new ManualLogEntry( 'merge', 'merge' );
+               $logEntry->setPerformer( $this->getUser() );
+               $logEntry->setComment( $this->mComment );
+               $logEntry->setTarget( $targetTitle );
+               $logEntry->setParameters( array(
+                       '4::dest' => $destTitle->getPrefixedText(),
+                       '5::mergepoint' => $timestampLimit
+               ) );
+               $logId = $logEntry->insert();
+               $logEntry->publish( $logId );
 
                # @todo message should use redirect=no
                $this->getOutput()->addWikiText( $this->msg( 'mergehistory-success',
index e81131e..b6ee3c7 100644 (file)
        "revdelete-uname-unhid": "username unhidden",
        "revdelete-restricted": "applied restrictions to administrators",
        "revdelete-unrestricted": "removed restrictions for administrators",
+       "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",
        "logentry-move-move_redir": "$1 {{GENDER:$2|moved}} page $3 to $4 over redirect",
index 4712b05..e5ecc91 100644 (file)
        "mergehistory-reason": "{{Identical|Reason}}",
        "mergehistory-revisionrow": "{{Optional}}\nA revision row in the merge history page. Parameters:\n* $1 - a radio button to indicate a merge point\n* $2 - a link to the last revision of a page ({{msg-mw|Last}})\n* $3 - a page link\n* $4 - a user link\n* $5 - a revision size\n* $6 - a revision comment",
        "mergelog": "{{doc-logpage}}\n\nThis is the name of a log of merge actions done on [[Special:MergeHistory]]. This special page and this log is not enabled by default.",
-       "pagemerge-logentry": "This log message is used in a merge log entry.\n\nParameters:\n* $1 - the page name of the source of the content to be merged\n* $2 - the page into which the content is merged\n* $3 - 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.",
+       "pagemerge-logentry": "{{ignored}}This is ''logentry'' message only used on IRC.\n\nParameters:\n* $1 - the page name of the source of the content to be merged\n* $2 - the page into which the content is merged\n* $3 - 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.",
        "revertmerge": "Used as link text",
        "mergelogpagetext": "Description of the [{{canonicalurl:Special:Log|type=merge&user=&page=&year=&month=-1}} merge log], on the log. The associated [[Special:MergeHistory|Merge]] special page is not enabled by default.",
        "history-title": "Displayed as page title when you click on the \"history\" tab. Parameters:\n* $1 - the normal page title",
        "revdelete-uname-unhid": "Used on\n* {{msg-mw|logentry-delete-event}}\n* {{msg-mw|logentry-delete-revision}}\n* {{msg-mw|logentry-suppress-event}}\n* {{msg-mw|logentry-suppress-event}}",
        "revdelete-restricted": "Used as <code>$4</code> in the following messages when setting visibility restrictions for administrators:\n* {{msg-mw|Logentry-delete-event}}\n* {{msg-mw|Logentry-delete-revision}}\n* {{msg-mw|Logentry-suppress-event}}\n* {{msg-mw|Logentry-suppress-event}}",
        "revdelete-unrestricted": "Used as <code>$4</code> in the following messages when setting visibility restrictions for administrators:\n* {{msg-mw|Logentry-delete-event}}\n* {{msg-mw|Logentry-delete-revision}}\n* {{msg-mw|Logentry-suppress-event}}\n* {{msg-mw|Logentry-suppress-event}}",
+       "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.",
        "logentry-move-move_redir": "{{Logentry|[[Special:Log/move]]}}\nParameter $4, the target page, is also not visible to parser functions.",
index 98903f1..7c2ba1a 100644 (file)
@@ -46,6 +46,7 @@ class RecentChangeTest extends MediaWikiTestCase {
         * - protect/modifyprotect
         * - protect/unprotect
         * - upload/upload
+        * - merge/merge
         *
         * As well as the following Auto Edit Summaries:
         * - blank
@@ -229,6 +230,25 @@ class RecentChangeTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers LogFormatter::getIRCActionText
+        */
+       public function testIrcMsgForLogTypeMerge() {
+               $sep = $this->context->msg( 'colon-separator' )->text();
+
+               # merge/merge
+               $this->assertIRCComment(
+                       $this->context->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
+                               . $sep . $this->user_comment,
+                       'merge', 'merge',
+                       array(
+                               '4::dest' => 'Dest',
+                               '5::mergepoint' => 'timestamp',
+                       ),
+                       $this->user_comment
+               );
+       }
+
        /**
         * @todo Emulate these edits somehow and extract
         * raw edit summary from RecentChange object