mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-12 01:10:07 +00:00
Send notification for mentions on changes
This sends out a notification when a user gets mentioned in a change as long as a signature is added in the same section. Bug: T138938 Change-Id: Ie183fbb8150bd9451a5b0a9fea0227e3241b26a0
This commit is contained in:
parent
5fd9831c07
commit
3da89ea4d9
3
Echo.php
3
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
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
|
||||
abstract class EchoDiscussionParser {
|
||||
const HEADER_REGEX = '^(==+)\s*([^=].*)\s*\1$';
|
||||
|
@ -19,6 +18,8 @@ abstract class EchoDiscussionParser {
|
|||
*/
|
||||
static function generateEventsForRevision( Revision $revision ) {
|
||||
global $wgEchoMentionsOnMultipleSectionEdits;
|
||||
global $wgEchoMentionOnChanges;
|
||||
|
||||
// use slave database if there is a previous revision
|
||||
if ( $revision->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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
2
tests/phpunit/revision_txt/987654321.txt
Normal file
2
tests/phpunit/revision_txt/987654321.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
== Section 1 ==
|
||||
Hi.
|
2
tests/phpunit/revision_txt/987654322.txt
Normal file
2
tests/phpunit/revision_txt/987654322.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
== Section 1 ==
|
||||
Hi [[User:Test11]].
|
4
tests/phpunit/revision_txt/987654323.txt
Normal file
4
tests/phpunit/revision_txt/987654323.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
== Section 1 ==
|
||||
Hi [[User:Test11]].
|
||||
|
||||
[[:User:Admin|Admin]] 23:47, 6 July 2015 (UTC)
|
2
tests/phpunit/revision_txt/987654324.txt
Normal file
2
tests/phpunit/revision_txt/987654324.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
== Section 1 ==
|
||||
Hi [[User:Test11]] - [[:User:Admin|Admin]] 23:47, 6 July 2015 (UTC)
|
4
tests/phpunit/revision_txt/987654325.txt
Normal file
4
tests/phpunit/revision_txt/987654325.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
== Section 1 ==
|
||||
[[User:JarJar|JarJar]]
|
||||
== Section 2 ==
|
||||
Hi [[User:Test11|Test11]] - [[:User:Admin|Admin]] 23:47, 6 July 2015 (UTC)
|
Loading…
Reference in a new issue