Cenarium has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/336627 )

Change subject: Remove legacy code from hooks
......................................................................

Remove legacy code from hooks

This removes legacy code that was needed until the merge of
I130d5b8104e5c794c246a769e26dc460bc45928c.
In particular, the RollbackComplete hook handler is removed.

Change-Id: I484acd080ac6e8cab9049f5368a155f92b552c75
---
M Hooks.php
M extension.json
2 files changed, 32 insertions(+), 97 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/27/336627/1

diff --git a/Hooks.php b/Hooks.php
index 08ee2c2..6809900 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -574,57 +574,37 @@
 
                // Handle the case of someone reverting an edit, either through 
the
                // 'undo'/'rollback' link in the article history or via the API.
-               if ( isset( $wgEchoNotifications['reverted'] ) ) {
-                       if ( class_exists( 'Revert' ) && $revert instanceof 
Revert ) {
-                               $affectedRevsToUsers = []; // revid -> userid
-                               $revisions = wfGetDB( DB_SLAVE )->select(
-                                       'revision',
-                                       [ 'rev_id', 'rev_user' ],
-                                       [
-                                               'rev_id <= ' . 
$revert->getRevertedId(),
-                                               'rev_id > ' . 
$revert->getRestoredId(),
-                                               'rev_page' => $article->getId(),
+               if ( isset( $wgEchoNotifications['reverted'] ) && $revert !== 
null ) {
+                       $affectedRevsToUsers = []; // revid -> userid
+                       $revisions = wfGetDB( DB_SLAVE )->select(
+                               'revision',
+                               [ 'rev_id', 'rev_user' ],
+                               [
+                                       'rev_id <= ' . $revert->getRevertedId(),
+                                       'rev_id > ' . $revert->getRestoredId(),
+                                       'rev_page' => $article->getId(),
+                               ],
+                               __METHOD__,
+                               [ 'ORDER BY rev_timestamp DESC', 'LIMIT' => 50 ]
+                       );
+                       foreach ( $revisions as $row ) {
+                               if ( $row->rev_user ) { // No notifications for 
anonymous users
+                                       $affectedRevsToUsers[$row->rev_id] = 
$row->rev_user;
+                               }
+                       }
+                       if ( $affectedRevsToUsers ) {
+                               $isAutoSummary = $autoSummHash && ( md5( 
$summary ) === $autoSummHash );
+                               EchoEvent::create( [
+                                       'type' => 'reverted',
+                                       'title' => $title,
+                                       'extra' => [
+                                               'revid' => $revision->getId(),
+                                               'reverted-revs-to-user-ids' => 
$affectedRevsToUsers,
+                                               'summary' => $summary,
+                                               'isAutoSummary' => 
$isAutoSummary,
                                        ],
-                                       __METHOD__,
-                                       [ 'ORDER BY rev_timestamp DESC', 
'LIMIT' => 50 ]
-                               );
-                               foreach ( $revisions as $row ) {
-                                       if ( $row->rev_user ) { // No 
notifications for anonymous users
-                                               
$affectedRevsToUsers[$row->rev_id] = $row->rev_user;
-                                       }
-                               }
-                               if ( $affectedRevsToUsers ) {
-                                       $isAutoSummary = $autoSummHash && ( 
md5( $summary ) === $autoSummHash );
-                                       EchoEvent::create( [
-                                               'type' => 'reverted',
-                                               'title' => $title,
-                                               'extra' => [
-                                                       'revid' => 
$revision->getId(),
-                                                       
'reverted-revs-to-user-ids' => $affectedRevsToUsers,
-                                                       'summary' => $summary,
-                                                       'isAutoSummary' => 
$isAutoSummary,
-                                               ],
-                                               'agent' => $user,
-                                       ] );
-                               }
-                       } elseif ( $revert !== 0 ) { // legacy
-                               // TODO: remove once 
I130d5b8104e5c794c246a769e26dc460bc45928c is merged
-                               $undidRevision = Revision::newFromId( $revert );
-                               if ( $undidRevision && 
$undidRevision->getTitle()->equals( $title ) ) {
-                                       $victimId = $undidRevision->getUser();
-                                       if ( $victimId ) { // No notifications 
for anonymous users
-                                               EchoEvent::create( [
-                                                       'type' => 'reverted',
-                                                       'title' => $title,
-                                                       'extra' => [
-                                                               'revid' => 
$revision->getId(),
-                                                               
'reverted-revs-to-user-ids' => [ $revert => $victimId ],
-                                                               'summary' => 
$summary,
-                                                       ],
-                                                       'agent' => $user,
-                                               ] );
-                                       }
-                               }
+                                       'agent' => $user,
+                               ] );
                        }
                }
 
@@ -758,9 +738,6 @@
         * @return bool
         */
        public static function onLinksUpdateAfterInsert( $linksUpdate, $table, 
$insertions ) {
-               $isRevert = is_callable( [ $linksUpdate, 'getRevert' ] ) &&
-                       $linksUpdate->getRevert() !== null;
-
                // Handle only
                // 1. inserts to pagelinks table &&
                // 2. content namespace pages &&
@@ -769,17 +746,12 @@
                // 5. edits that are not exact reverts
                if ( $table !== 'pagelinks' || !MWNamespace::isContent( 
$linksUpdate->mTitle->getNamespace() )
                        || !$linksUpdate->mRecursive || 
$linksUpdate->mTitle->isRedirect() ||
-                       ( $isRevert && $linksUpdate->getRevert()->isExact() )
+                       ( $linksUpdate->getRevert() !== null && 
$linksUpdate->getRevert()->isExact() )
                ) {
                        return true;
                }
 
-               if ( is_callable( [ $linksUpdate, 'getTriggeringUser' ] ) ) {
-                       $user = $linksUpdate->getTriggeringUser();
-               } else {
-                       global $wgUser;
-                       $user = $wgUser;
-               }
+               $user = $linksUpdate->getTriggeringUser();
 
                $revid = $linksUpdate->getRevision() ? 
$linksUpdate->getRevision()->getId() : null;
 
@@ -1161,42 +1133,6 @@
                        // show new messages alert
                        return true;
                }
-       }
-
-       /**
-        * @todo: remove this once I130d5b8104e5c794c246a769e26dc460bc45928c is 
merged
-        * Handler for ArticleRollbackComplete hook.
-        * @see 
http://www.mediawiki.org/wiki/Manual:Hooks/ArticleRollbackComplete
-        * @param $page WikiPage The article that was edited
-        * @param $agent User The user who did the rollback
-        * @param $newRevision Revision The revision the page was reverted back 
to
-        * @param $oldRevision Revision The revision of the top edit that was 
reverted
-        * @return bool true in all cases
-        */
-       public static function onRollbackComplete( $page, $agent, $newRevision, 
$oldRevision ) {
-               if ( class_exists( 'Revert' ) ) {
-                       return true; // already handled by 
onPageContentSaveComplete
-               }
-               $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' => $page->getTitle(),
-                               'extra' => [
-                                       'revid' => 
$page->getRevision()->getId(),
-                                       'reverted-user-id' => $victimId,
-                                       'reverted-revision-id' => 
$oldRevision->getId(),
-                                       'method' => 'rollback',
-                               ],
-                               'agent' => $agent,
-                       ] );
-               }
-
-               return true;
        }
 
        /**
diff --git a/extension.json b/extension.json
index 9cdcce0..e408649 100644
--- a/extension.json
+++ b/extension.json
@@ -554,7 +554,6 @@
                "EchoAbortEmailNotification": 
"EchoHooks::onEchoAbortEmailNotification",
                "PageContentSaveComplete": 
"EchoHooks::onPageContentSaveComplete",
                "LocalUserCreated": "EchoHooks::onLocalUserCreated",
-               "ArticleRollbackComplete": "EchoHooks::onRollbackComplete",
                "UserSaveSettings": "EchoHooks::onUserSaveSettings",
                "AbortTalkPageEmailNotification": 
"EchoHooks::onAbortTalkPageEmailNotification",
                "SendWatchlistEmailNotification": 
"EchoHooks::onSendWatchlistEmailNotification",

-- 
To view, visit https://gerrit.wikimedia.org/r/336627
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I484acd080ac6e8cab9049f5368a155f92b552c75
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Cenarium <cenarium.sy...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to