MediaWiki  1.34.0
CheckExclusiveRights.php
Go to the documentation of this file.
1 <?php
2 
4 
9 use User;
10 use Title;
11 
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 
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 }
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights
Definition: CheckExclusiveRights.php:12
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$user
User $user
Definition: CheckExclusiveRights.php:34
MediaWiki\Extension\OATHAuth\OATHAuth\AUTHENTICATED_OVER_2FA
const AUTHENTICATED_OVER_2FA
Definition: OATHAuth.php:15
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\__construct
__construct( $exclusiveRights, $session, $title, $user, $action, &$result)
Definition: CheckExclusiveRights.php:73
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\actionBlocked
actionBlocked()
Definition: CheckExclusiveRights.php:102
User\getRequest
getRequest()
Get the WebRequest object to use with this object.
Definition: User.php:3631
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$result
string array $result
Definition: CheckExclusiveRights.php:44
MediaWiki\Extension\OATHAuth\OATHAuth
Definition: OATHAuth.php:14
MediaWiki\Session\Session
Manages data for an an authenticated session.
Definition: Session.php:48
Config\get
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
ConfigException
Exceptions for config failures.
Definition: ConfigException.php:28
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$session
Session $session
Definition: CheckExclusiveRights.php:24
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:33
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\addError
addError()
Definition: CheckExclusiveRights.php:106
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$action
string $action
Definition: CheckExclusiveRights.php:39
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:431
Config\has
has( $name)
Check whether a configuration option is set for the given name.
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\authenticatedOver2FA
authenticatedOver2FA()
Definition: CheckExclusiveRights.php:98
Title
Represents a title within MediaWiki.
Definition: Title.php:42
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\callback
static callback( $title, $user, $action, &$result)
Definition: CheckExclusiveRights.php:54
MediaWiki\$config
Config $config
Definition: MediaWiki.php:43
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors
Definition: CheckExclusiveRights.php:3
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
MediaWiki\Extension\OATHAuth\Hook\GetUserPermissionsErrors\CheckExclusiveRights\$title
Title $title
Definition: CheckExclusiveRights.php:29