Merge "Use {{int:}} on MediaWiki:Blockedtext and MediaWiki:Autoblockedtext"
[lhc/web/wiklou.git] / includes / widget / ExpiryInputWidget.php
1 <?php
2
3 namespace MediaWiki\Widget;
4
5 use OOUI\Widget;
6
7 /**
8 * Expiry widget.
9 *
10 * Allows the user to toggle between a precise time or enter a relative time,
11 * regardless, the value comes in as a relative time.
12 *
13 * @copyright 2018 MediaWiki Widgets Team and others; see AUTHORS.txt
14 * @license MIT
15 */
16 class ExpiryInputWidget extends Widget {
17
18 /**
19 * @var Widget
20 */
21 protected $relativeInput;
22
23 /**
24 * @var bool
25 */
26 protected $noDatePicker;
27
28 /**
29 * @var bool
30 */
31 protected $required;
32
33 /**
34 * @param Widget $relativeInput
35 * @param array $options Configuration options
36 */
37 public function __construct( Widget $relativeInput, array $options = [] ) {
38 $config = \RequestContext::getMain()->getConfig();
39
40 $options['noDatePicker'] = $config->get( 'ExpiryWidgetNoDatePicker' );
41
42 parent::__construct( $options );
43
44 $this->noDatePicker = $options['noDatePicker'];
45 $this->required = isset( $options['required'] ) ? $options['required'] : false;
46
47 // Properties
48 $this->relativeInput = $relativeInput;
49 $this->relativeInput->addClasses( [ 'mw-widget-ExpiryWidget-relative' ] );
50
51 // Initialization
52 $classes = [
53 'mw-widget-ExpiryWidget',
54 ];
55 if ( $options['noDatePicker'] === false ) {
56 $classes[] = 'mw-widget-ExpiryWidget-hasDatePicker';
57 }
58 $this
59 ->addClasses( $classes )
60 ->appendContent( $this->relativeInput );
61 }
62
63 protected function getJavaScriptClassName() {
64 return 'mw.widgets.ExpiryWidget';
65 }
66
67 /**
68 * {@inheritdoc}
69 */
70 public function getConfig( &$config ) {
71 $config['noDatePicker'] = $this->noDatePicker;
72 $config['required'] = $this->required;
73 $config['relativeInput'] = [];
74 $this->relativeInput->getConfig( $config['relativeInput'] );
75 return parent::getConfig( $config );
76 }
77 }