From 52f5634ba0f3b65d1ab6b87790c4adee2780901d Mon Sep 17 00:00:00 2001 From: umherirrender Date: Mon, 4 Aug 2014 19:10:51 +0200 Subject: [PATCH] Migrate merge log to new log system 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 | 1 + includes/DefaultSettings.php | 2 +- includes/api/ApiQueryLogEvents.php | 11 +++ includes/logging/LogFormatter.php | 26 ++----- includes/logging/LogPage.php | 13 ---- includes/logging/MergeLogFormatter.php | 70 +++++++++++++++++++ includes/specials/SpecialMergeHistory.php | 15 ++-- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 3 +- .../includes/changes/RecentChangeTest.php | 20 ++++++ 10 files changed, 122 insertions(+), 40 deletions(-) create mode 100644 includes/logging/MergeLogFormatter.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index a564ce6787..6936570ae2 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -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', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index cd65ffea52..af36a64d17 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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', ); /** diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index f83fe6905a..eb5ca4f523 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -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(); diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 48a565f2cf..bbe2f42975 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -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 diff --git a/includes/logging/LogPage.php b/includes/logging/LogPage.php index b0b23babe4..d576d74902 100644 --- a/includes/logging/LogPage.php +++ b/includes/logging/LogPage.php @@ -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 index 0000000000..6680873906 --- /dev/null +++ b/includes/logging/MergeLogFormatter.php @@ -0,0 +1,70 @@ +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(); + } +} diff --git a/includes/specials/SpecialMergeHistory.php b/includes/specials/SpecialMergeHistory.php index 43f5a1bafc..c71ef76dec 100644 --- a/includes/specials/SpecialMergeHistory.php +++ b/includes/specials/SpecialMergeHistory.php @@ -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', diff --git a/languages/i18n/en.json b/languages/i18n/en.json index e81131e7bb..b6ee3c76c0 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3393,6 +3393,7 @@ "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", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 4712b0525e..e5ecc9168c 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1007,7 +1007,7 @@ "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", @@ -3556,6 +3556,7 @@ "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 $4 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 $4 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.", diff --git a/tests/phpunit/includes/changes/RecentChangeTest.php b/tests/phpunit/includes/changes/RecentChangeTest.php index 98903f1e46..7c2ba1a995 100644 --- a/tests/phpunit/includes/changes/RecentChangeTest.php +++ b/tests/phpunit/includes/changes/RecentChangeTest.php @@ -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 -- 2.20.1