| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Auth; |
| 23 |
|
| 24 |
use MediaWiki\Language\RawMessage; |
| 25 |
use MediaWiki\Message\Message; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#[\AllowDynamicProperties] |
| 34 |
class ButtonAuthenticationRequest extends AuthenticationRequest { |
| 35 |
|
| 36 |
protected $name; |
| 37 |
|
| 38 |
|
| 39 |
protected $label; |
| 40 |
|
| 41 |
|
| 42 |
protected $help; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function __construct( $name, Message $label, Message $help, $required = false ) { |
| 52 |
$this->name = $name; |
| 53 |
$this->label = $label; |
| 54 |
$this->help = $help; |
| 55 |
$this->required = $required ? self::REQUIRED : self::OPTIONAL; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public function getUniqueId() { |
| 63 |
return parent::getUniqueId() . ':' . $this->name; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public function getFieldInfo() { |
| 71 |
return [ |
| 72 |
$this->name => [ |
| 73 |
'type' => 'button', |
| 74 |
'label' => $this->label, |
| 75 |
'help' => $this->help, |
| 76 |
] |
| 77 |
]; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public static function getRequestByName( array $reqs, $name ) { |
| 88 |
$requests = array_filter( $reqs, static function ( $req ) use ( $name ) { |
| 89 |
return $req instanceof ButtonAuthenticationRequest && $req->name === $name; |
| 90 |
} ); |
| 91 |
|
| 92 |
return count( $requests ) === 1 ? reset( $requests ) : null; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public static function __set_state( $data ) { |
| 102 |
if ( !isset( $data['label'] ) ) { |
| 103 |
$data['label'] = new RawMessage( '$1', $data['name'] ); |
| 104 |
} elseif ( is_string( $data['label'] ) ) { |
| 105 |
$data['label'] = new Message( $data['label'] ); |
| 106 |
} elseif ( is_array( $data['label'] ) && $data['label'] ) { |
| 107 |
|
| 108 |
$data['label'] = Message::newFromKey( ...$data['label'] ); |
| 109 |
} |
| 110 |
if ( !isset( $data['help'] ) ) { |
| 111 |
$data['help'] = new RawMessage( '$1', $data['name'] ); |
| 112 |
} elseif ( is_string( $data['help'] ) ) { |
| 113 |
$data['help'] = new Message( $data['help'] ); |
| 114 |
} elseif ( is_array( $data['help'] ) && $data['help'] ) { |
| 115 |
|
| 116 |
$data['help'] = Message::newFromKey( ...$data['help'] ); |
| 117 |
} |
| 118 |
$ret = new static( $data['name'], $data['label'], $data['help'] ); |
| 119 |
foreach ( $data as $k => $v ) { |
| 120 |
$ret->$k = $v; |
| 121 |
} |
| 122 |
return $ret; |
| 123 |
} |
| 124 |
} |