'day', 'longDisplayFormat' => false, ], $config ); // Properties if ( isset( $config['inputFormat'] ) ) { $this->inputFormat = $config['inputFormat']; } if ( isset( $config['placeholderDateFormat'] ) ) { $this->placeholderDateFormat = $config['placeholderDateFormat']; } $this->precision = $config['precision']; if ( isset( $config['mustBeAfter'] ) ) { $this->mustBeAfter = $config['mustBeAfter']; } if ( isset( $config['mustBeBefore'] ) ) { $this->mustBeBefore = $config['mustBeBefore']; } // Properties stored for the infused JS widget if ( isset( $config['displayFormat'] ) ) { $this->displayFormat = $config['displayFormat']; } if ( isset( $config['longDisplayFormat'] ) ) { $this->longDisplayFormat = $config['longDisplayFormat']; } if ( isset( $config['placeholderLabel'] ) ) { $this->placeholderLabel = $config['placeholderLabel']; } // Set up placeholder text visible if the browser doesn't override it (logic taken from JS) if ( $this->placeholderDateFormat !== null ) { $placeholder = $this->placeholderDateFormat; } elseif ( $this->inputFormat !== null ) { // We have no way to display a translated placeholder for custom formats $placeholder = ''; } else { $placeholder = wfMessage( "mw-widgets-dateinput-placeholder-$this->precision" )->text(); } $config = array_merge( [ // Processed config values 'placeholder' => $placeholder, ], $config ); parent::__construct( $config ); // Calculate min/max attributes (which are skipped by TextInputWidget) and add to // min/max attributes are inclusive, but mustBeAfter/Before are exclusive if ( $this->mustBeAfter !== null ) { $min = new DateTime( $this->mustBeAfter ); $min = $min->modify( '+1 day' ); $min = $min->format( 'Y-m-d' ); $this->input->setAttributes( [ 'min' => $min ] ); } if ( $this->mustBeBefore !== null ) { $max = new DateTime( $this->mustBeBefore ); $max = $max->modify( '-1 day' ); $max = $max->format( 'Y-m-d' ); $this->input->setAttributes( [ 'max' => $max ] ); } // Initialization $this->addClasses( [ 'mw-widget-dateInputWidget' ] ); } protected function getJavaScriptClassName() { return 'mw.widgets.DateInputWidget'; } public function getConfig( &$config ) { if ( $this->inputFormat !== null ) { $config['inputFormat'] = $this->inputFormat; } if ( $this->displayFormat !== null ) { $config['displayFormat'] = $this->displayFormat; } if ( $this->longDisplayFormat !== null ) { $config['longDisplayFormat'] = $this->longDisplayFormat; } if ( $this->placeholderLabel !== null ) { $config['placeholderLabel'] = $this->placeholderLabel; } if ( $this->placeholderDateFormat !== null ) { $config['placeholderDateFormat'] = $this->placeholderDateFormat; } if ( $this->precision !== null ) { $config['precision'] = $this->precision; } if ( $this->mustBeAfter !== null ) { $config['mustBeAfter'] = $this->mustBeAfter; } if ( $this->mustBeBefore !== null ) { $config['mustBeBefore'] = $this->mustBeBefore; } $config['$overlay'] = true; return parent::getConfig( $config ); } public function getInputElement( $config ) { // Inserts date/month type attribute return parent::getInputElement( $config ) ->setAttributes( [ 'type' => ( $config['precision'] === 'month' ) ? 'month' : 'date' ] ); } }