MediaWiki  1.34.0
ButtonAuthenticationRequest.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Auth;
23 
24 use Message;
25 
33  protected $name;
34 
36  protected $label;
37 
39  protected $help;
40 
47  public function __construct( $name, Message $label, Message $help, $required = false ) {
48  $this->name = $name;
49  $this->label = $label;
50  $this->help = $help;
51  $this->required = $required ? self::REQUIRED : self::OPTIONAL;
52  }
53 
54  public function getUniqueId() {
55  return parent::getUniqueId() . ':' . $this->name;
56  }
57 
58  public function getFieldInfo() {
59  return [
60  $this->name => [
61  'type' => 'button',
62  'label' => $this->label,
63  'help' => $this->help,
64  ]
65  ];
66  }
67 
75  public static function getRequestByName( array $reqs, $name ) {
76  $requests = array_filter( $reqs, function ( $req ) use ( $name ) {
77  return $req instanceof ButtonAuthenticationRequest && $req->name === $name;
78  } );
79  return count( $requests ) === 1 ? reset( $requests ) : null;
80  }
81 
87  public static function __set_state( $data ) {
88  if ( !isset( $data['label'] ) ) {
89  $data['label'] = new \RawMessage( '$1', $data['name'] );
90  } elseif ( is_string( $data['label'] ) ) {
91  $data['label'] = new \Message( $data['label'] );
92  } elseif ( is_array( $data['label'] ) ) {
93  $data['label'] = Message::newFromKey( ...$data['label'] );
94  }
95  if ( !isset( $data['help'] ) ) {
96  $data['help'] = new \RawMessage( '$1', $data['name'] );
97  } elseif ( is_string( $data['help'] ) ) {
98  $data['help'] = new \Message( $data['help'] );
99  } elseif ( is_array( $data['help'] ) ) {
100  $data['help'] = Message::newFromKey( ...$data['help'] );
101  }
102  $ret = new static( $data['name'], $data['label'], $data['help'] );
103  foreach ( $data as $k => $v ) {
104  $ret->$k = $v;
105  }
106  return $ret;
107  }
108 }
MediaWiki\Auth\ButtonAuthenticationRequest\$name
string $name
Definition: ButtonAuthenticationRequest.php:33
MediaWiki\Auth\AuthenticationRequest\OPTIONAL
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
Definition: AuthenticationRequest.php:40
MediaWiki\Auth\AuthenticationRequest\$required
int $required
For login, continue, and link actions, one of self::OPTIONAL, self::REQUIRED, or self::PRIMARY_REQUIR...
Definition: AuthenticationRequest.php:63
MediaWiki\Auth\ButtonAuthenticationRequest\$label
Message $label
Definition: ButtonAuthenticationRequest.php:36
MediaWiki\Auth\ButtonAuthenticationRequest\$help
Message $help
Definition: ButtonAuthenticationRequest.php:39
Message
MediaWiki\Auth\ButtonAuthenticationRequest\__construct
__construct( $name, Message $label, Message $help, $required=false)
Definition: ButtonAuthenticationRequest.php:47
MediaWiki\Auth\ButtonAuthenticationRequest\getFieldInfo
getFieldInfo()
Fetch input field info.
Definition: ButtonAuthenticationRequest.php:58
MediaWiki\Auth\ButtonAuthenticationRequest\getRequestByName
static getRequestByName(array $reqs, $name)
Fetch a ButtonAuthenticationRequest or subclass by name.
Definition: ButtonAuthenticationRequest.php:75
MediaWiki\Auth\ButtonAuthenticationRequest\__set_state
static __set_state( $data)
Definition: ButtonAuthenticationRequest.php:87
MediaWiki\Auth\ButtonAuthenticationRequest
This is an authentication request that just implements a simple button.
Definition: ButtonAuthenticationRequest.php:31
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:37
MediaWiki\Auth\AuthenticationRequest\REQUIRED
const REQUIRED
Indicates that the request is required for authentication to proceed.
Definition: AuthenticationRequest.php:46
MediaWiki\Auth\ButtonAuthenticationRequest\getUniqueId
getUniqueId()
Supply a unique key for deduplication.
Definition: ButtonAuthenticationRequest.php:54