From 818d79ce9a23ac7e869ed13513b15bff087a53d9 Mon Sep 17 00:00:00 2001 From: Cindy Cicalese Date: Tue, 27 Apr 2021 16:39:57 -0400 Subject: [PATCH] Replace usage of deprecated User watchlist methods Bug: T281187 Change-Id: Ib6f21b41b0a82ab4c48db6eb36d4417c05f30637 --- includes/Menu/PageActions/ToolbarBuilder.php | 16 +++++++++++++--- includes/ServiceWiring.php | 5 ++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/includes/Menu/PageActions/ToolbarBuilder.php b/includes/Menu/PageActions/ToolbarBuilder.php index 9d0ea17c7..692decb77 100644 --- a/includes/Menu/PageActions/ToolbarBuilder.php +++ b/includes/Menu/PageActions/ToolbarBuilder.php @@ -32,6 +32,7 @@ use MediaWiki\Minerva\Permissions\IMinervaPagePermissions; use MediaWiki\Minerva\SkinOptions; use MediaWiki\Minerva\Skins\SkinUserPageHelper; use MediaWiki\User\UserIdentity; +use MediaWiki\Watchlist\WatchlistManager; use MessageLocalizer; use MinervaUI; use MWException; @@ -80,6 +81,11 @@ class ToolbarBuilder { */ private $watchlistExpiryEnabled; + /** + * @var WatchlistManager + */ + private $watchlistManager; + /** * ServiceOptions needed. */ @@ -100,6 +106,7 @@ class ToolbarBuilder { * Title and NOT with the user talk page Title. * @param LanguagesHelper $languagesHelper Helper to check title languages/variants * @param ServiceOptions $options + * @param WatchlistManager $watchlistManager */ public function __construct( Title $title, @@ -109,7 +116,8 @@ class ToolbarBuilder { SkinOptions $skinOptions, SkinUserPageHelper $relevantUserPageHelper, LanguagesHelper $languagesHelper, - ServiceOptions $options + ServiceOptions $options, + WatchlistManager $watchlistManager ) { $this->title = $title; $this->user = $user; @@ -119,6 +127,7 @@ class ToolbarBuilder { $this->relevantUserPageHelper = $relevantUserPageHelper; $this->languagesHelper = $languagesHelper; $this->watchlistExpiryEnabled = $options->get( 'WatchlistExpiry' ); + $this->watchlistManager = $watchlistManager; } /** @@ -236,10 +245,11 @@ class ToolbarBuilder { * @throws MWException */ protected function createWatchPageAction(): IMenuEntry { - $isWatched = $this->user->isRegistered() && $this->user->isWatched( $this->title ); + $isWatched = $this->user->isRegistered() && + $this->watchlistManager->isWatched( $this->user, $this->title ); $isTempWatched = $this->watchlistExpiryEnabled && $isWatched && - $this->user->isTempWatched( $this->title ); + $this->watchlistManager->isTempWatched( $this->user, $this->title ); $newModeToSet = $isWatched ? 'unwatch' : 'watch'; $href = $this->user->isAnon() ? $this->getLoginUrl( [ 'returnto' => $this->title ] ) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index b6b4ecd4f..6717e460c 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -93,6 +93,8 @@ return [ ) : $userPageHelper; + $watchlistManager = $services->getWatchlistManager(); + $toolbarBuilder = new PageActionsMenu\ToolbarBuilder( $title, $user, @@ -102,7 +104,8 @@ return [ $relevantUserPageHelper, $languagesHelper, new ServiceOptions( PageActionsMenu\ToolbarBuilder::CONSTRUCTOR_OPTIONS, - $services->getMainConfig() ) + $services->getMainConfig() ), + $watchlistManager ); if ( $skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) ) { $overflowBuilder = $relevantUserPageHelper->isUserPage() ?