diff --git a/Echo.php b/Echo.php index 9d4e08fed..5d292ede3 100644 --- a/Echo.php +++ b/Echo.php @@ -176,6 +176,9 @@ $wgEchoMaxMentionsCount = 50; // Enable this when you want to enable mention failure notifications for the users. $wgEchoMentionStatusNotifications = false; +// Disable this when you want to disable mentions for multiple section edits. +$wgEchoMentionsOnMultipleSectionEdits = true; + // The time interval between each bundle email in seconds // set a small number for test wikis, should set this to 0 to disable email bundling // if there is no delay queue support diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php index ff632821b..5c211f0c7 100644 --- a/includes/DiscussionParser.php +++ b/includes/DiscussionParser.php @@ -18,6 +18,7 @@ abstract class EchoDiscussionParser { * @return null */ static function generateEventsForRevision( Revision $revision ) { + global $wgEchoMentionsOnMultipleSectionEdits; // use slave database if there is a previous revision if ( $revision->getPrevious() ) { $title = Title::newFromID( $revision->getPage() ); @@ -53,20 +54,11 @@ abstract class EchoDiscussionParser { $header = self::extractHeader( $content ); $userLinks = self::getUserLinks( $content, $title ); self::generateMentionEvents( $header, $userLinks, $content, $revision, $user ); - } elseif ( $action['type'] == 'add-section-multiple' ) { + } elseif ( $action['type'] == 'add-section-multiple' && $wgEchoMentionsOnMultipleSectionEdits ) { $content = self::stripHeader( $action['content'] ); $content = self::stripSignature( $content ); $userLinks = self::getUserLinks( $content, $title ); - if ( $userLinks ) { - $logger->debug( - 'Triggered add-section-multiple action with user links by {user} on {diff}', - array( - 'user' => $user->getName(), - 'diff' => $diffUrl, - 'user-links' => $userLinks, - ) - ); - } + self::generateMentionEvents( $action['header'], $userLinks, $content, $revision, $user ); } elseif ( $action['type'] === 'unknown-signed-change' ) { $userLinks = array_diff_key( self::getUserLinks( $action['new_content'], $title ) ?: [], @@ -757,7 +749,7 @@ abstract class EchoDiscussionParser { $content = substr( $text, $matches[0][$i][1] ); } $sections[] = array( - 'header' => $matches[0][$i][0], + 'header' => self::extractHeader( $matches[0][$i][0] ), 'content' => trim( $content ) ); } diff --git a/tests/phpunit/DiscussionParserTest.php b/tests/phpunit/DiscussionParserTest.php index 3dc91bce8..1630faa94 100644 --- a/tests/phpunit/DiscussionParserTest.php +++ b/tests/phpunit/DiscussionParserTest.php @@ -453,6 +453,85 @@ class EchoDiscussionParserTest extends MediaWikiTestCase { 'title' => 'UTPage', 'expected' => array(), ), + array( + 'new' => 747798770, + 'old' => 747798765, + 'username' => 'Admin', + 'lang' => 'en', + 'pages' => array(), + 'title' => 'UTPage', + 'expected' => array( + array( + 'type' => 'mention', + 'agent' => 'Admin', + 'section-title' => 'Section 1.5', + 'subject-name' => null, + 'notifyAgent' => null, + ), + array( + 'type' => 'mention-success', + 'agent' => 'Admin', + 'section-title' => 'Section 1.5', + 'subject-name' => 'Test11', + 'notifyAgent' => true, + ), + ), + ), + array( + 'new' => 747798771, + 'old' => 747798765, + 'username' => 'Admin', + 'lang' => 'en', + 'pages' => array(), + 'title' => 'UTPage', + 'expected' => array( + array( + 'type' => 'mention-failure', + 'agent' => 'Admin', + 'section-title' => 'Section 1.5', + 'subject-name' => 'NoUser1.5', + 'notifyAgent' => true, + ), + array( + 'type' => 'mention-failure', + 'agent' => 'Admin', + 'section-title' => 'Section 2', + 'subject-name' => 'NoUser2', + 'notifyAgent' => true, + ), + ), + ), + array( + 'new' => 747798772, + 'old' => 747798765, + 'username' => 'Admin', + 'lang' => 'en', + 'pages' => array(), + 'title' => 'UTPage', + 'expected' => array( + array( + 'type' => 'mention-failure', + 'agent' => 'Admin', + 'section-title' => 'Section 1', + 'subject-name' => 'NoUser1', + 'notifyAgent' => true, + ), + array( + 'type' => 'mention-failure', + 'agent' => 'Admin', + 'section-title' => 'Section 1.75', + 'subject-name' => 'NoUser1.75', + 'notifyAgent' => true, + ), + array( + 'type' => 'mention-failure', + 'agent' => 'Admin', + 'section-title' => 'Section 2', + 'subject-name' => 'NoUser2', + 'notifyAgent' => true, + ), + ), + ), ); } @@ -481,6 +560,8 @@ class EchoDiscussionParserTest extends MediaWikiTestCase { // enable mention failure and success notifications $this->setMwGlobals( 'wgEchoMentionStatusNotifications', true ); + // enable multiple sections mentions + $this->setMwGlobals( 'wgEchoMentionsOnMultipleSectionEdits', true ); EchoDiscussionParser::generateEventsForRevision( $revision ); @@ -516,7 +597,7 @@ TEXT , ), array( - 'header' => '== Headline ==', + 'header' => 'Headline', 'content' => << array( array( - 'header' => '== Headline ==', + 'header' => 'Headline', 'content' => << 'Content 0', ), array( - 'header' => '== Headline 1 ==', + 'header' => 'Headline 1', 'content' => << '=== Headline 2 ===', + 'header' => 'Headline 2', 'content' => << array( array( - 'header' => '== Headline 1 ==', + 'header' => 'Headline 1', 'content' => << '=== Headline 2 ===', + 'header' => 'Headline 2', 'content' => << '=== Headline 1 ===', + 'header' => 'Headline 1', 'content' => <<