diff --git a/OAuth2Client.php b/OAuth2Client.php index 7c42e9a..3dff564 100644 --- a/OAuth2Client.php +++ b/OAuth2Client.php @@ -18,10 +18,12 @@ die( 'This is a MediaWiki extension, and must be run from within MediaWiki.' ); } class OAuth2ClientHooks { - public static function onPersonalUrls( array &$personal_urls, Title $title ) { + public static function onSkinTemplateNavigation_Universal( SkinTemplate $skinTemplate, array &$links ) { - 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, @@ -39,20 +41,21 @@ public static function onPersonalUrls( array &$personal_urls, Title $title ) { } $inExt = ( null == $page || ('OAuth2Client' == substr( $page->getText(), 0, 12) ) || strstr($page->getText(), 'Logout') ); - $personal_urls['anon_oauth_login'] = array( + $links['user-menu']['anon_oauth_login'] = array( + 'single-id' => 'pt-oauth', 'text' => $service_login_link_text, - //'class' => , 'active' => false, + 'icon' => 'oauth', ); if( $inExt ) { - $personal_urls['anon_oauth_login']['href'] = Skin::makeSpecialUrlSubpage( 'OAuth2Client', 'redirect' ); + $links['user-menu']['anon_oauth_login']['href'] = Skin::makeSpecialUrlSubpage( 'OAuth2Client', 'redirect' ); } else { # Due to bug 32276, if a user does not have read permissions, # $this->getTitle() will just give Special:Badtitle, which is # not especially useful as a returnto parameter. Use the title # from the request instead, if there was one. # see SkinTemplate->buildPersonalUrls() - $personal_urls['anon_oauth_login']['href'] = Skin::makeSpecialUrlSubpage( + $links['user-menu']['anon_oauth_login']['href'] = Skin::makeSpecialUrlSubpage( 'OAuth2Client', 'redirect', wfArrayToCGI( array( 'returnto' => $page ) ) @@ -66,5 +69,4 @@ public static function onPersonalUrls( array &$personal_urls, Title $title ) { } return true; } - } diff --git a/SpecialOAuth2Client.php b/SpecialOAuth2Client.php index e9a263d..5727754 100644 --- a/SpecialOAuth2Client.php +++ b/SpecialOAuth2Client.php @@ -136,13 +136,14 @@ 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->getTitle( 'redirect' )->getPrefixedURL(), $service_name ); + $wgOut->addWikiMsg( 'oauth2client-login-with-oauth2', $this->getPageTitle('redirect')->getPrefixedURL(), $service_name ); } else { $wgOut->addWikiMsg( 'oauth2client-youre-already-loggedin' ); @@ -166,15 +167,13 @@ protected function _userHandling( $response ) { isset($wgOAuth2Client['configuration']['authz_callback']) && false === $wgOAuth2Client['configuration']['authz_callback']($response) ) { - $callback_failure_message = isset($wgOAuth2Client['configuration']['authz_failure_message']) - ? $wgOAuth2Client['configuration']['authz_failure_message'] - : 'Not authorized'; + $callback_failure_message = $wgOAuth2Client['configuration']['authz_failure_message'] ?? 'Not authorized'; throw new MWException($callback_failure_message); } $username = JsonHelper::extractValue($response, $wgOAuth2Client['configuration']['username']); $email = JsonHelper::extractValue($response, $wgOAuth2Client['configuration']['email']); - Hooks::run("OAuth2ClientBeforeUserSave", [&$username, &$email, $response]); + MediaWiki\MediaWikiServices::getInstance()->getHookContainer()->run("OAuth2ClientBeforeUserSave", [&$username, &$email, $response]); $user = User::newFromName($username, 'creatable'); if (!$user) { throw new MWException('Could not create user with username:' . $username); @@ -197,11 +196,9 @@ 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; } - } diff --git a/extension.json b/extension.json index e11dc35..2334b3a 100644 --- a/extension.json +++ b/extension.json @@ -18,8 +18,8 @@ "OAuth2ClientAlias": "OAuth2Client.alias.php" }, "Hooks": { - "PersonalUrls": [ - "OAuth2ClientHooks::onPersonalUrls" + "SkinTemplateNavigation::Universal": [ + "OAuth2ClientHooks::onSkinTemplateNavigation_Universal" ] }, "SpecialPages": { diff --git a/vendors/oauth2-client b/vendors/oauth2-client index 0b32264..badb01e 160000 --- a/vendors/oauth2-client +++ b/vendors/oauth2-client @@ -1 +1 @@ -Subproject commit 0b3226498c87a737366211b1a5b745d73a5717e2 +Subproject commit badb01e62383430706433191b82506b6df24ad98