MediaWiki REL1_34
CheckExclusiveRights.php
Go to the documentation of this file.
1<?php
2
4
9use User;
10use Title;
11
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
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}
Exceptions for config failures.
array $exclusiveRights
Array of rights that a user should only have if they authenticated with 2FA.
__construct( $exclusiveRights, $session, $title, $user, $action, &$result)
Manages data for an an authenticated session.
Definition Session.php:48
Group all the pieces relevant to the context of a request into one instance.
static getMain()
Get the RequestContext object associated with the main request.
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
getRequest()
Get the WebRequest object to use with this object.
Definition User.php:3737