From 6229cadd2e8155719b33c1abcdca1342e1563901 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Mon, 26 Mar 2018 11:54:03 -0700 Subject: [PATCH] Revert my fix for summary pings in reverts To redo more properly. This reverts commit 74eacad8d646c6a2b17775dd8e37fd48108ab469. Bug: T190374 Change-Id: If178ed1a497df5276894f86d7a3312811651ce6b --- Hooks.php | 63 ++++++++++--------- extension.json | 1 + .../formatters/RevertedPresentationModel.php | 10 +-- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Hooks.php b/Hooks.php index d8fce4fa8..e08ea9615 100644 --- a/Hooks.php +++ b/Hooks.php @@ -598,15 +598,14 @@ class EchoHooks { if ( $undidRevision && $undidRevision->getTitle()->equals( $title ) ) { $victimId = $undidRevision->getUser(); if ( $victimId ) { // No notifications for anonymous users - $revisionCount = self::countRevisions( $wikiPage->getId(), $baseRevId, $undidRevId ); EchoEvent::create( [ 'type' => 'reverted', 'title' => $title, 'extra' => [ 'revid' => $revision->getId(), 'reverted-user-id' => $victimId, - 'reverted-revision-count' => $revisionCount, 'reverted-revision-id' => $undidRevId, + 'method' => 'undo', 'summary' => $summary, ], 'agent' => $user, @@ -618,32 +617,6 @@ class EchoHooks { return true; } - /** - * Counts revisions int a page between two given revisions - * - * @param int $pageId - * @param int $revIdFrom - * @param int $revIdTo - * @return bool|int - */ - private static function countRevisions( $pageId, $revIdFrom, $revIdTo ) { - // The edit has just been made, can't guarantee it's on replicas - $dbw = wfGetDB( DB_MASTER ); - $count = $dbw->selectField( 'revision', - 'COUNT(*)', - [ - 'rev_page' => $pageId, - "rev_id > {$dbw->addQuotes( $revIdFrom )}", - "rev_id <= {$dbw->addQuotes( $revIdTo )}", - ], - __METHOD__ - ); - if ( $count !== false ) { - $count = (int)$count; - } - return $count; - } - /** * Handler for EchoAbortEmailNotification hook * @param User $user @@ -1213,6 +1186,40 @@ class EchoHooks { } } + /** + * Handler for ArticleRollbackComplete hook. + * @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleRollbackComplete + * + * @param WikiPage $wikiPage The article that was edited + * @param User $agent The user who did the rollback + * @param Revision $newRevision The revision the page was reverted back to + * @param Revision $oldRevision The revision of the top edit that was reverted + * + * @return bool true in all cases + */ + public static function onRollbackComplete( WikiPage $wikiPage, $agent, $newRevision, $oldRevision ) { + $victimId = $oldRevision->getUser(); + + if ( + $victimId && // No notifications for anonymous users + !$oldRevision->getContent()->equals( $newRevision->getContent() ) // No notifications for null rollbacks + ) { + EchoEvent::create( [ + 'type' => 'reverted', + 'title' => $wikiPage->getTitle(), + 'extra' => [ + 'revid' => $wikiPage->getRevision()->getId(), + 'reverted-user-id' => $victimId, + 'reverted-revision-id' => $oldRevision->getId(), + 'method' => 'rollback', + ], + 'agent' => $agent, + ] ); + } + + return true; + } + /** * Handler for UserSaveSettings hook. * @see http://www.mediawiki.org/wiki/Manual:Hooks/UserSaveSettings diff --git a/extension.json b/extension.json index b585418b4..2649b05df 100644 --- a/extension.json +++ b/extension.json @@ -435,6 +435,7 @@ "EchoAbortEmailNotification": "EchoHooks::onEchoAbortEmailNotification", "PageContentSaveComplete": "EchoHooks::onPageContentSaveComplete", "LocalUserCreated": "EchoHooks::onLocalUserCreated", + "ArticleRollbackComplete": "EchoHooks::onRollbackComplete", "UserSaveSettings": "EchoHooks::onUserSaveSettings", "AbortTalkPageEmailNotification": "EchoHooks::onAbortTalkPageEmailNotification", "SendWatchlistEmailNotification": "EchoHooks::onSendWatchlistEmailNotification", diff --git a/includes/formatters/RevertedPresentationModel.php b/includes/formatters/RevertedPresentationModel.php index b7e8a1b04..04d63b939 100644 --- a/includes/formatters/RevertedPresentationModel.php +++ b/includes/formatters/RevertedPresentationModel.php @@ -62,18 +62,12 @@ class EchoRevertedPresentationModel extends EchoEventPresentationModel { * @return int */ private function getNumberOfEdits() { - // b/c for old notifications $method = $this->event->getExtraParam( 'method' ); if ( $method && $method === 'rollback' ) { return 2; + } else { + return 1; } - - $count = $this->event->getExtraParam( 'reverted-revision-count' ); - if ( $count > 0 ) { - return $count; - } - // "Educated guess" - return 1; } private function isAutomaticSummary( $summary ) {