diff --git a/Echo.php b/Echo.php index 335ee4439..66e3aaf7d 100644 --- a/Echo.php +++ b/Echo.php @@ -179,6 +179,9 @@ $wgEchoMentionStatusNotifications = false; // Disable this when you want to disable mentions for multiple section edits. $wgEchoMentionsOnMultipleSectionEdits = true; +// Enable this to send out notifications for mentions on changes. +$wgEchoMentionOnChanges = 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 5c211f0c7..3793eb091 100644 --- a/includes/DiscussionParser.php +++ b/includes/DiscussionParser.php @@ -1,7 +1,6 @@ getPrevious() ) { $title = Title::newFromID( $revision->getPage() ); @@ -37,11 +38,6 @@ abstract class EchoDiscussionParser { $userID = $revision->getUser(); $userName = $revision->getUserText(); $user = $userID != 0 ? User::newFromId( $userID ) : User::newFromName( $userName, false ); - $logger = LoggerFactory::getInstance( 'Echo' ); - $diffUrl = $title->getFullURL( array( - 'oldid' => 'prev', - 'diff' => $revision->getId() - ) ); foreach ( $interpretation as $action ) { if ( $action['type'] == 'add-comment' ) { @@ -64,15 +60,10 @@ abstract class EchoDiscussionParser { self::getUserLinks( $action['new_content'], $title ) ?: [], self::getUserLinks( $action['old_content'], $title ) ?: [] ); - if ( $userLinks ) { - $logger->debug( - 'Potential mention on a change by {user} on {diff}', - array( - 'user' => $user->getName(), - 'diff' => $diffUrl, - 'user-links' => $userLinks, - ) - ); + $header = self::extractHeader( $action['full-section'] ); + + if ( $wgEchoMentionOnChanges ) { + self::generateMentionEvents( $header, $userLinks, $action['new_content'], $revision, $user ); } } } diff --git a/tests/phpunit/DiscussionParserTest.php b/tests/phpunit/DiscussionParserTest.php index 1630faa94..cf334c30c 100644 --- a/tests/phpunit/DiscussionParserTest.php +++ b/tests/phpunit/DiscussionParserTest.php @@ -531,6 +531,114 @@ class EchoDiscussionParserTest extends MediaWikiTestCase { 'notifyAgent' => true, ), ), + array( + 'new' => 987654322, + 'old' => 987654321, + 'username' => 'Admin', + 'lang' => 'en', + 'pages' => array(), + 'title' => 'User_talk:Admin', + 'expected' => array( array( + 'type' => 'edit-user-talk', + 'agent' => 'Admin', + 'section-title' => false, + 'subject-name' => null, + 'notifyAgent' => null, + ) ), + ), + array( + 'new' => 987654323, + 'old' => 987654321, + 'username' => 'Admin', + 'lang' => 'en', + 'pages' => array(), + 'title' => 'User_talk:Admin', + 'expected' => array( + array( + 'type' => 'mention', + 'agent' => 'Admin', + 'section-title' => 'Section 1', + 'subject-name' => null, + 'notifyAgent' => null, + ), + array( + 'type' => 'mention-success', + 'agent' => 'Admin', + 'section-title' => 'Section 1', + 'subject-name' => 'Test11', + 'notifyAgent' => true, + ), + array( + 'type' => 'edit-user-talk', + 'agent' => 'Admin', + 'section-title' => 'Section 1', + 'subject-name' => null, + 'notifyAgent' => null, + ), + ), + ), + ), + array( + 'new' => 987654324, + 'old' => 987654321, + 'username' => 'Admin', + 'lang' => 'en', + 'pages' => array(), + 'title' => 'User_talk:Admin', + 'expected' => array( + array( + 'type' => 'mention', + 'agent' => 'Admin', + 'section-title' => 'Section 1', + 'subject-name' => null, + 'notifyAgent' => null, + ), + array( + 'type' => 'mention-success', + 'agent' => 'Admin', + 'section-title' => 'Section 1', + 'subject-name' => 'Test11', + 'notifyAgent' => true, + ), + array( + 'type' => 'edit-user-talk', + 'agent' => 'Admin', + 'section-title' => false, + 'subject-name' => null, + 'notifyAgent' => null, + ), + ), + ), + array( + 'new' => 987654325, + 'old' => 987654321, + 'username' => 'Admin', + 'lang' => 'en', + 'pages' => array(), + 'title' => 'User_talk:Admin', + 'expected' => array( + array( + 'type' => 'mention', + 'agent' => 'Admin', + 'section-title' => 'Section 2', + 'subject-name' => null, + 'notifyAgent' => null, + ), + array( + 'type' => 'mention-success', + 'agent' => 'Admin', + 'section-title' => 'Section 2', + 'subject-name' => 'Test11', + 'notifyAgent' => true, + ), + array( + 'type' => 'edit-user-talk', + 'agent' => 'Admin', + 'section-title' => 'Section 2', + 'subject-name' => null, + 'notifyAgent' => null, + ), + ), ), ); } diff --git a/tests/phpunit/revision_txt/987654321.txt b/tests/phpunit/revision_txt/987654321.txt new file mode 100644 index 000000000..2d01e38a4 --- /dev/null +++ b/tests/phpunit/revision_txt/987654321.txt @@ -0,0 +1,2 @@ +== Section 1 == +Hi. diff --git a/tests/phpunit/revision_txt/987654322.txt b/tests/phpunit/revision_txt/987654322.txt new file mode 100644 index 000000000..b8a1722b4 --- /dev/null +++ b/tests/phpunit/revision_txt/987654322.txt @@ -0,0 +1,2 @@ +== Section 1 == +Hi [[User:Test11]]. diff --git a/tests/phpunit/revision_txt/987654323.txt b/tests/phpunit/revision_txt/987654323.txt new file mode 100644 index 000000000..cd1e6ca38 --- /dev/null +++ b/tests/phpunit/revision_txt/987654323.txt @@ -0,0 +1,4 @@ +== Section 1 == +Hi [[User:Test11]]. + +[[:User:Admin|Admin]] 23:47, 6 July 2015 (UTC) diff --git a/tests/phpunit/revision_txt/987654324.txt b/tests/phpunit/revision_txt/987654324.txt new file mode 100644 index 000000000..d30166d74 --- /dev/null +++ b/tests/phpunit/revision_txt/987654324.txt @@ -0,0 +1,2 @@ +== Section 1 == +Hi [[User:Test11]] - [[:User:Admin|Admin]] 23:47, 6 July 2015 (UTC) diff --git a/tests/phpunit/revision_txt/987654325.txt b/tests/phpunit/revision_txt/987654325.txt new file mode 100644 index 000000000..3ba1be74a --- /dev/null +++ b/tests/phpunit/revision_txt/987654325.txt @@ -0,0 +1,4 @@ +== Section 1 == +[[User:JarJar|JarJar]] +== Section 2 == +Hi [[User:Test11|Test11]] - [[:User:Admin|Admin]] 23:47, 6 July 2015 (UTC)