Add option to mute/unmute notifications on Special:Mute

The hook (SpecialMuteModifyFormFields) is used to append
the option to mute/unmute echo notifications from a specified user.

Special:Mute handles posting and saving the fields, the only
requirement is that the field name is the same as the property
that wants to be modified, in this case 'echo-notifications-blacklist'

Bug: T220163
Depends-On: I2b3eee0802cb086091f35ecce13ae77a8e7d518d
Change-Id: I77b3ccfdce9b501eb8ecd58c0d7bbecb78029a7e
This commit is contained in:
Dayllan Maza 2019-07-01 13:49:31 -04:00 committed by Dbarratt
parent 64eb55c290
commit b3df45dc34
6 changed files with 30 additions and 10 deletions

View file

@ -15,7 +15,7 @@
"license-name": "MIT",
"type": "specialpage",
"requires": {
"MediaWiki": ">= 1.32.0"
"MediaWiki": ">= 1.34.0"
},
"APIMetaModules": {
"notifications": "ApiEchoNotifications",
@ -409,7 +409,8 @@
"SendWatchlistEmailNotification": "EchoHooks::onSendWatchlistEmailNotification",
"GetNewMessagesAlert": "EchoHooks::abortNewMessagesAlert",
"LinksUpdateAfterInsert": "EchoHooks::onLinksUpdateAfterInsert",
"ResourceLoaderGetConfigVars": "EchoHooks::onResourceLoaderGetConfigVars"
"ResourceLoaderGetConfigVars": "EchoHooks::onResourceLoaderGetConfigVars",
"SpecialMuteModifyFormFields": "EchoHooks::onSpecialMuteModifyFormFields"
},
"config": {
"EchoEnableEmailBatch": {

View file

@ -198,6 +198,7 @@
"notification-inbox-filter-read": "Read",
"notification-inbox-filter-unread": "Unread",
"notification-inbox-filter-all": "All",
"echo-specialmute-label-mute-notifications": "Mute notifications from this user",
"echo-email-plain-footer": "To control which emails we send {{GENDER:$1|you}}, check {{GENDER:$1|your}} preferences:",
"echo-email-html-footer-preference-link-text": "check {{GENDER:$1|your}} preferences",
"echo-email-html-footer-with-link": "To control which emails we send {{GENDER:$2|you}}, $1.",

View file

@ -198,6 +198,7 @@
"notification-inbox-filter-read": "Label for the button that shows only read notification.\n{{Identical|Read}}",
"notification-inbox-filter-unread": "Label for the button that shows only unread notification.\n{{Identical|Unread}}",
"notification-inbox-filter-all": "Label for the button that shows all notification.\n{{Identical|All}}",
"echo-specialmute-label-mute-notifications": "Label for the checkbox that mutes/unmutes notifications on [[Special:Mute]] from the specified user.",
"echo-email-plain-footer": "Footer content for Echo text e-mail notifications. Parameters:\n* $1 - the name of the user being addressed, used for GENDER\n\nFor HTML version, see {{msg-mw|echo-email-html-footer-with-link}}.",
"echo-email-html-footer-preference-link-text": "Text of link to the preference page in the footer of HTML emails. Parameters:\n* $1 - the name of the user being addressed, used for GENDER",
"echo-email-html-footer-with-link": "Footer content of the HTML email. Parameters:\n* $1 - complete HTML link to the preference page. $2 - the name of the user being addressed, used for GENDER\n\nSee {{msg-mw|echo-email-html-footer-preference-link-text}} for the text of the link.",

View file

@ -431,10 +431,11 @@ abstract class EchoDiscussionParser {
return $cache[$cacheKey];
}
global $wgParser;
$parser = MediaWikiServices::getInstance()->getParser();
$options = new ParserOptions;
$options->setTidy( true );
$output = $wgParser->parse( $wikitext, $article->getTitle(), $options );
$output = $parser->parse( $wikitext, $article->getTitle(), $options );
$cache[$cacheKey] = $output;
return $output;
@ -1023,7 +1024,7 @@ abstract class EchoDiscussionParser {
* - Second element is the normalised user name.
*/
public static function getUserFromLine( $line, Title $title = null ) {
global $wgParser;
$parser = MediaWikiServices::getInstance()->getParser();
/*
* First we call extractUsersFromLine to get all the potential usernames
@ -1038,7 +1039,7 @@ abstract class EchoDiscussionParser {
// discovered the signature from
// don't validate the username - anon (IP) is fine!
$user = User::newFromName( $username, false );
$sig = $wgParser->preSaveTransform(
$sig = $parser->preSaveTransform(
'~~~',
$title ?: Title::newMainPage(),
$user,
@ -1152,9 +1153,9 @@ abstract class EchoDiscussionParser {
$user = User::newFromName( 'Test' );
$options = new ParserOptions;
global $wgParser;
$parser = MediaWikiServices::getInstance()->getParser();
$exemplarTimestamp =
$wgParser->preSaveTransform( '~~~~~', $title, $user, $options );
$parser->preSaveTransform( '~~~~~', $title, $user, $options );
// Step 2: Generalise it
// Trim off the timezone to replace at the end

View file

@ -1521,4 +1521,20 @@ class EchoHooks {
return true;
}
/**
* Handler for SpecialMuteModifyFormFields hook
*
* @param SpecialMute $specialMute
* @param array &$fields
*/
public static function onSpecialMuteModifyFormFields( SpecialMute $specialMute, &$fields ) {
$echoPerUserBlacklist = MediaWikiServices::getInstance()->getMainConfig()->get( 'EchoPerUserBlacklist' );
if ( $echoPerUserBlacklist ) {
$fields[ 'echo-notifications-blacklist'] = [
'type' => 'check',
'label-message' => 'echo-specialmute-label-mute-notifications',
'default' => $specialMute->isTargetBlacklisted( 'echo-notifications-blacklist' ),
];
}
}
}

View file

@ -1494,9 +1494,9 @@ TEXT
$options = new ParserOptions;
global $wgParser;
$parser = MediaWikiServices::getInstance()->getParser();
$exemplarTimestamp =
$wgParser->preSaveTransform( '~~~~~', $title, $user, $options );
$parser->preSaveTransform( '~~~~~', $title, $user, $options );
return $exemplarTimestamp;
}