MediaWiki REL1_37
RememberMeAuthenticationRequest.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
26use 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}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
This is a value object for authentication requests.
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
This is an authentication request added by AuthManager to show a "remember me" checkbox.
const CHOOSE_REMEMBER
Indicates that the user may be able to choose whether to be remembered or not.
const ALWAYS_REMEMBER
Indicates that the user will always be remembered.
bool $required
Whether this field must be filled in on the form.
int null $expiration
How long the user will be remembered, in seconds.
getFieldInfo()
Fetch input field info.The field info is an associative array mapping field names to info arrays....
const FORCE_CHOOSE_REMEMBER
Indicates that the user will be able to choose whether to be remembered or not.
bool $skippable
Whether display of this field can be skipped, accepting the default value, if there are no other fiel...
const NEVER_REMEMBER
Indicates that the user will never be rememberd.
This serves as the entry point to the MediaWiki session handling system.
A SessionProvider provides SessionInfo and support for Session.