Use UserGetDefaultOptions hook instead of $wgExtensionFunctions

$wgExtensionFunctions are run on every MediaWiki request, and should be
avoided unless necessary. Default user options should be controlled by
the UserGetDefaultOptions hook instead.

Bug: T180192
Change-Id: I2a79e078753d289c3ea2f04b613ce72c59a9e59a
This commit is contained in:
Kunal Mehta 2018-07-25 17:19:17 -07:00
parent 70d07878c9
commit 9f2383a727
2 changed files with 20 additions and 12 deletions

View file

@ -415,6 +415,7 @@
"UserGroupsChanged": "EchoHooks::onUserGroupsChanged",
"UserLoadOptions": "EchoHooks::onUserLoadOptions",
"UserSaveOptions": "EchoHooks::onUserSaveOptions",
"UserGetDefaultOptions": "EchoHooks::onUserGetDefaultOptions",
"UserClearNewTalkNotification": "EchoHooks::onUserClearNewTalkNotification",
"ParserTestTables": "EchoHooks::onParserTestTables",
"EmailUserComplete": "EchoHooks::onEmailUserComplete",

View file

@ -12,29 +12,36 @@ class EchoHooks {
private static $lastRevertedRevision = null;
public static function registerExtension() {
global $wgNotificationSender, $wgPasswordSender, $wgAllowHTMLEmail,
$wgEchoNotificationCategories, $wgDefaultUserOptions;
global $wgNotificationSender, $wgPasswordSender;
$wgNotificationSender = $wgPasswordSender;
}
/**
* @param array &$defaults
*/
public static function onUserGetDefaultOptions( array &$defaults ) {
global $wgAllowHTMLEmail, $wgEchoNotificationCategories;
if ( $wgAllowHTMLEmail ) {
$wgDefaultUserOptions['echo-email-format'] = 'html'; /*EchoHooks::EMAIL_FORMAT_HTML*/
$defaults['echo-email-format'] = 'html'; /*EchoHooks::EMAIL_FORMAT_HTML*/
} else {
$wgDefaultUserOptions['echo-email-format'] = 'plain-text'; /*EchoHooks::EMAIL_FORMAT_PLAIN_TEXT*/
$defaults['echo-email-format'] = 'plain-text'; /*EchoHooks::EMAIL_FORMAT_PLAIN_TEXT*/
}
// Set all of the events to notify by web but not email by default (won't affect events that don't email)
// Set all of the events to notify by web but not email by default
// (won't affect events that don't email)
foreach ( $wgEchoNotificationCategories as $category => $categoryData ) {
$wgDefaultUserOptions["echo-subscriptions-email-{$category}"] = false;
$wgDefaultUserOptions["echo-subscriptions-web-{$category}"] = true;
$defaults["echo-subscriptions-email-{$category}"] = false;
$defaults["echo-subscriptions-web-{$category}"] = true;
}
// most settings default to web on, email off, but override these
$wgDefaultUserOptions['echo-subscriptions-email-system'] = true;
$wgDefaultUserOptions['echo-subscriptions-email-user-rights'] = true;
$wgDefaultUserOptions['echo-subscriptions-web-article-linked'] = false;
$wgDefaultUserOptions['echo-subscriptions-web-mention-failure'] = false;
$wgDefaultUserOptions['echo-subscriptions-web-mention-success'] = false;
$defaults['echo-subscriptions-email-system'] = true;
$defaults['echo-subscriptions-email-user-rights'] = true;
$defaults['echo-subscriptions-web-article-linked'] = false;
$defaults['echo-subscriptions-web-mention-failure'] = false;
$defaults['echo-subscriptions-web-mention-success'] = false;
}
/**