Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[lhc/web/wiklou.git] / includes / htmlform / fields / HTMLExpiryField.php
1 <?php
2
3 use MediaWiki\Widget\ExpiryInputWidget;
4
5 /**
6 * Expiry Field that allows the user to specify a precise date or a
7 * relative date string.
8 */
9 class HTMLExpiryField extends HTMLFormField {
10
11 /**
12 * @var HTMLFormField
13 */
14 protected $relativeField;
15
16 /**
17 * Relative Date Time Field.
18 * @param array $params
19 */
20 public function __construct( array $params = [] ) {
21 parent::__construct( $params );
22
23 $type = !empty( $params['options'] ) ? 'selectorother' : 'text';
24 $this->relativeField = $this->getFieldByType( $type );
25 }
26
27 /**
28 * @inheritDoc
29 *
30 * Use whatever the relative field is as the standard HTML input.
31 */
32 public function getInputHTML( $value ) {
33 return $this->relativeField->getInputHTML( $value );
34 }
35
36 protected function shouldInfuseOOUI() {
37 return true;
38 }
39
40 /**
41 * @inheritDoc
42 */
43 protected function getOOUIModules() {
44 return array_merge(
45 [
46 'mediawiki.widgets.expiry',
47 ],
48 $this->relativeField->getOOUIModules()
49 );
50 }
51
52 /**
53 * @inheritDoc
54 */
55 public function getInputOOUI( $value ) {
56 return new ExpiryInputWidget(
57 $this->relativeField->getInputOOUI( $value ),
58 [
59 'id' => $this->mID,
60 'required' => $this->mParams['required'] ?? false,
61 ]
62 );
63 }
64
65 /**
66 * @inheritDoc
67 */
68 public function loadDataFromRequest( $request ) {
69 return $this->relativeField->loadDataFromRequest( $request );
70 }
71
72 /**
73 * Get the HTMLForm field by the type string.
74 *
75 * @param string $type
76 * @return \HTMLFormField
77 */
78 protected function getFieldByType( $type ) {
79 $class = HTMLForm::$typeMappings[$type];
80 $params = $this->mParams;
81 $params['type'] = $type;
82 $params['class'] = $class;
83
84 // Remove Parameters that are being used on the parent.
85 unset( $params['label-message'] );
86 return new $class( $params );
87 }
88
89 }