3 namespace MediaWiki\HTMLForm\Field
;
5 use MediaWiki\HTMLForm\HTMLForm
;
6 use MediaWiki\HTMLForm\HTMLFormField
;
7 use MediaWiki\Widget\ExpiryInputWidget
;
10 * Expiry Field that allows the user to specify a precise date or a
11 * relative date string.
15 class HTMLExpiryField
extends HTMLFormField
{
20 protected $relativeField;
23 * Relative Date Time Field.
26 * @param array $params
28 public function __construct( array $params = [] ) {
29 parent
::__construct( $params );
31 $type = !empty( $params['options'] ) ?
'selectorother' : 'text';
32 $this->relativeField
= $this->getFieldByType( $type );
38 * Use whatever the relative field is as the standard HTML input.
40 public function getInputHTML( $value ) {
41 return $this->relativeField
->getInputHTML( $value );
44 protected function shouldInfuseOOUI() {
51 protected function getOOUIModules() {
54 'mediawiki.widgets.expiry',
56 $this->relativeField
->getOOUIModules()
63 public function getInputOOUI( $value ) {
64 return new ExpiryInputWidget(
65 $this->relativeField
->getInputOOUI( $value ),
68 'required' => $this->mParams
['required'] ??
false,
73 public function getInputCodex( $value, $hasErrors ) {
74 return $this->relativeField
->getInputCodex( $value, $hasErrors );
80 public function loadDataFromRequest( $request ) {
81 return $this->relativeField
->loadDataFromRequest( $request );
85 * Get the HTMLForm field by the type string.
88 * @return HTMLFormField
90 protected function getFieldByType( $type ) {
91 $class = HTMLForm
::$typeMappings[$type];
92 $params = $this->mParams
;
93 $params['type'] = $type;
94 $params['class'] = $class;
96 // Remove Parameters that are being used on the parent.
97 unset( $params['label-message'] );
98 return new $class( $params );
103 /** @deprecated class alias since 1.42 */
104 class_alias( HTMLExpiryField
::class, 'HTMLExpiryField' );