MediaWiki REL1_37
HTMLFileField.php
Go to the documentation of this file.
1<?php
2
3use OOUI\Widget;
4
18 protected $mPlaceholder = '';
19 protected $mAccept = null;
20
22 protected $mMultiple;
23
32 public function __construct( $params ) {
33 if ( isset( $params['autocomplete'] ) && is_bool( $params['autocomplete'] ) ) {
34 $params['autocomplete'] = $params['autocomplete'] ? 'on' : 'off';
35 }
36
37 parent::__construct( $params );
38
39 if ( isset( $params['placeholder-message'] ) ) {
40 $this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->text();
41 } elseif ( isset( $params['placeholder'] ) ) {
42 $this->mPlaceholder = $params['placeholder'];
43 }
44
45 $this->mAccept = $params['accept'] ?? null;
46 $this->mMultiple = !empty( $params['multiple'] );
47 }
48
53 public function getInputHTML( $value ) {
54 $attribs = [
55 'id' => $this->mID,
56 'name' => $this->mName,
57 'dir' => $this->mDir,
58 ] + $this->getTooltipAndAccessKey();
59
60 if ( $this->mClass !== '' ) {
61 $attribs['class'] = $this->mClass;
62 }
63 if ( $this->mAccept ) {
64 $attribs['accept'] = implode( ',', $this->mAccept );
65 }
66 if ( $this->mMultiple ) {
67 $attribs['multiple'] = '';
68 }
69 // Note: Placeholders are not supported by native file inputs
70
71 $allowedParams = [
72 'title',
73 'tabindex',
74 'disabled',
75 'required',
76 'autofocus',
77 'readonly',
78 ];
79
80 $attribs += $this->getAttributes( $allowedParams );
81
82 return Html::input( $this->mName, $value, 'file', $attribs );
83 }
84
89 public function getInputOOUI( $value ) {
90 $attribs = $this->getTooltipAndAccessKeyOOUI();
91
92 if ( $this->mClass !== '' ) {
93 $attribs['classes'] = [ $this->mClass ];
94 }
95 if ( $this->mPlaceholder !== '' ) {
96 $attribs['placeholder'] = $this->mPlaceholder;
97 }
98 if ( $this->mAccept ) {
99 $attribs['accept'] = $this->mAccept;
100 }
101 if ( $this->mMultiple ) {
102 $attribs['multiple'] = true;
103 }
104
105 # @todo Enforce pattern, step, required, readonly on the server side as
106 # well
107 $allowedParams = [
108 'title',
109 'tabindex',
110 'disabled',
111 'required',
112 'autofocus',
113 'readonly',
114 ];
115
116 $attribs += OOUI\Element::configFromHtmlAttributes(
117 $this->getAttributes( $allowedParams )
118 );
119
120 return $this->getInputWidget( [
121 'id' => $this->mID,
122 'name' => $this->mName,
123 'dir' => $this->mDir,
124 ] + $attribs );
125 }
126
134 protected function getInputWidget( $params ) {
135 return new OOUI\SelectFileInputWidget( $params );
136 }
137
142 protected function shouldInfuseOOUI() {
143 return true;
144 }
145}
File <input> field.
getInputWidget( $params)
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
__construct( $params)
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
shouldInfuseOOUI()
Whether the field should be automatically infused.Note that all OOUI HTMLForm fields are infusable (y...
The parent class to generate form fields.
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
getTooltipAndAccessKeyOOUI()
Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
getAttributes(array $list)
Returns the given attributes from the parameters.
getTooltipAndAccessKey()
Returns the attributes required for the tooltip and accesskey, for Html::element() etc.