MediaWiki 1.40.4
HTMLTextAreaField.php
Go to the documentation of this file.
1<?php
2
3/*
4 * @stable to extend
5 */
6
9
11 protected const DEFAULT_COLS = 80;
12 protected const DEFAULT_ROWS = 25;
13
14 protected $mPlaceholder = '';
15 protected $mUseEditFont = false;
16
26 public function __construct( $params ) {
27 parent::__construct( $params );
28
29 if ( isset( $params['placeholder-message'] ) ) {
30 $this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->text();
31 } elseif ( isset( $params['placeholder'] ) ) {
32 $this->mPlaceholder = $params['placeholder'];
33 }
34
35 if ( isset( $params['useeditfont'] ) ) {
36 $this->mUseEditFont = $params['useeditfont'];
37 }
38 }
39
40 public function getCols() {
41 return $this->mParams['cols'] ?? static::DEFAULT_COLS;
42 }
43
44 public function getRows() {
45 return $this->mParams['rows'] ?? static::DEFAULT_ROWS;
46 }
47
48 public function getSpellCheck() {
49 $val = $this->mParams['spellcheck'] ?? null;
50 if ( is_bool( $val ) ) {
51 // "spellcheck" attribute literally requires "true" or "false" to work.
52 return $val ? 'true' : 'false';
53 }
54 return null;
55 }
56
61 public function getInputHTML( $value ) {
62 $classes = [];
63
64 $attribs = [
65 'id' => $this->mID,
66 'cols' => $this->getCols(),
67 'rows' => $this->getRows(),
68 'spellcheck' => $this->getSpellCheck(),
69 ] + $this->getTooltipAndAccessKey();
70
71 if ( $this->mClass !== '' ) {
72 array_push( $classes, $this->mClass );
73 }
74 if ( $this->mUseEditFont ) {
75 $userOptionsLookup = MediaWikiServices::getInstance()
76 ->getUserOptionsLookup();
77 // The following classes can be used here:
78 // * mw-editfont-monospace
79 // * mw-editfont-sans-serif
80 // * mw-editfont-serif
81 array_push(
82 $classes,
83 'mw-editfont-' . $userOptionsLookup->getOption(
84 $this->mParent->getUser(),
85 'editfont'
86 )
87 );
88 $this->mParent->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' );
89 }
90 if ( $this->mPlaceholder !== '' ) {
91 $attribs['placeholder'] = $this->mPlaceholder;
92 }
93 if ( $classes ) {
94 $attribs['class'] = $classes;
95 }
96
97 $allowedParams = [
98 'tabindex',
99 'disabled',
100 'readonly',
101 'required',
102 'autofocus'
103 ];
104
105 $attribs += $this->getAttributes( $allowedParams );
106 return Html::textarea( $this->mName, $value, $attribs );
107 }
108
113 public function getInputOOUI( $value ) {
114 $classes = [];
115
116 if ( isset( $this->mParams['cols'] ) ) {
117 throw new Exception( "OOUIHTMLForm does not support the 'cols' parameter for textareas" );
118 }
119
120 $attribs = $this->getTooltipAndAccessKeyOOUI();
121
122 if ( $this->mClass !== '' ) {
123 array_push( $classes, $this->mClass );
124 }
125 if ( $this->mUseEditFont ) {
126 $userOptionsLookup = MediaWikiServices::getInstance()
127 ->getUserOptionsLookup();
128 // The following classes can be used here:
129 // * mw-editfont-monospace
130 // * mw-editfont-sans-serif
131 // * mw-editfont-serif
132 array_push(
133 $classes,
134 'mw-editfont-' . $userOptionsLookup->getOption(
135 $this->mParent->getUser(),
136 'editfont'
137 )
138 );
139 $this->mParent->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' );
140 }
141 if ( $this->mPlaceholder !== '' ) {
142 $attribs['placeholder'] = $this->mPlaceholder;
143 }
144 if ( count( $classes ) ) {
145 $attribs['classes'] = $classes;
146 }
147
148 $allowedParams = [
149 'tabindex',
150 'disabled',
151 'readonly',
152 'required',
153 'autofocus',
154 ];
155
156 $attribs += OOUI\Element::configFromHtmlAttributes(
157 $this->getAttributes( $allowedParams )
158 );
159
160 return new OOUI\MultilineTextInputWidget( [
161 'id' => $this->mID,
162 'name' => $this->mName,
163 'value' => $value,
164 'rows' => $this->getRows(),
165 ] + $attribs );
166 }
167}
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.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
This class is a collection of static functions that serve two purposes:
Definition Html.php:55
Service locator for MediaWiki core services.