MediaWiki  master
RememberMeAuthenticationRequest.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Auth;
23 
26 use UnexpectedValueException;
27 
36 
42  public const CHOOSE_REMEMBER = 'choose';
43 
48  public const FORCE_CHOOSE_REMEMBER = 'force-choose';
49 
53  public const ALWAYS_REMEMBER = 'always';
54 
58  public const NEVER_REMEMBER = 'never';
59 
63  public const ALLOWED_FLAGS = [
68  ];
69 
76 
83  public $skippable = true;
84 
86  private $checkbox = false;
87 
92  protected $expiration = null;
93 
95  public $rememberMe = false;
96 
101  public function __construct( string $flag = self::CHOOSE_REMEMBER ) {
103  $provider = SessionManager::getGlobalSession()->getProvider();
104  '@phan-var SessionProvider $provider';
105 
106  switch ( $flag ) {
108  $this->skippable = true;
109  $this->checkbox = true;
110  $this->expiration = $provider->getRememberUserDuration();
111  break;
113  $this->skippable = false;
114  $this->checkbox = true;
115  $this->expiration = $provider->getRememberUserDuration();
116  break;
118  $this->skippable = true;
119  $this->checkbox = false;
120  $this->expiration = $provider->getRememberUserDuration();
121  break;
123  $this->skippable = true;
124  $this->checkbox = false;
125  $this->expiration = null;
126  break;
127  default:
128  throw new UnexpectedValueException( '$flag must be one of the values: \'' .
129  implode( "', '", self::ALLOWED_FLAGS ) . '\'' );
130  }
131  }
132 
137  public function getFieldInfo() {
138  if ( !$this->expiration || !$this->checkbox ) {
139  return [];
140  }
141 
142  $expirationDays = ceil( $this->expiration / ( 3600 * 24 ) );
143  return [
144  'rememberMe' => [
145  'type' => 'checkbox',
146  'label' => wfMessage( 'userlogin-remembermypassword' )->numParams( $expirationDays ),
147  'help' => wfMessage( 'authmanager-userlogin-remembermypassword-help' ),
148  'optional' => true,
149  'skippable' => $this->skippable,
150  ]
151  ];
152  }
153 }
MediaWiki\Auth\AuthenticationRequest\OPTIONAL
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
Definition: AuthenticationRequest.php:41
MediaWiki\Auth\RememberMeAuthenticationRequest\getFieldInfo
getFieldInfo()
Fetch input field info.The field info is an associative array mapping field names to info arrays....
Definition: RememberMeAuthenticationRequest.php:137
MediaWiki\Auth\RememberMeAuthenticationRequest\ALWAYS_REMEMBER
const ALWAYS_REMEMBER
Indicates that the user will always be remembered.
Definition: RememberMeAuthenticationRequest.php:53
MediaWiki\Auth\RememberMeAuthenticationRequest\$required
bool $required
Whether this field must be filled in on the form.
Definition: RememberMeAuthenticationRequest.php:75
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1182
MediaWiki\Auth\RememberMeAuthenticationRequest\NEVER_REMEMBER
const NEVER_REMEMBER
Indicates that the user will never be rememberd.
Definition: RememberMeAuthenticationRequest.php:58
MediaWiki\Auth\RememberMeAuthenticationRequest\$rememberMe
bool $rememberMe
Definition: RememberMeAuthenticationRequest.php:95
MediaWiki\Session\SessionProvider
A SessionProvider provides SessionInfo and support for Session.
Definition: SessionProvider.php:81
MediaWiki\Auth\RememberMeAuthenticationRequest\ALLOWED_FLAGS
const ALLOWED_FLAGS
Allowed configuration flags.
Definition: RememberMeAuthenticationRequest.php:63
MediaWiki\Auth\RememberMeAuthenticationRequest\$checkbox
bool $checkbox
Definition: RememberMeAuthenticationRequest.php:86
MediaWiki\Session\SessionManager\getGlobalSession
static getGlobalSession()
If PHP's session_id() has been set, returns that session.
Definition: SessionManager.php:146
MediaWiki\Auth\RememberMeAuthenticationRequest\CHOOSE_REMEMBER
const CHOOSE_REMEMBER
Indicates that the user may be able to choose whether to be remembered or not.
Definition: RememberMeAuthenticationRequest.php:42
MediaWiki\Auth\RememberMeAuthenticationRequest\FORCE_CHOOSE_REMEMBER
const FORCE_CHOOSE_REMEMBER
Indicates that the user will be able to choose whether to be remembered or not.
Definition: RememberMeAuthenticationRequest.php:48
MediaWiki\Session\SessionManager
This serves as the entry point to the MediaWiki session handling system.
Definition: SessionManager.php:83
MediaWiki\Auth\RememberMeAuthenticationRequest
This is an authentication request added by AuthManager to show a "remember me" checkbox.
Definition: RememberMeAuthenticationRequest.php:35
MediaWiki\Auth\RememberMeAuthenticationRequest\$expiration
int null $expiration
How long the user will be remembered, in seconds.
Definition: RememberMeAuthenticationRequest.php:92
MediaWiki\Auth\RememberMeAuthenticationRequest\__construct
__construct(string $flag=self::CHOOSE_REMEMBER)
Definition: RememberMeAuthenticationRequest.php:101
MediaWiki\Auth\RememberMeAuthenticationRequest\$skippable
bool $skippable
Whether display of this field can be skipped, accepting the default value, if there are no other fiel...
Definition: RememberMeAuthenticationRequest.php:83
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:38