From 5946b71f63d7f1fc4d0b1f15fe8fb5c345315817 Mon Sep 17 00:00:00 2001 From: Nymphxyz <65056401+Nymphxyz@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:06:13 +1100 Subject: [PATCH] chore: fix deprecation with wgUser and isLoggedIn (#2) * Replace isLoggedIn * Replace deprecated wgUser --------- Co-authored-by: Mo8it --- OAuth2Client.php | 6 ++++-- SpecialOAuth2Client.php | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/OAuth2Client.php b/OAuth2Client.php index 7c42e9a..859ee19 100644 --- a/OAuth2Client.php +++ b/OAuth2Client.php @@ -20,8 +20,10 @@ class OAuth2ClientHooks { public static function onPersonalUrls( array &$personal_urls, Title $title ) { - global $wgOAuth2Client, $wgUser, $wgRequest; - if( $wgUser->isLoggedIn() ) return true; + global $wgOAuth2Client, $wgRequest; + + $user = RequestContext::getMain()->getUser(); + if( $user->isRegistered() ) return true; # Due to bug 32276, if a user does not have read permissions, diff --git a/SpecialOAuth2Client.php b/SpecialOAuth2Client.php index f29e1f9..a94cab9 100644 --- a/SpecialOAuth2Client.php +++ b/SpecialOAuth2Client.php @@ -136,11 +136,13 @@ private function _handleCallback(){ } private function _default(){ - global $wgOAuth2Client, $wgOut, $wgUser, $wgScriptPath, $wgExtensionAssetsPath; + global $wgOAuth2Client, $wgOut, $wgScriptPath, $wgExtensionAssetsPath; + $service_name = ( isset( $wgOAuth2Client['configuration']['service_name'] ) && 0 < strlen( $wgOAuth2Client['configuration']['service_name'] ) ? $wgOAuth2Client['configuration']['service_name'] : 'OAuth2' ); $wgOut->setPagetitle( wfMessage( 'oauth2client-login-header', $service_name)->text() ); - if ( !$wgUser->isLoggedIn() ) { + $user = RequestContext::getMain()->getUser(); + if ( !$user->isRegistered() ) { $wgOut->addWikiMsg( 'oauth2client-you-can-login-to-this-wiki-with-oauth2', $service_name ); $wgOut->addWikiMsg( 'oauth2client-login-with-oauth2', $this->getPageTitle( 'redirect' )->getPrefixedURL(), $service_name ); @@ -197,8 +199,7 @@ protected function _userHandling( $response ) { $user->setCookies(); $this->getContext()->setUser( $user ); $user->saveSettings(); - global $wgUser; - $wgUser = $user; + RequestContext::getMain()->setUser( $user ); $sessionUser = User::newFromSession($this->getRequest()); $sessionUser->load(); return $user;