mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-09-23 10:22:05 +00:00
Merge "Send mentions when editing multiple sections in between sections."
This commit is contained in:
commit
5fd9831c07
3
Echo.php
3
Echo.php
|
@ -176,6 +176,9 @@ $wgEchoMaxMentionsCount = 50;
|
|||
// Enable this when you want to enable mention failure and success 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
|
||||
|
|
|
@ -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 )
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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' =>
|
||||
<<<TEXT
|
||||
== Headline ==
|
||||
|
@ -535,7 +616,7 @@ TEXT
|
|||
,
|
||||
'result' => array(
|
||||
array(
|
||||
'header' => '== Headline ==',
|
||||
'header' => 'Headline',
|
||||
'content' =>
|
||||
<<<TEXT
|
||||
== Headline ==
|
||||
|
@ -561,7 +642,7 @@ TEXT
|
|||
'content' => 'Content 0',
|
||||
),
|
||||
array(
|
||||
'header' => '== Headline 1 ==',
|
||||
'header' => 'Headline 1',
|
||||
'content' =>
|
||||
<<<TEXT
|
||||
== Headline 1 ==
|
||||
|
@ -570,7 +651,7 @@ TEXT
|
|||
,
|
||||
),
|
||||
array(
|
||||
'header' => '=== Headline 2 ===',
|
||||
'header' => 'Headline 2',
|
||||
'content' =>
|
||||
<<<TEXT
|
||||
=== Headline 2 ===
|
||||
|
@ -591,7 +672,7 @@ TEXT
|
|||
,
|
||||
'result' => array(
|
||||
array(
|
||||
'header' => '== Headline 1 ==',
|
||||
'header' => 'Headline 1',
|
||||
'content' =>
|
||||
<<<TEXT
|
||||
== Headline 1 ==
|
||||
|
@ -600,7 +681,7 @@ TEXT
|
|||
,
|
||||
),
|
||||
array(
|
||||
'header' => '=== Headline 2 ===',
|
||||
'header' => 'Headline 2',
|
||||
'content' =>
|
||||
<<<TEXT
|
||||
=== Headline 2 ===
|
||||
|
@ -628,7 +709,7 @@ TEXT
|
|||
,
|
||||
),
|
||||
array(
|
||||
'header' => '=== Headline 1 ===',
|
||||
'header' => 'Headline 1',
|
||||
'content' =>
|
||||
<<<TEXT
|
||||
=== Headline 1 ===
|
||||
|
|
25
tests/phpunit/revision_txt/747798770.txt
Normal file
25
tests/phpunit/revision_txt/747798770.txt
Normal file
|
@ -0,0 +1,25 @@
|
|||
Simultaneously edit multiple sections
|
||||
|
||||
== Section 1 ==
|
||||
|
||||
Content 1
|
||||
|
||||
New Content with userlink ( dont try to mention this one )
|
||||
|
||||
[[User:NoUser1]]
|
||||
|
||||
== Section 1.5 ==
|
||||
|
||||
New section in between with userlink & signature ( try to mention this one )
|
||||
|
||||
[[User:Test11]]
|
||||
|
||||
[[:User:Admin|Admin]] 13:22, 23 June 2016 (UTC)
|
||||
|
||||
== Section 2 ==
|
||||
|
||||
Content 2
|
||||
|
||||
New Content with userlink ( dont try to mention this one )
|
||||
|
||||
[[User:NoUser2]]
|
27
tests/phpunit/revision_txt/747798771.txt
Normal file
27
tests/phpunit/revision_txt/747798771.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
Simultaneously edit multiple sections
|
||||
|
||||
== Section 1 ==
|
||||
|
||||
Content 1
|
||||
|
||||
New Content with userlink ( dont try to mention this one )
|
||||
|
||||
[[User:NoUser1]]
|
||||
|
||||
== Section 1.5 ==
|
||||
|
||||
New section in between with userlink & signature ( try to mention this one )
|
||||
|
||||
[[User:NoUser1.5]]
|
||||
|
||||
[[:User:Admin|Admin]] 13:22, 23 June 2016 (UTC)
|
||||
|
||||
== Section 2 ==
|
||||
|
||||
Content 2
|
||||
|
||||
New Content with userlink & signature ( try to mention this one )
|
||||
|
||||
[[User:NoUser2]]
|
||||
|
||||
[[:User:Admin|Admin]] 13:22, 23 June 2016 (UTC)
|
35
tests/phpunit/revision_txt/747798772.txt
Normal file
35
tests/phpunit/revision_txt/747798772.txt
Normal file
|
@ -0,0 +1,35 @@
|
|||
Simultaneously edit multiple sections
|
||||
|
||||
== Section 1 ==
|
||||
|
||||
Content 1
|
||||
|
||||
New Content with userlink & signature ( try to mention this one )
|
||||
|
||||
[[User:NoUser1]]
|
||||
|
||||
[[:User:Admin|Admin]] 13:22, 23 June 2016 (UTC)
|
||||
|
||||
== Section 1.5 ==
|
||||
|
||||
New section in between with userlink ( don't try to mention this one )
|
||||
|
||||
[[User:NoUser1.5]]
|
||||
|
||||
== Section 1.75 ==
|
||||
|
||||
New section in between with userlink & signature ( try to mention this one )
|
||||
|
||||
[[User:NoUser1.75]]
|
||||
|
||||
[[:User:Admin|Admin]] 13:22, 23 June 2016 (UTC
|
||||
|
||||
== Section 2 ==
|
||||
|
||||
Content 2
|
||||
|
||||
New Content with userlink & signature ( try to mention this one )
|
||||
|
||||
[[User:NoUser2]]
|
||||
|
||||
[[:User:Admin|Admin]] 13:22, 23 June 2016 (UTC)
|
Loading…
Reference in a new issue