MediaWiki
REL1_34
CheckExclusiveRights.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors
;
4
5
use
ConfigException
;
6
use
MediaWiki\Extension\OATHAuth\OATHAuth
;
7
use
MediaWiki\Session\Session
;
8
use
RequestContext
;
9
use
User
;
10
use
Title
;
11
12
class
CheckExclusiveRights
{
19
protected
$exclusiveRights
;
20
24
protected
$session
;
25
29
protected
$title
;
30
34
protected
$user
;
35
39
protected
$action
;
40
44
protected
$result
;
45
54
public
static
function
callback
(
$title
,
$user
,
$action
, &
$result
) {
55
$config =
RequestContext::getMain
()->getConfig();
56
if
( !$config->has(
'OATHExclusiveRights'
) ) {
57
return
true
;
58
}
59
$session
=
$user
->
getRequest
()->getSession();
60
$exclusiveRights
= $config->get(
'OATHExclusiveRights'
);
61
$handler =
new
static
(
$exclusiveRights
,
$session
,
$title
,
$user
,
$action
,
$result
);
62
return
$handler->execute();
63
}
64
73
protected
function
__construct
(
$exclusiveRights
,
$session
,
$title
,
$user
,
$action
, &
$result
) {
74
$this->exclusiveRights =
$exclusiveRights
;
75
$this->session =
$session
;
76
$this->title =
$title
;
77
$this->user =
$user
;
78
$this->action =
$action
;
79
$this->result = &
$result
;
80
}
81
87
protected
function
execute
() {
88
if
( !$this->
authenticatedOver2FA
() && $this->
actionBlocked
() ) {
89
$this->
addError
();
90
return
false
;
91
}
92
return
true
;
93
}
94
98
private
function
authenticatedOver2FA
() {
99
return
(
bool
)$this->session->get(
OATHAuth::AUTHENTICATED_OVER_2FA
,
false
);
100
}
101
102
private
function
actionBlocked
() {
103
return
in_array( $this->action, $this->exclusiveRights );
104
}
105
106
private
function
addError
() {
107
$this->result =
'oathauth-action-exclusive-to-2fa'
;
108
}
109
}
ConfigException
Exceptions for config failures.
Definition
ConfigException.php:28
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights
Definition
CheckExclusiveRights.php:12
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\callback
static callback( $title, $user, $action, &$result)
Definition
CheckExclusiveRights.php:54
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\authenticatedOver2FA
authenticatedOver2FA()
Definition
CheckExclusiveRights.php:98
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$session
Session $session
Definition
CheckExclusiveRights.php:24
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$action
string $action
Definition
CheckExclusiveRights.php:39
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$exclusiveRights
array $exclusiveRights
Array of rights that a user should only have if they authenticated with 2FA.
Definition
CheckExclusiveRights.php:19
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$user
User $user
Definition
CheckExclusiveRights.php:34
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\actionBlocked
actionBlocked()
Definition
CheckExclusiveRights.php:102
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\__construct
__construct( $exclusiveRights, $session, $title, $user, $action, &$result)
Definition
CheckExclusiveRights.php:73
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\addError
addError()
Definition
CheckExclusiveRights.php:106
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\execute
execute()
Take away user rights if not authenticated with 2FA.
Definition
CheckExclusiveRights.php:87
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$title
Title $title
Definition
CheckExclusiveRights.php:29
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$result
string array $result
Definition
CheckExclusiveRights.php:44
MediaWiki\Extension\OATHAuth\OATHAuth
Definition
OATHAuth.php:14
MediaWiki\Extension\OATHAuth\OATHAuth\AUTHENTICATED_OVER_2FA
const AUTHENTICATED_OVER_2FA
Definition
OATHAuth.php:15
MediaWiki\Session\Session
Manages data for an an authenticated session.
Definition
Session.php:48
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition
RequestContext.php:33
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition
RequestContext.php:431
Title
Represents a title within MediaWiki.
Definition
Title.php:42
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition
User.php:51
User\getRequest
getRequest()
Get the WebRequest object to use with this object.
Definition
User.php:3737
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors
Definition
CheckExclusiveRights.php:3
extensions
OATHAuth
src
Hook
GetUserPermissionsErrors
CheckExclusiveRights.php
Generated on Mon Nov 25 2024 16:04:39 for MediaWiki by
1.10.0