Merge "SpecialDisplayNotificationsConfiguration: Fix default values of core prefs"

This commit is contained in:
jenkins-bot 2021-07-27 18:32:19 +00:00 committed by Gerrit Code Review
commit 9e9303221e
2 changed files with 39 additions and 33 deletions

View file

@ -1291,6 +1291,23 @@ class EchoHooks implements RecentChange_saveHook {
}
}
/**
* Some of Echo's subscription user preferences are mapped to existing user preferences defined in
* core MediaWiki. This returns the map of Echo preference names to core preference names.
*
* @return array
*/
public static function getVirtualUserOptions() {
global $wgEchoWatchlistNotifications;
$options = [];
$options['echo-subscriptions-email-edit-user-talk'] = 'enotifusertalkpages';
if ( $wgEchoWatchlistNotifications ) {
$options['echo-subscriptions-email-watchlist'] = 'enotifwatchlistpages';
$options['echo-subscriptions-email-minor-watchlist'] = 'enotifminoredits';
}
return $options;
}
/**
* Handler for UserLoadOptions hook.
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserLoadOptions
@ -1298,21 +1315,10 @@ class EchoHooks implements RecentChange_saveHook {
* @param array &$options Options can be modified
*/
public static function onUserLoadOptions( $user, &$options ) {
global $wgEchoWatchlistNotifications;
// Use existing enotifusertalkpages option for echo-subscriptions-email-edit-user-talk
if ( isset( $options['enotifusertalkpages'] ) ) {
$options['echo-subscriptions-email-edit-user-talk'] = $options['enotifusertalkpages'];
}
if ( $wgEchoWatchlistNotifications ) {
// Use existing enotifwatchlistpages option for echo-subscriptions-email-watchlist
if ( isset( $options['enotifwatchlistpages'] ) ) {
$options['echo-subscriptions-email-watchlist'] = $options['enotifwatchlistpages'];
}
// Use existing enotifminoredits option for echo-subscriptions-email-minor-watchlist
if ( isset( $options['enotifminoredits'] ) ) {
$options['echo-subscriptions-email-minor-watchlist'] = $options['enotifminoredits'];
foreach ( self::getVirtualUserOptions() as $echoPref => $mwPref ) {
// Use the existing core option's value for the Echo option
if ( isset( $options[ $mwPref ] ) ) {
$options[ $echoPref ] = $options[ $mwPref ];
}
}
}
@ -1324,20 +1330,11 @@ class EchoHooks implements RecentChange_saveHook {
* @param array &$options Options can be modified
*/
public static function onUserSaveOptions( $user, &$options ) {
global $wgEchoWatchlistNotifications;
// save virtual option values in corresponding real option values
if ( isset( $options['echo-subscriptions-email-edit-user-talk'] ) ) {
$options['enotifusertalkpages'] = $options['echo-subscriptions-email-edit-user-talk'];
unset( $options['echo-subscriptions-email-edit-user-talk'] );
}
if ( $wgEchoWatchlistNotifications ) {
if ( isset( $options['echo-subscriptions-email-watchlist'] ) ) {
$options['enotifwatchlistpages'] = $options['echo-subscriptions-email-watchlist'];
unset( $options['echo-subscriptions-email-watchlist'] );
}
if ( isset( $options['echo-subscriptions-email-minor-watchlist'] ) ) {
$options['enotifminoredits'] = $options['echo-subscriptions-email-minor-watchlist'];
unset( $options['echo-subscriptions-email-minor-watchlist'] );
foreach ( self::getVirtualUserOptions() as $echoPref => $mwPref ) {
// Save virtual option values in corresponding real option values
if ( isset( $options[ $echoPref ] ) ) {
$options[ $mwPref ] = $options[ $echoPref ];
unset( $options[ $echoPref ] );
}
}
}

View file

@ -269,14 +269,20 @@ class SpecialDisplayNotificationsConfiguration extends UnlistedSpecialPage {
$this->msg( 'echo-displaynotificationsconfiguration-enabled-default-header' )->text()
) );
// Some of the preferences are mapped to existing ones defined in core MediaWiki
$virtualOptions = EchoHooks::getVirtualUserOptions();
// In reality, anon users are not relevant to Echo, but this lets us easily query default options.
$anonUser = new User;
$byCategoryValueExisting = [];
foreach ( $this->notifyTypes as $notifyType => $displayNotifyType ) {
foreach ( $this->categoryNames as $category => $displayCategory ) {
$tag = "$notifyType-$category";
if ( $anonUser->getOption( "echo-subscriptions-$tag" ) ) {
$prefKey = "echo-subscriptions-$notifyType-$category";
if ( isset( $virtualOptions[ $prefKey ] ) ) {
$prefKey = $virtualOptions[ $prefKey ];
}
if ( $anonUser->getOption( $prefKey ) ) {
$byCategoryValueExisting[] = "$notifyType-$category";
}
}
@ -301,8 +307,11 @@ class SpecialDisplayNotificationsConfiguration extends UnlistedSpecialPage {
$byCategoryValueNew = [];
foreach ( $this->notifyTypes as $notifyType => $displayNotifyType ) {
foreach ( $this->categoryNames as $category => $displayCategory ) {
$tag = "$notifyType-$category";
if ( $loggedInUser->getOption( "echo-subscriptions-$tag" ) ) {
$prefKey = "echo-subscriptions-$notifyType-$category";
if ( isset( $virtualOptions[ $prefKey ] ) ) {
$prefKey = $virtualOptions[ $prefKey ];
}
if ( $loggedInUser->getOption( $prefKey ) ) {
$byCategoryValueNew[] = "$notifyType-$category";
}
}