Extension/MW-OAuth2Client: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Sysop (Diskussion • Beiträge) |
|||
(4 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt) | |||
Zeile 8: | Zeile 8: | ||
|storemode=property | |storemode=property | ||
}} | }} | ||
= Installation = | |||
<source lang='bash'> | |||
www-data@338655f466c4:~/html/extensions$ git clone https://github.com/jze/MW-OAuth2Client | |||
Cloning into 'MW-OAuth2Client'... | |||
remote: Enumerating objects: 219, done. | |||
remote: Counting objects: 100% (42/42), done. | |||
remote: Compressing objects: 100% (16/16), done. | |||
remote: Total 219 (delta 31), reused 26 (delta 26), pack-reused 177 (from 1) | |||
Receiving objects: 100% (219/219), 50.16 KiB | 1.86 MiB/s, done. | |||
Resolving deltas: 100% (113/113), done. | |||
</source> | |||
== LocalSettings.php == | |||
* https://gitlab.genealogy.net/system0/documentation/-/wikis/GenWiki/LocalSettings.php | |||
= Kompatibilität = | |||
https://www.mediawiki.org/wiki/Extension:OAuth2_Client ist inkompatibel mit MediaWiki 1.42 plus | |||
= CompGen = | = CompGen = | ||
Zeile 33: | Zeile 49: | ||
Unterschied: vorher wurde der Benutzer per Name angelegt, jetzt per numerischer ID. | Unterschied: vorher wurde der Benutzer per Name angelegt, jetzt per numerischer ID. | ||
Die Fehlermeldung zeigt nun die UID anstelle des Benutzernamens. | Die Fehlermeldung zeigt nun die UID anstelle des Benutzernamens. | ||
== Anpassung MediaWiki 1.39 == | |||
<source lang='bash'> | |||
git --no-pager diff | |||
diff --git a/OAuth2Client.php b/OAuth2Client.php | |||
index 7c42e9a..26e725b 100644 | |||
--- a/OAuth2Client.php | |||
+++ b/OAuth2Client.php | |||
@@ -20,8 +20,16 @@ if ( !defined( 'MEDIAWIKI' ) ) { | |||
class OAuth2ClientHooks { | |||
public static function onPersonalUrls( array &$personal_urls, Title $title ) { | |||
- global $wgOAuth2Client, $wgUser, $wgRequest; | |||
- if( $wgUser->isLoggedIn() ) return true; | |||
+ global $wgOAuth2Client, $wgRequest; | |||
+ # deprecated | |||
+ #if( $wgUser->isLoggedIn() ) return true; | |||
+ $context = RequestContext::getMain(); | |||
+ $user = $context->getUser(); | |||
+ $request = $context->getRequest(); | |||
+ | |||
+ if ( $user && $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 bbb331c..0e3b2ab 100644 | |||
--- a/SpecialOAuth2Client.php | |||
+++ b/SpecialOAuth2Client.php | |||
@@ -135,18 +135,37 @@ class SpecialOAuth2Client extends SpecialPage { | |||
return true; | |||
} | |||
- private function _default(){ | |||
- global $wgOAuth2Client, $wgOut, $wgUser, $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() ) { | |||
- $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 ); | |||
- | |||
+ private function _default() { | |||
+ global $wgOAuth2Client, $wgScriptPath, $wgExtensionAssetsPath; | |||
+ | |||
+ $service_name = ( | |||
+ isset( $wgOAuth2Client['configuration']['service_name'] ) | |||
+ && strlen( $wgOAuth2Client['configuration']['service_name'] ) > 0 | |||
+ ) | |||
+ ? $wgOAuth2Client['configuration']['service_name'] | |||
+ : 'OAuth2'; | |||
+ | |||
+ $out = $this->getOutput(); | |||
+ $user = $this->getUser(); | |||
+ | |||
+ $out->setPagetitle( | |||
+ wfMessage( 'oauth2client-login-header', $service_name )->text() | |||
+ ); | |||
+ | |||
+ if ( !$user || !$user->isRegistered() ) { | |||
+ $out->addWikiMsg( | |||
+ 'oauth2client-you-can-login-to-this-wiki-with-oauth2', | |||
+ $service_name | |||
+ ); | |||
+ $out->addWikiMsg( | |||
+ 'oauth2client-login-with-oauth2', | |||
+ $this->getTitle( 'redirect' )->getPrefixedURL(), | |||
+ $service_name | |||
+ ); | |||
} else { | |||
- $wgOut->addWikiMsg( 'oauth2client-youre-already-loggedin' ); | |||
+ $out->addWikiMsg( 'oauth2client-youre-already-loggedin' ); | |||
} | |||
+ | |||
return true; | |||
} | |||
@@ -199,8 +218,6 @@ class SpecialOAuth2Client extends SpecialPage { | |||
$user->setCookies(); | |||
$this->getContext()->setUser( $user ); | |||
$user->saveSettings(); | |||
- global $wgUser; | |||
- $wgUser = $user; | |||
$sessionUser = User::newFromSession($this->getRequest()); | |||
$sessionUser->load(); | |||
return $user; | |||
</source> | |||
[[Category:Extension]] | [[Category:Extension]] |
Aktuelle Version vom 21. August 2025, 09:27 Uhr
Extension[Bearbeiten]
Extension | |
---|---|
name | MW-OAuth2Client |
url | https://github.com/jze/MW-OAuth2Client |
wikidataid | Q26883676→Q26883676 |
purpose | Provides OAuth 2.0 client functionality for MediaWiki |
since | |
until | |
comment | |
state | ⚠️ |
wiki | → |
Installation[Bearbeiten]
www-data@338655f466c4:~/html/extensions$ git clone https://github.com/jze/MW-OAuth2Client
Cloning into 'MW-OAuth2Client'...
remote: Enumerating objects: 219, done.
remote: Counting objects: 100% (42/42), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 219 (delta 31), reused 26 (delta 26), pack-reused 177 (from 1)
Receiving objects: 100% (219/219), 50.16 KiB | 1.86 MiB/s, done.
Resolving deltas: 100% (113/113), done.
LocalSettings.php[Bearbeiten]
Kompatibilität[Bearbeiten]
https://www.mediawiki.org/wiki/Extension:OAuth2_Client ist inkompatibel mit MediaWiki 1.42 plus
CompGen[Bearbeiten]
$user = User::newFromName($username, 'creatable');
if (!$user) {
throw new MWException('Could not create user with username:' . $username);
die();
}
→ geändert zu:
$user = User::newFromId($uid);
if (!$user) {
throw new MWException('Could not create user with user id:' . $uid);
die();
}
Unterschied: vorher wurde der Benutzer per Name angelegt, jetzt per numerischer ID. Die Fehlermeldung zeigt nun die UID anstelle des Benutzernamens.
Anpassung MediaWiki 1.39[Bearbeiten]
git --no-pager diff
diff --git a/OAuth2Client.php b/OAuth2Client.php
index 7c42e9a..26e725b 100644
--- a/OAuth2Client.php
+++ b/OAuth2Client.php
@@ -20,8 +20,16 @@ if ( !defined( 'MEDIAWIKI' ) ) {
class OAuth2ClientHooks {
public static function onPersonalUrls( array &$personal_urls, Title $title ) {
- global $wgOAuth2Client, $wgUser, $wgRequest;
- if( $wgUser->isLoggedIn() ) return true;
+ global $wgOAuth2Client, $wgRequest;
+ # deprecated
+ #if( $wgUser->isLoggedIn() ) return true;
+ $context = RequestContext::getMain();
+ $user = $context->getUser();
+ $request = $context->getRequest();
+
+ if ( $user && $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 bbb331c..0e3b2ab 100644
--- a/SpecialOAuth2Client.php
+++ b/SpecialOAuth2Client.php
@@ -135,18 +135,37 @@ class SpecialOAuth2Client extends SpecialPage {
return true;
}
- private function _default(){
- global $wgOAuth2Client, $wgOut, $wgUser, $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() ) {
- $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 );
-
+ private function _default() {
+ global $wgOAuth2Client, $wgScriptPath, $wgExtensionAssetsPath;
+
+ $service_name = (
+ isset( $wgOAuth2Client['configuration']['service_name'] )
+ && strlen( $wgOAuth2Client['configuration']['service_name'] ) > 0
+ )
+ ? $wgOAuth2Client['configuration']['service_name']
+ : 'OAuth2';
+
+ $out = $this->getOutput();
+ $user = $this->getUser();
+
+ $out->setPagetitle(
+ wfMessage( 'oauth2client-login-header', $service_name )->text()
+ );
+
+ if ( !$user || !$user->isRegistered() ) {
+ $out->addWikiMsg(
+ 'oauth2client-you-can-login-to-this-wiki-with-oauth2',
+ $service_name
+ );
+ $out->addWikiMsg(
+ 'oauth2client-login-with-oauth2',
+ $this->getTitle( 'redirect' )->getPrefixedURL(),
+ $service_name
+ );
} else {
- $wgOut->addWikiMsg( 'oauth2client-youre-already-loggedin' );
+ $out->addWikiMsg( 'oauth2client-youre-already-loggedin' );
}
+
return true;
}
@@ -199,8 +218,6 @@ class SpecialOAuth2Client extends SpecialPage {
$user->setCookies();
$this->getContext()->setUser( $user );
$user->saveSettings();
- global $wgUser;
- $wgUser = $user;
$sessionUser = User::newFromSession($this->getRequest());
$sessionUser->load();
return $user;