MediaWiki
REL1_34
AuthModule.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Extension\OATHAuth\Hook\GetPreferences
;
4
5
use
MediaWiki\Extension\OATHAuth\OATHUserRepository
;
6
use
MediaWiki\MediaWikiServices
;
7
use OOUI\HorizontalLayout;
8
use OOUI\LabelWidget;
9
use OOUI\ButtonWidget;
10
use
SpecialPage
;
11
12
class
AuthModule
{
16
protected
$userRepo
;
20
protected
$user
;
24
protected
$preferences
;
25
31
public
static
function
callback
(
$user
, &
$preferences
) {
32
$userRepo
=
MediaWikiServices::getInstance
()->getService(
'OATHUserRepository'
);
33
$handler =
new
static
(
$userRepo
,
$user
,
$preferences
);
34
return
$handler->execute();
35
}
36
37
protected
function
__construct
(
$userRepo
,
$user
, &
$preferences
) {
38
$this->userRepo =
$userRepo
;
39
$this->user =
$user
;
40
$this->preferences = &
$preferences
;
41
}
42
43
protected
function
execute
() {
44
$oathUser = $this->userRepo->findByUser( $this->user );
45
46
// If there is no existing module in user, and the user is not allowed to enable it,
47
// we have nothing to show.
48
if
( $oathUser->getModule() ===
null
&& !$this->user->isAllowed(
'oathauth-enable'
) ) {
49
return
true
;
50
}
51
$module = $oathUser->getModule();
52
53
$moduleLabel = $module ===
null
?
54
wfMessage
(
'oauthauth-ui-no-module'
) :
55
$module->getDisplayName();
56
57
$manageButton =
new
ButtonWidget( [
58
'href'
=>
SpecialPage::getTitleFor
(
'OATHManage'
)->getLocalURL(),
59
'label'
=>
wfMessage
(
'oathauth-ui-manage'
)->text()
60
] );
61
$currentModuleLabel =
new
LabelWidget( [
62
'label'
=> $moduleLabel->text()
63
] );
64
$control =
new
HorizontalLayout( [
65
'items'
=> [
66
$currentModuleLabel,
67
$manageButton
68
]
69
] );
70
71
$this->preferences[
'oathauth-module'
] = [
72
'type'
=>
'info'
,
73
'raw'
=>
true
,
74
'default'
=> (string)$control,
75
'label-message'
=>
'oathauth-prefs-label'
,
76
'section'
=>
'personal/info'
, ];
77
78
return
true
;
79
}
80
}
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition
GlobalFunctions.php:1263
MediaWiki\Extension\OATHAuth\Hook\GetPreferences\AuthModule
Definition
AuthModule.php:12
MediaWiki\Extension\OATHAuth\Hook\GetPreferences\AuthModule\$userRepo
OATHUserRepository $userRepo
Definition
AuthModule.php:16
MediaWiki\Extension\OATHAuth\Hook\GetPreferences\AuthModule\callback
static callback( $user, &$preferences)
Definition
AuthModule.php:31
MediaWiki\Extension\OATHAuth\Hook\GetPreferences\AuthModule\$preferences
array $preferences
Definition
AuthModule.php:24
MediaWiki\Extension\OATHAuth\Hook\GetPreferences\AuthModule\execute
execute()
Definition
AuthModule.php:43
MediaWiki\Extension\OATHAuth\Hook\GetPreferences\AuthModule\__construct
__construct( $userRepo, $user, &$preferences)
Definition
AuthModule.php:37
MediaWiki\Extension\OATHAuth\Hook\GetPreferences\AuthModule\$user
User $user
Definition
AuthModule.php:20
MediaWiki\Extension\OATHAuth\OATHUserRepository
Definition
OATHUserRepository.php:34
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition
MediaWikiServices.php:117
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition
MediaWikiServices.php:138
SpecialPage
Parent class for all special pages.
Definition
SpecialPage.php:37
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition
SpecialPage.php:83
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition
User.php:51
MediaWiki\Extension\OATHAuth\Hook\GetPreferences
Definition
AuthModule.php:3
extensions
OATHAuth
src
Hook
GetPreferences
AuthModule.php
Generated on Mon Nov 25 2024 16:04:39 for MediaWiki by
1.10.0