aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCindy Cicalese <cindom@gmail.com>2021-04-12 20:43:46 -0400
committerCicalese <ccicalese@wikimedia.org>2021-04-21 02:48:31 +0000
commitce6a4ef45e623c248b29ece228bb72e7fc27f51a (patch)
tree83bcb4ba2be02bb40c0c11bb0e280a755362fad3
parentf8ed11e1705137da7077ad9d2045f4ccd9ed4e06 (diff)
downloadmediawikicore-ce6a4ef45e623c248b29ece228bb72e7fc27f51a.tar.gz
mediawikicore-ce6a4ef45e623c248b29ece228bb72e7fc27f51a.zip
Use WatchlistManager in auth classes
Change-Id: Ib8d338bc0b167277f36ab6c5d45c98c35e4a9ba9
-rw-r--r--includes/ServiceWiring.php3
-rw-r--r--includes/auth/AuthManager.php15
-rw-r--r--tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php3
-rw-r--r--tests/phpunit/includes/auth/AuthManagerTest.php10
-rw-r--r--tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php6
-rw-r--r--tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php3
-rw-r--r--tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php3
-rw-r--r--tests/phpunit/includes/auth/ResetPasswordSecondaryAuthenticationProviderTest.php3
-rw-r--r--tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php3
9 files changed, 36 insertions, 13 deletions
diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php
index 7c94a3c5f810..aa5d2e329d0c 100644
--- a/includes/ServiceWiring.php
+++ b/includes/ServiceWiring.php
@@ -179,7 +179,8 @@ return [
$services->getReadOnlyMode(),
$services->getUserNameUtils(),
$services->getBlockManager(),
- $services->getBlockErrorFormatter()
+ $services->getBlockErrorFormatter(),
+ $services->getWatchlistManager()
);
$authManager->setLogger( LoggerFactory::getInstance( 'authentication' ) );
return $authManager;
diff --git a/includes/auth/AuthManager.php b/includes/auth/AuthManager.php
index 16d3fdce749e..d9c06a204317 100644
--- a/includes/auth/AuthManager.php
+++ b/includes/auth/AuthManager.php
@@ -31,6 +31,7 @@ use MediaWiki\HookContainer\HookRunner;
use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\PermissionStatus;
use MediaWiki\User\UserNameUtils;
+use MediaWiki\Watchlist\WatchlistManager;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
@@ -177,6 +178,9 @@ class AuthManager implements LoggerAwareInterface {
/** @var BlockErrorFormatter */
private $blockErrorFormatter;
+ /** @var WatchlistManager */
+ private $watchlistManager;
+
/**
* Get the global AuthManager
* @return AuthManager
@@ -197,6 +201,7 @@ class AuthManager implements LoggerAwareInterface {
* @param UserNameUtils $userNameUtils
* @param BlockManager $blockManager
* @param BlockErrorFormatter $blockErrorFormatter
+ * @param WatchlistManager $watchlistManager
*/
public function __construct(
WebRequest $request,
@@ -206,7 +211,8 @@ class AuthManager implements LoggerAwareInterface {
ReadOnlyMode $readOnlyMode,
UserNameUtils $userNameUtils,
BlockManager $blockManager,
- BlockErrorFormatter $blockErrorFormatter
+ BlockErrorFormatter $blockErrorFormatter,
+ WatchlistManager $watchlistManager
) {
$this->request = $request;
$this->config = $config;
@@ -218,6 +224,7 @@ class AuthManager implements LoggerAwareInterface {
$this->userNameUtils = $userNameUtils;
$this->blockManager = $blockManager;
$this->blockErrorFormatter = $blockErrorFormatter;
+ $this->watchlistManager = $watchlistManager;
}
/**
@@ -1473,7 +1480,7 @@ class AuthManager implements LoggerAwareInterface {
\DeferredUpdates::addUpdate( \SiteStatsUpdate::factory( [ 'users' => 1 ] ) );
// Watch user's userpage and talk page
- $user->addWatch( $user->getUserPage(), User::IGNORE_USER_RIGHTS );
+ $this->watchlistManager->addWatchIgnoringRights( $user, $user->getUserPage() );
// Inform the provider
$logSubtype = $provider->finishAccountCreation( $user, $creator, $state['primaryResponse'] );
@@ -1792,8 +1799,8 @@ class AuthManager implements LoggerAwareInterface {
// Update user count
\DeferredUpdates::addUpdate( \SiteStatsUpdate::factory( [ 'users' => 1 ] ) );
// Watch user's userpage and talk page
- \DeferredUpdates::addCallableUpdate( static function () use ( $user ) {
- $user->addWatch( $user->getUserPage(), User::IGNORE_USER_RIGHTS );
+ \DeferredUpdates::addCallableUpdate( function () use ( $user ) {
+ $this->watchlistManager->addWatchIgnoringRights( $user, $user->getUserPage() );
} );
// Log the creation
diff --git a/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php
index c2afed08668d..6ee49f3e7b68 100644
--- a/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php
@@ -132,7 +132,8 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiIntegr
$services->getReadOnlyMode(),
$services->getUserNameUtils(),
$services->getBlockManager(),
- $services->getBlockErrorFormatter()
+ $services->getBlockErrorFormatter(),
+ $services->getWatchlistManager()
);
$provider = $this->getMockForAbstractClass(
diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php
index ecf400d7d846..6b42b1347a01 100644
--- a/tests/phpunit/includes/auth/AuthManagerTest.php
+++ b/tests/phpunit/includes/auth/AuthManagerTest.php
@@ -16,6 +16,7 @@ use MediaWiki\MediaWikiServices;
use MediaWiki\Session\SessionInfo;
use MediaWiki\Session\UserInfo;
use MediaWiki\User\UserNameUtils;
+use MediaWiki\Watchlist\WatchlistManager;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
@@ -70,6 +71,9 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
/** @var BlockErrorFormatter */
private $blockErrorFormatter;
+ /** @var WatchlistManager */
+ private $watchlistManager;
+
/**
* Sets a mock on a hook
* @param string $hook
@@ -189,6 +193,9 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
if ( $regen || !$this->blockErrorFormatter ) {
$this->blockErrorFormatter = MediaWikiServices::getInstance()->getBlockErrorFormatter();
}
+ if ( $regen || !$this->watchlistManager ) {
+ $this->watchlistManager = MediaWikiServices::getInstance()->getWatchlistManager();
+ }
if ( $regen || !$this->hookContainer ) {
// Set up a HookContainer similar to the normal one except that it
// gets global hooks from $this->authHooks instead of $wgHooks
@@ -226,7 +233,8 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase {
$this->readOnlyMode,
$this->userNameUtils,
$this->blockManager,
- $this->blockErrorFormatter
+ $this->blockErrorFormatter,
+ $this->watchlistManager
);
$this->manager->setLogger( $this->logger );
$this->managerPriv = TestingAccessWrapper::newFromObject( $this->manager );
diff --git a/tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php
index 8fc1778b3746..a0c02c1c29a7 100644
--- a/tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/ConfirmLinkSecondaryAuthenticationProviderTest.php
@@ -146,7 +146,8 @@ class ConfirmLinkSecondaryAuthenticationProviderTest extends \MediaWikiIntegrati
$mwServices->getReadOnlyMode(),
$this->createNoOpMock( UserNameUtils::class ),
$mwServices->getBlockManager(),
- $mwServices->getBlockErrorFormatter()
+ $mwServices->getBlockErrorFormatter(),
+ $mwServices->getWatchlistManager()
] )
->getMock();
$manager->expects( $this->any() )->method( 'allowsAuthenticationDataChange' )
@@ -251,7 +252,8 @@ class ConfirmLinkSecondaryAuthenticationProviderTest extends \MediaWikiIntegrati
$readOnlyMode,
$userNameUtils,
$mwServices->getBlockManager(),
- $mwServices->getBlockErrorFormatter()
+ $mwServices->getBlockErrorFormatter(),
+ $mwServices->getWatchlistManager()
);
$provider->setManager( $manager );
$provider = TestingAccessWrapper::newFromObject( $provider );
diff --git a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php
index f5ba18cf0644..50363243bdf7 100644
--- a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php
@@ -75,7 +75,8 @@ class EmailNotificationSecondaryAuthenticationProviderTest extends \MediaWikiInt
$mwServices->getReadOnlyMode(),
$userNameUtils,
$mwServices->getBlockManager(),
- $mwServices->getBlockErrorFormatter()
+ $mwServices->getBlockErrorFormatter(),
+ $mwServices->getWatchlistManager()
);
$creator = $this->getMockBuilder( \User::class )->getMock();
diff --git a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
index dd8aa58b1b33..0fc39b9e7c97 100644
--- a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
@@ -54,7 +54,8 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiIntegrati
$mwServices->getReadOnlyMode(),
$userNameUtils,
$mwServices->getBlockManager(),
- $mwServices->getBlockErrorFormatter()
+ $mwServices->getBlockErrorFormatter(),
+ $mwServices->getWatchlistManager()
);
}
$this->validity = \Status::newGood();
diff --git a/tests/phpunit/includes/auth/ResetPasswordSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/ResetPasswordSecondaryAuthenticationProviderTest.php
index 663f48eb9901..05d58caeff9c 100644
--- a/tests/phpunit/includes/auth/ResetPasswordSecondaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/ResetPasswordSecondaryAuthenticationProviderTest.php
@@ -103,7 +103,8 @@ class ResetPasswordSecondaryAuthenticationProviderTest extends \MediaWikiIntegra
$mwServices->getReadOnlyMode(),
$userNameUtils,
$mwServices->getBlockManager(),
- $mwServices->getBlockErrorFormatter()
+ $mwServices->getBlockErrorFormatter(),
+ $mwServices->getWatchlistManager()
);
$provider->setManager( $manager );
$provider = TestingAccessWrapper::newFromObject( $provider );
diff --git a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
index 165f476e0d1f..d061f2839e96 100644
--- a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
@@ -54,7 +54,8 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
$mwServices->getReadOnlyMode(),
$userNameUtils,
$mwServices->getBlockManager(),
- $mwServices->getBlockErrorFormatter()
+ $mwServices->getBlockErrorFormatter(),
+ $mwServices->getWatchlistManager()
);
}
$this->validity = \Status::newGood();