MediaWiki  master
ButtonAuthenticationRequest.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Auth;
23 
24 use Message;
25 use RawMessage;
26 
35  protected $name;
36 
38  protected $label;
39 
41  protected $help;
42 
50  public function __construct( $name, Message $label, Message $help, $required = false ) {
51  $this->name = $name;
52  $this->label = $label;
53  $this->help = $help;
54  $this->required = $required ? self::REQUIRED : self::OPTIONAL;
55  }
56 
61  public function getUniqueId() {
62  return parent::getUniqueId() . ':' . $this->name;
63  }
64 
69  public function getFieldInfo() {
70  return [
71  $this->name => [
72  'type' => 'button',
73  'label' => $this->label,
74  'help' => $this->help,
75  ]
76  ];
77  }
78 
86  public static function getRequestByName( array $reqs, $name ) {
87  $requests = array_filter( $reqs, function ( $req ) use ( $name ) {
88  return $req instanceof ButtonAuthenticationRequest && $req->name === $name;
89  } );
90  return count( $requests ) === 1 ? reset( $requests ) : null;
91  }
92 
99  public static function __set_state( $data ) {
100  if ( !isset( $data['label'] ) ) {
101  $data['label'] = new RawMessage( '$1', $data['name'] );
102  } elseif ( is_string( $data['label'] ) ) {
103  $data['label'] = new Message( $data['label'] );
104  } elseif ( is_array( $data['label'] ) ) {
105  $data['label'] = Message::newFromKey( ...$data['label'] );
106  }
107  if ( !isset( $data['help'] ) ) {
108  $data['help'] = new RawMessage( '$1', $data['name'] );
109  } elseif ( is_string( $data['help'] ) ) {
110  $data['help'] = new Message( $data['help'] );
111  } elseif ( is_array( $data['help'] ) ) {
112  $data['help'] = Message::newFromKey( ...$data['help'] );
113  }
114  $ret = new static( $data['name'], $data['label'], $data['help'] );
115  foreach ( $data as $k => $v ) {
116  $ret->$k = $v;
117  }
118  return $ret;
119  }
120 }
MediaWiki\Auth\ButtonAuthenticationRequest\$name
string $name
Definition: ButtonAuthenticationRequest.php:35
MediaWiki\Auth\AuthenticationRequest\OPTIONAL
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
Definition: AuthenticationRequest.php:41
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:64
MediaWiki\Auth\ButtonAuthenticationRequest\$label
Message $label
Definition: ButtonAuthenticationRequest.php:38
MediaWiki\Auth\ButtonAuthenticationRequest\$help
Message $help
Definition: ButtonAuthenticationRequest.php:41
MediaWiki\Auth\ButtonAuthenticationRequest\__construct
__construct( $name, Message $label, Message $help, $required=false)
Stable to call.
Definition: ButtonAuthenticationRequest.php:50
MediaWiki\Auth\ButtonAuthenticationRequest\getFieldInfo
getFieldInfo()
Fetch input field info.The field info is an associative array mapping field names to info arrays....
Definition: ButtonAuthenticationRequest.php:69
MediaWiki\Auth\ButtonAuthenticationRequest\getRequestByName
static getRequestByName(array $reqs, $name)
Fetch a ButtonAuthenticationRequest or subclass by name.
Definition: ButtonAuthenticationRequest.php:86
MediaWiki\Auth\ButtonAuthenticationRequest\__set_state
static __set_state( $data)
Stable to override.
Definition: ButtonAuthenticationRequest.php:99
Message\newFromKey
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition: Message.php:419
MediaWiki\Auth\ButtonAuthenticationRequest
This is an authentication request that just implements a simple button.
Definition: ButtonAuthenticationRequest.php:33
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:161
RawMessage
Variant of the Message class.
Definition: RawMessage.php:35
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:38
MediaWiki\Auth\AuthenticationRequest\REQUIRED
const REQUIRED
Indicates that the request is required for authentication to proceed.
Definition: AuthenticationRequest.php:47
MediaWiki\Auth\ButtonAuthenticationRequest\getUniqueId
getUniqueId()
Supply a unique key for deduplication.When the AuthenticationRequests instances returned by the provi...
Definition: ButtonAuthenticationRequest.php:61