MediaWiki REL1_30
DateInputWidget.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Widget;
10
11use DateTime;
12
18class DateInputWidget extends \OOUI\TextInputWidget {
19
20 protected $inputFormat = null;
21 protected $displayFormat = null;
22 protected $longDisplayFormat = null;
23 protected $placeholderLabel = null;
24 protected $placeholderDateFormat = null;
25 protected $precision = null;
26 protected $mustBeAfter = null;
27 protected $mustBeBefore = null;
28 protected $overlay = null;
29
61 public function __construct( array $config = [] ) {
62 $config = array_merge( [
63 // Default config values
64 'precision' => 'day',
65 'longDisplayFormat' => false,
66 ], $config );
67
68 // Properties
69 if ( isset( $config['inputFormat'] ) ) {
70 $this->inputFormat = $config['inputFormat'];
71 }
72 if ( isset( $config['placeholderDateFormat'] ) ) {
73 $this->placeholderDateFormat = $config['placeholderDateFormat'];
74 }
75 $this->precision = $config['precision'];
76 if ( isset( $config['mustBeAfter'] ) ) {
77 $this->mustBeAfter = $config['mustBeAfter'];
78 }
79 if ( isset( $config['mustBeBefore'] ) ) {
80 $this->mustBeBefore = $config['mustBeBefore'];
81 }
82
83 // Properties stored for the infused JS widget
84 if ( isset( $config['displayFormat'] ) ) {
85 $this->displayFormat = $config['displayFormat'];
86 }
87 if ( isset( $config['longDisplayFormat'] ) ) {
88 $this->longDisplayFormat = $config['longDisplayFormat'];
89 }
90 if ( isset( $config['placeholderLabel'] ) ) {
91 $this->placeholderLabel = $config['placeholderLabel'];
92 }
93 if ( isset( $config['overlay'] ) ) {
94 $this->overlay = $config['overlay'];
95 }
96
97 // Set up placeholder text visible if the browser doesn't override it (logic taken from JS)
98 if ( $this->placeholderDateFormat !== null ) {
99 $placeholder = $this->placeholderDateFormat;
100 } elseif ( $this->inputFormat !== null ) {
101 // We have no way to display a translated placeholder for custom formats
102 $placeholder = '';
103 } else {
104 $placeholder = wfMessage( "mw-widgets-dateinput-placeholder-$this->precision" )->text();
105 }
106
107 $config = array_merge( [
108 // Processed config values
109 'placeholder' => $placeholder,
110 ], $config );
111
112 // Parent constructor
113 parent::__construct( $config );
114
115 // Calculate min/max attributes (which are skipped by TextInputWidget) and add to <input>
116 // min/max attributes are inclusive, but mustBeAfter/Before are exclusive
117 if ( $this->mustBeAfter !== null ) {
118 $min = new DateTime( $this->mustBeAfter );
119 $min = $min->modify( '+1 day' );
120 $min = $min->format( 'Y-m-d' );
121 $this->input->setAttributes( [ 'min' => $min ] );
122 }
123 if ( $this->mustBeBefore !== null ) {
124 $max = new DateTime( $this->mustBeBefore );
125 $max = $max->modify( '-1 day' );
126 $max = $max->format( 'Y-m-d' );
127 $this->input->setAttributes( [ 'max' => $max ] );
128 }
129
130 // Initialization
131 $this->addClasses( [ 'mw-widget-dateInputWidget' ] );
132 }
133
134 protected function getJavaScriptClassName() {
135 return 'mw.widgets.DateInputWidget';
136 }
137
138 public function getConfig( &$config ) {
139 if ( $this->inputFormat !== null ) {
140 $config['inputFormat'] = $this->inputFormat;
141 }
142 if ( $this->displayFormat !== null ) {
143 $config['displayFormat'] = $this->displayFormat;
144 }
145 if ( $this->longDisplayFormat !== null ) {
146 $config['longDisplayFormat'] = $this->longDisplayFormat;
147 }
148 if ( $this->placeholderLabel !== null ) {
149 $config['placeholderLabel'] = $this->placeholderLabel;
150 }
151 if ( $this->placeholderDateFormat !== null ) {
152 $config['placeholderDateFormat'] = $this->placeholderDateFormat;
153 }
154 if ( $this->precision !== null ) {
155 $config['precision'] = $this->precision;
156 }
157 if ( $this->mustBeAfter !== null ) {
158 $config['mustBeAfter'] = $this->mustBeAfter;
159 }
160 if ( $this->mustBeBefore !== null ) {
161 $config['mustBeBefore'] = $this->mustBeBefore;
162 }
163 if ( $this->overlay !== null ) {
164 $config['overlay'] = $this->overlay;
165 }
166 return parent::getConfig( $config );
167 }
168
169 public function getInputElement( $config ) {
170 // Inserts date/month type attribute
171 return parent::getInputElement( $config )
172 ->setAttributes( [
173 'type' => ( $config['precision'] === 'month' ) ? 'month' : 'date'
174 ] );
175 }
176}
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
MediaWiki Widgets – ComplexNamespaceInputWidget class.