mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-09-24 18:59:40 +00:00
SpecialDisplayNotificationsConfiguration: Fix default values of core prefs
Some of Echo's subscription user preferences are mapped to existing user preferences defined in core MediaWiki. However, this special page was checking the Echo preference names, returning incorrect values. This affected the edit-user-talk preference and watchlist preferences (not available with the default configuration). Change-Id: I2de7553f82434505c000c30a71b9f90c4490482b
This commit is contained in:
parent
b826dd263c
commit
0341634e45
|
@ -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 ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue