MediaWiki REL1_34
ButtonAuthenticationRequest.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
24use 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}
This is a value object for authentication requests.
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
int $required
For login, continue, and link actions, one of self::OPTIONAL, self::REQUIRED, or self::PRIMARY_REQUIR...
const REQUIRED
Indicates that the request is required for authentication to proceed.
This is an authentication request that just implements a simple button.
static getRequestByName(array $reqs, $name)
Fetch a ButtonAuthenticationRequest or subclass by name.
getUniqueId()
Supply a unique key for deduplication.
__construct( $name, Message $label, Message $help, $required=false)
The Message class provides methods which fulfil two basic services:
Definition Message.php:162
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition Message.php:410