3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 namespace MediaWiki\Auth
;
27 * This is an authentication request that just implements a simple button.
31 class ButtonAuthenticationRequest
extends AuthenticationRequest
{
42 * @param string $name Button name
43 * @param Message $label Button label
44 * @param Message $help Button help
45 * @param bool $required The button is required for authentication to proceed.
47 public function __construct( $name, Message
$label, Message
$help, $required = false ) {
49 $this->label
= $label;
51 $this->required
= $required ? self
::REQUIRED
: self
::OPTIONAL
;
54 public function getUniqueId() {
55 return parent
::getUniqueId() . ':' . $this->name
;
58 public function getFieldInfo() {
62 'label' => $this->label
,
63 'help' => $this->help
,
69 * Fetch a ButtonAuthenticationRequest or subclass by name
70 * @param AuthenticationRequest[] $reqs Requests to search
71 * @param string $name Name to look for
72 * @return ButtonAuthenticationRequest|null Returns null if there is not
73 * exactly one matching request.
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;
79 return count( $requests ) === 1 ?
reset( $requests ) : null;
85 public static function __set_state( $data ) {
86 if ( !isset( $data['label'] ) ) {
87 $data['label'] = new \
RawMessage( '$1', $data['name'] );
88 } elseif ( is_string( $data['label'] ) ) {
89 $data['label'] = new \
Message( $data['label'] );
90 } elseif ( is_array( $data['label'] ) ) {
91 $data['label'] = call_user_func_array( 'Message::newFromKey', $data['label'] );
93 if ( !isset( $data['help'] ) ) {
94 $data['help'] = new \
RawMessage( '$1', $data['name'] );
95 } elseif ( is_string( $data['help'] ) ) {
96 $data['help'] = new \
Message( $data['help'] );
97 } elseif ( is_array( $data['help'] ) ) {
98 $data['help'] = call_user_func_array( 'Message::newFromKey', $data['help'] );
100 $ret = new static( $data['name'], $data['label'], $data['help'] );
101 foreach ( $data as $k => $v ) {