GitInfo: Don't try shelling out if it's disabled
[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 */
19 public function __construct( array $params = [] ) {
20 parent::__construct( $params );
21
22 $type = !empty( $params['options'] ) ? 'selectorother' : 'text';
23 $this->relativeField = $this->getFieldByType( $type );
24 }
25
26 /**
27 * {@inheritdoc}
28 *
29 * Use whatever the relative field is as the standard HTML input.
30 */
31 public function getInputHTML( $value ) {
32 return $this->relativeField->getInputHTML( $value );
33 }
34
35 protected function shouldInfuseOOUI() {
36 return true;
37 }
38
39 /**
40 * {@inheritdoc}
41 */
42 protected function getOOUIModules() {
43 return array_merge(
44 [
45 'mediawiki.widgets.expiry',
46 ],
47 $this->relativeField->getOOUIModules()
48 );
49 }
50
51 /**
52 * {@inheritdoc}
53 */
54 public function getInputOOUI( $value ) {
55 return new ExpiryInputWidget(
56 $this->relativeField->getInputOOUI( $value ),
57 [
58 'id' => $this->mID,
59 'required' => $this->mParams['required'] ?? false,
60 ]
61 );
62 }
63
64 /**
65 * {@inheritdoc}
66 */
67 public function loadDataFromRequest( $request ) {
68 return $this->relativeField->loadDataFromRequest( $request );
69 }
70
71 /**
72 * Get the HTMLForm field by the type string.
73 *
74 * @param string $type
75 * @return \HTMLFormField
76 */
77 protected function getFieldByType( $type ) {
78 $class = HTMLForm::$typeMappings[$type];
79 $params = $this->mParams;
80 $params['type'] = $type;
81 $params['class'] = $class;
82
83 // Remove Parameters that are being used on the parent.
84 unset( $params['label-message'] );
85 return new $class( $params );
86 }
87
88 }