Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / fields / HTMLExpiryField.php
blob62daa738d7d6efd749da9155156cf3394ebcb677
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 use MediaWiki\HTMLForm\HTMLForm;
6 use MediaWiki\HTMLForm\HTMLFormField;
7 use MediaWiki\Widget\ExpiryInputWidget;
9 /**
10 * Expiry Field that allows the user to specify a precise date or a
11 * relative date string.
13 * @stable to extend
15 class HTMLExpiryField extends HTMLFormField {
17 /**
18 * @var HTMLFormField
20 protected $relativeField;
22 /**
23 * Relative Date Time Field.
25 * @stable to call
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 );
35 /**
36 * @inheritDoc
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() {
45 return true;
48 /**
49 * @inheritDoc
51 protected function getOOUIModules() {
52 return array_merge(
54 'mediawiki.widgets.expiry',
56 $this->relativeField->getOOUIModules()
60 /**
61 * @inheritDoc
63 public function getInputOOUI( $value ) {
64 return new ExpiryInputWidget(
65 $this->relativeField->getInputOOUI( $value ),
67 'id' => $this->mID,
68 'required' => $this->mParams['required'] ?? false,
73 public function getInputCodex( $value, $hasErrors ) {
74 return $this->relativeField->getInputCodex( $value, $hasErrors );
77 /**
78 * @inheritDoc
80 public function loadDataFromRequest( $request ) {
81 return $this->relativeField->loadDataFromRequest( $request );
84 /**
85 * Get the HTMLForm field by the type string.
87 * @param string $type
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' );