forked from joostdekeijzer/mw-oauth2-client-extension
-
Notifications
You must be signed in to change notification settings - Fork 55
/
OAuth2Client.php
70 lines (62 loc) · 2.68 KB
/
OAuth2Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* OAuth2Client.php
* Based on TwitterLogin by David Raison, which is based on the guideline published by Dave Challis at http://blogs.ecs.soton.ac.uk/webteam/2010/04/13/254/
* @license: LGPL (GNU Lesser General Public License) http://www.gnu.org/licenses/lgpl.html
*
* @file OAuth2Client.php
* @ingroup OAuth2Client
*
* @author Joost de Keijzer
* @author Nischay Nahata for Schine GmbH
*
* Uses the OAuth2 library https://github.com/thephpleague/oauth2-client
*
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This is a MediaWiki extension, and must be run from within MediaWiki.' );
}
class OAuth2ClientHooks {
public static function onPersonalUrls( array &$personal_urls, Title $title ) {
global $wgOAuth2Client, $wgUser, $wgRequest;
if( $wgUser->isLoggedIn() ) return true;
# 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()
$page = Title::newFromURL( $wgRequest->getVal( 'title', '' ) );
$service_name = isset( $wgOAuth2Client['configuration']['service_name'] ) && 0 < strlen( $wgOAuth2Client['configuration']['service_name'] ) ? $wgOAuth2Client['configuration']['service_name'] : 'OAuth2';
if( isset( $wgOAuth2Client['configuration']['service_login_link_text'] ) && 0 < strlen( $wgOAuth2Client['configuration']['service_login_link_text'] ) ) {
$service_login_link_text = $wgOAuth2Client['configuration']['service_login_link_text'];
} else {
$service_login_link_text = wfMessage('oauth2client-header-link-text', $service_name)->text();
}
$inExt = ( null == $page || ('OAuth2Client' == substr( $page->getText(), 0, 12) ) || strstr($page->getText(), 'Logout') );
$personal_urls['anon_oauth_login'] = array(
'text' => $service_login_link_text,
//'class' => ,
'active' => false,
);
if( $inExt ) {
$personal_urls['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(
'OAuth2Client',
'redirect',
wfArrayToCGI( array( 'returnto' => $page ) )
);
}
if( isset( $personal_urls['anonlogin'] ) ) {
if( $inExt ) {
$personal_urls['anonlogin']['href'] = Skin::makeSpecialUrl( 'Userlogin' );
}
}
return true;
}
}