MediaWiki  master
DateInputWidget.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Widget;
4 
6 
14 class DateInputWidget extends \OOUI\TextInputWidget {
15 
16  protected $inputFormat = null;
17  protected $displayFormat = null;
18  protected $longDisplayFormat = null;
19  protected $placeholderLabel = null;
20  protected $placeholderDateFormat = null;
21  protected $precision = null;
22  protected $mustBeAfter = null;
23  protected $mustBeBefore = null;
24 
51  public function __construct( array $config = [] ) {
52  $config = array_merge( [
53  // Default config values
54  'precision' => 'day',
55  'longDisplayFormat' => false,
56  ], $config );
57 
58  // Properties
59  if ( isset( $config['inputFormat'] ) ) {
60  $this->inputFormat = $config['inputFormat'];
61  }
62  if ( isset( $config['placeholderDateFormat'] ) ) {
63  $this->placeholderDateFormat = $config['placeholderDateFormat'];
64  }
65  $this->precision = $config['precision'];
66  if ( isset( $config['mustBeAfter'] ) ) {
67  $this->mustBeAfter = $config['mustBeAfter'];
68  }
69  if ( isset( $config['mustBeBefore'] ) ) {
70  $this->mustBeBefore = $config['mustBeBefore'];
71  }
72 
73  // Properties stored for the infused JS widget
74  if ( isset( $config['displayFormat'] ) ) {
75  $this->displayFormat = $config['displayFormat'];
76  }
77  if ( isset( $config['longDisplayFormat'] ) ) {
78  $this->longDisplayFormat = $config['longDisplayFormat'];
79  }
80  if ( isset( $config['placeholderLabel'] ) ) {
81  $this->placeholderLabel = $config['placeholderLabel'];
82  }
83 
84  // Set up placeholder text visible if the browser doesn't override it (logic taken from JS)
85  if ( $this->placeholderDateFormat !== null ) {
86  $placeholder = $this->placeholderDateFormat;
87  } elseif ( $this->inputFormat !== null ) {
88  // We have no way to display a translated placeholder for custom formats
89  $placeholder = '';
90  } else {
91  $placeholder = wfMessage( "mw-widgets-dateinput-placeholder-$this->precision" )->text();
92  }
93 
94  $config = array_merge( [
95  // Processed config values
96  'placeholder' => $placeholder,
97  ], $config );
98 
99  parent::__construct( $config );
100 
101  // Calculate min/max attributes (which are skipped by TextInputWidget) and add to <input>
102  // min/max attributes are inclusive, but mustBeAfter/Before are exclusive
103  if ( $this->mustBeAfter !== null ) {
104  $min = new DateTime( $this->mustBeAfter );
105  $min = $min->modify( '+1 day' );
106  $min = $min->format( 'Y-m-d' );
107  $this->input->setAttributes( [ 'min' => $min ] );
108  }
109  if ( $this->mustBeBefore !== null ) {
110  $max = new DateTime( $this->mustBeBefore );
111  $max = $max->modify( '-1 day' );
112  $max = $max->format( 'Y-m-d' );
113  $this->input->setAttributes( [ 'max' => $max ] );
114  }
115 
116  // Initialization
117  $this->addClasses( [ 'mw-widget-dateInputWidget' ] );
118  }
119 
120  protected function getJavaScriptClassName() {
121  return 'mw.widgets.DateInputWidget';
122  }
123 
124  public function getConfig( &$config ) {
125  if ( $this->inputFormat !== null ) {
126  $config['inputFormat'] = $this->inputFormat;
127  }
128  if ( $this->displayFormat !== null ) {
129  $config['displayFormat'] = $this->displayFormat;
130  }
131  if ( $this->longDisplayFormat !== null ) {
132  $config['longDisplayFormat'] = $this->longDisplayFormat;
133  }
134  if ( $this->placeholderLabel !== null ) {
135  $config['placeholderLabel'] = $this->placeholderLabel;
136  }
137  if ( $this->placeholderDateFormat !== null ) {
138  $config['placeholderDateFormat'] = $this->placeholderDateFormat;
139  }
140  if ( $this->precision !== null ) {
141  $config['precision'] = $this->precision;
142  }
143  if ( $this->mustBeAfter !== null ) {
144  $config['mustBeAfter'] = $this->mustBeAfter;
145  }
146  if ( $this->mustBeBefore !== null ) {
147  $config['mustBeBefore'] = $this->mustBeBefore;
148  }
149  $config['$overlay'] = true;
150  return parent::getConfig( $config );
151  }
152 
153  public function getInputElement( $config ) {
154  // Inserts date/month type attribute
155  return parent::getInputElement( $config )
156  ->setAttributes( [
157  'type' => ( $config['precision'] === 'month' ) ? 'month' : 'date'
158  ] );
159  }
160 }
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Config $config
Definition: MediaWiki.php:43
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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 use $formDescriptor instead 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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35