MediaWiki  1.34.0
SetIsEnabled.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
9 class SetIsEnabled {
13  protected $authUser;
14 
18  protected $isEnabled;
19 
24  public static function callback( &$isEnabled ) {
25  $userRepo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' );
26  $authUser = $userRepo->findByUser( RequestContext::getMain()->getUser() );
27  $handler = new static( $authUser, $isEnabled );
28  return $handler->execute();
29  }
30 
36  protected function __construct( $authUser, &$isEnabled ) {
37  $this->authUser = $authUser;
38  $this->isEnabled = &$isEnabled;
39  }
40 
41  protected function execute() {
42  if ( $this->authUser && $this->authUser->getModule() !== null ) {
43  $this->isEnabled = true;
44  # This two-factor extension is enabled by the user,
45  # we don't need to check others.
46  return false;
47  } else {
48  $this->isEnabled = false;
49  # This two-factor extension isn't enabled by the user,
50  # but others may be.
51  return true;
52  }
53  }
54 }
MediaWiki\Extension\OATHAuth\Hook\TwoFactorIsEnabled\SetIsEnabled\$authUser
OATHUser $authUser
Definition: SetIsEnabled.php:13
MediaWiki\Extension\OATHAuth\Hook\TwoFactorIsEnabled\SetIsEnabled\execute
execute()
Definition: SetIsEnabled.php:41
MediaWiki\Extension\OATHAuth\OATHUser
Class representing a user from OATH's perspective.
Definition: OATHUser.php:28
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
getUser
getUser()
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:138
MediaWiki\Extension\OATHAuth\Hook\TwoFactorIsEnabled\SetIsEnabled\__construct
__construct( $authUser, &$isEnabled)
SetIsEnabled constructor.
Definition: SetIsEnabled.php:36
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:33
MediaWiki\Extension\OATHAuth\Hook\TwoFactorIsEnabled\SetIsEnabled\callback
static callback(&$isEnabled)
Definition: SetIsEnabled.php:24
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:431
MediaWiki\Extension\OATHAuth\Hook\TwoFactorIsEnabled\SetIsEnabled\$isEnabled
bool $isEnabled
Definition: SetIsEnabled.php:18
MediaWiki\Extension\OATHAuth\Hook\TwoFactorIsEnabled
Definition: SetIsEnabled.php:3
MediaWiki\Extension\OATHAuth\Hook\TwoFactorIsEnabled\SetIsEnabled
Definition: SetIsEnabled.php:9