From 9b8f153fb8b6cbcf116ea13f52bf7c4757af6d51 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Fri, 29 Apr 2022 19:37:49 +0200 Subject: [PATCH] Setup: Remove internal short-cut config $wgUseEnotif It is not possible to set $wgUseEnotif on LocalSettings.php, because it is always set on setup, it should not be a global/setting. Just remove it from the dynamic setup and use the config it is set from Bug: T305093 Change-Id: I9bfa502a0b9798bd149b4cfe4db86a0461e76f55 --- includes/SetupDynamicConfig.php | 5 +---- includes/changes/RecentChange.php | 7 ++++--- includes/watchlist/WatchlistManager.php | 9 ++++++--- .../unit/includes/SetupDynamicConfigTest.php | 7 ------- .../watchlist/WatchlistManagerTest.php | 19 ++++++++++++------- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/includes/SetupDynamicConfig.php b/includes/SetupDynamicConfig.php index e585cd6071e..e5520157f0c 100644 --- a/includes/SetupDynamicConfig.php +++ b/includes/SetupDynamicConfig.php @@ -199,9 +199,7 @@ unset( $rcMaxAgeDays ); $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' ); -if ( $wgEnableEmail ) { - $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist; -} else { +if ( !$wgEnableEmail ) { // Disable all other email settings automatically if $wgEnableEmail // is set to false. - T65678 $wgAllowHTMLEmail = false; @@ -216,7 +214,6 @@ if ( $wgEnableEmail ) { $wgEnotifUserTalk = false; $wgEnotifWatchlist = false; unset( $wgGroupPermissions['user']['sendemail'] ); - $wgUseEnotif = false; $wgUserEmailUseReplyTo = false; $wgUsersNotifiedOnAllChanges = []; } diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 014aee3307e..ffc913f9105 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -411,8 +411,6 @@ class RecentChange implements Taggable { public function save( $send = self::SEND_FEED ) { $mainConfig = MediaWikiServices::getInstance()->getMainConfig(); $putIPinRC = $mainConfig->get( MainConfigNames::PutIPinRC ); - $useEnotif = $mainConfig->get( 'UseEnotif' ); - $showUpdatedMarker = $mainConfig->get( MainConfigNames::ShowUpdatedMarker ); $dbw = wfGetDB( DB_PRIMARY ); if ( !is_array( $this->mExtra ) ) { $this->mExtra = []; @@ -501,7 +499,10 @@ class RecentChange implements Taggable { } # E-mail notifications - if ( $useEnotif || $showUpdatedMarker ) { + if ( $mainConfig->get( MainConfigNames::EnotifUserTalk ) || + $mainConfig->get( MainConfigNames::EnotifWatchlist ) || + $mainConfig->get( MainConfigNames::ShowUpdatedMarker ) + ) { $userFactory = MediaWikiServices::getInstance()->getUserFactory(); $editor = $userFactory->newFromUserIdentity( $this->getPerformerIdentity() ); $page = $this->getPage(); diff --git a/includes/watchlist/WatchlistManager.php b/includes/watchlist/WatchlistManager.php index c4b4e32f7a4..6617f10e484 100644 --- a/includes/watchlist/WatchlistManager.php +++ b/includes/watchlist/WatchlistManager.php @@ -55,7 +55,8 @@ class WatchlistManager { * @internal For use by ServiceWiring */ public const CONSTRUCTOR_OPTIONS = [ - 'UseEnotif', + MainConfigNames::EnotifUserTalk, + MainConfigNames::EnotifWatchlist, MainConfigNames::ShowUpdatedMarker, ]; @@ -164,7 +165,8 @@ class WatchlistManager { $user = $performer->getUser(); - if ( !$this->options->get( 'UseEnotif' ) && + if ( !$this->options->get( MainConfigNames::EnotifUserTalk ) && + !$this->options->get( MainConfigNames::EnotifWatchlist ) && !$this->options->get( MainConfigNames::ShowUpdatedMarker ) ) { $this->talkPageNotificationManager->removeUserHasNewMessages( $user ); @@ -229,7 +231,8 @@ class WatchlistManager { $this->talkPageNotificationManager->clearForPageView( $userIdentity, $oldRev ); } - if ( !$this->options->get( 'UseEnotif' ) && + if ( !$this->options->get( MainConfigNames::EnotifUserTalk ) && + !$this->options->get( MainConfigNames::EnotifWatchlist ) && !$this->options->get( MainConfigNames::ShowUpdatedMarker ) ) { return; diff --git a/tests/phpunit/unit/includes/SetupDynamicConfigTest.php b/tests/phpunit/unit/includes/SetupDynamicConfigTest.php index e604207edd1..8e9eaa77097 100644 --- a/tests/phpunit/unit/includes/SetupDynamicConfigTest.php +++ b/tests/phpunit/unit/includes/SetupDynamicConfigTest.php @@ -168,7 +168,6 @@ class SetupDynamicConfigTest extends MediaWikiUnitTestCase { 'backend' => 'local-backend', ], 'CookiePrefix' => 'my_wiki', - 'UseEnotif' => false, 'Localtimezone' => 'UTC', 'LocalTZoffset' => 0, 'DBerrorLogTZ' => 'UTC', @@ -649,10 +648,6 @@ class SetupDynamicConfigTest extends MediaWikiUnitTestCase { [ 'CookiePrefix' => 'n=o,t;a l+l.o"w\'e\\d[' ], [ 'CookiePrefix' => 'n_o_t_a_l_l_o_w_e_d_' ], ]; - yield '$wgEnotifUserTalk true' => [ - [ 'EnotifUserTalk' => true ], - [ 'UseEnotif' => true ], - ]; yield '$wgEnableEmail set to false' => [ [ 'EnableEmail' => false, @@ -668,7 +663,6 @@ class SetupDynamicConfigTest extends MediaWikiUnitTestCase { 'EnotifUserTalk' => true, 'EnotifWatchlist' => true, 'GroupPermissions' => [ 'user' => [ 'sendemail' => true ] ], - 'UseEnotif' => true, 'UserEmailUseReplyTo' => true, 'UsersNotifiedOnAllChanges' => [ 'Admin' ], ], [ @@ -684,7 +678,6 @@ class SetupDynamicConfigTest extends MediaWikiUnitTestCase { 'EnotifUserTalk' => false, 'EnotifWatchlist' => false, 'GroupPermissions' => [ 'user' => [] ], - 'UseEnotif' => false, 'UserEmailUseReplyTo' => false, 'UsersNotifiedOnAllChanges' => [], ], diff --git a/tests/phpunit/unit/includes/watchlist/WatchlistManagerTest.php b/tests/phpunit/unit/includes/watchlist/WatchlistManagerTest.php index 226bb7d1cd3..dc7c92a2d6a 100644 --- a/tests/phpunit/unit/includes/watchlist/WatchlistManagerTest.php +++ b/tests/phpunit/unit/includes/watchlist/WatchlistManagerTest.php @@ -48,7 +48,8 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { private function getManager( array $params = [] ) { $config = $params['config'] ?? [ - 'UseEnotif' => false, + MainConfigNames::EnotifUserTalk => false, + MainConfigNames::EnotifWatchlist => false, MainConfigNames::ShowUpdatedMarker => false, ]; $options = new ServiceOptions( @@ -149,7 +150,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { public function testClearAllUserNotifications_configDisabled() { // ********** Code path #3 ********** - // Early return: config with `UseEnotif` and `ShowUpdatedMarker` both false + // Early return: config with `EnotifUserTalk`, `EnotifWatchlist` and `ShowUpdatedMarker` are false $userIdentity = new UserIdentityValue( 100, 'User Name' ); list( $authority, $userFactory ) = $this->getAuthorityAndUserFactory( @@ -180,7 +181,8 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { // Early return: user's id is falsey $config = [ - 'UseEnotif' => true, + MainConfigNames::EnotifUserTalk => true, + MainConfigNames::EnotifWatchlist => true, MainConfigNames::ShowUpdatedMarker => true ]; @@ -209,7 +211,8 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { // No early returns $config = [ - 'UseEnotif' => true, + MainConfigNames::EnotifUserTalk => true, + MainConfigNames::EnotifWatchlist => true, MainConfigNames::ShowUpdatedMarker => true ]; @@ -303,7 +306,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { */ public function testClearTitleUserNotifications_configDisabled( $testPageFactory ) { // ********** Code path #3 ********** - // Early return: config with `UseEnotif` and `ShowUpdatedMarker` both false + // Early return: config with `EnotifUserTalk` and `ShowUpdatedMarker` both false $title = $testPageFactory( 100, NS_USER_TALK, 'PageTitleGoesHere' ); @@ -336,7 +339,8 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $title = $testPageFactory( 100, NS_USER_TALK, 'PageTitleGoesHere' ); $config = [ - 'UseEnotif' => true, + MainConfigNames::EnotifUserTalk => true, + MainConfigNames::EnotifWatchlist => true, MainConfigNames::ShowUpdatedMarker => true ]; @@ -370,7 +374,8 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $title = $testPageFactory( 100, NS_USER_TALK, 'PageTitleGoesHere' ); $config = [ - 'UseEnotif' => true, + MainConfigNames::EnotifUserTalk => true, + MainConfigNames::EnotifWatchlist => true, MainConfigNames::ShowUpdatedMarker => true ];