41 $missing = array_diff( self::$requiredParams, array_keys( $params ) );
45 parent::__construct( $params );
49 $rows = $this->mParams[
'rows'];
50 $columns = $this->mParams[
'columns'];
53 $p = parent::validate( $value, $alldata );
59 if ( !is_array( $value ) ) {
66 foreach ( $rows as $rowTag ) {
67 foreach ( $columns as $columnTag ) {
68 $validOptions[] = $columnTag .
'-' . $rowTag;
71 $validValues = array_intersect( $value, $validOptions );
72 if ( count( $validValues ) == count( $value ) ) {
75 return $this->
msg(
'htmlform-select-badoption' );
92 $rows = $this->mParams[
'rows'];
93 $columns = $this->mParams[
'columns'];
95 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
98 $headerContents = Html::rawElement(
'td', [],
"\u{00A0}" );
99 foreach ( $columns as $columnLabel => $columnTag ) {
100 $headerContents .= Html::rawElement(
'th', [], $columnLabel );
102 $thead = Html::rawElement(
'tr', [],
"\n$headerContents\n" );
103 $tableContents .= Html::rawElement(
'thead', [],
"\n$thead\n" );
105 $tooltipClass =
'mw-icon-question';
106 if ( isset( $this->mParams[
'tooltip-class'] ) ) {
107 $tooltipClass = $this->mParams[
'tooltip-class'];
111 foreach ( $rows as $rowLabel => $rowTag ) {
113 if ( isset( $this->mParams[
'tooltips'][$rowLabel] ) ) {
115 'class' =>
"mw-htmlform-tooltip $tooltipClass",
116 'title' => $this->mParams[
'tooltips'][$rowLabel],
117 'aria-label' => $this->mParams[
'tooltips'][$rowLabel]
119 $rowLabel .=
' ' . Html::element(
'span', $tooltipAttribs,
'' );
121 $rowContents = Html::rawElement(
'td', [], $rowLabel );
122 foreach ( $columns as $columnTag ) {
123 $thisTag =
"$columnTag-$rowTag";
126 'id' =>
"{$this->mID}-$thisTag",
129 $checked = in_array( $thisTag, (array)$value,
true );
132 $thisAttribs[
'disabled'] = 1;
133 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-off';
136 $thisAttribs[
'disabled'] = 1;
137 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-on';
142 $rowContents .= Html::rawElement(
148 $tableContents .= Html::rawElement(
'tr', [],
"\n$rowContents\n" );
152 $html .= Html::rawElement(
'table',
153 [
'class' =>
'mw-htmlform-matrix' ],
154 Html::rawElement(
'tbody', [],
"\n$tableContents\n" ) ) .
"\n";
160 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
164 'name' => $this->mName,
167 'rows' => $this->mParams[
'rows'],
168 'columns' => $this->mParams[
'columns'],
169 'tooltips' => $this->mParams[
'tooltips'] ?? [],
170 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
171 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
173 ] + OOUI\Element::configFromHtmlAttributes( $attribs )
178 $checkbox = Xml::check(
"{$this->mName}[]", $checked, $attribs );
179 if ( $this->mParent->getConfig()->get(
'UseMediaWikiUIEverywhere' ) ) {
180 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
182 Html::element(
'label', [
'for' => $attribs[
'id'] ] ) .
183 Html::closeElement(
'div' );
189 return isset( $this->mParams[
'force-options-off'] )
190 && in_array( $tag, $this->mParams[
'force-options-off'] );
194 return isset( $this->mParams[
'force-options-on'] )
195 && in_array( $tag, $this->mParams[
'force-options-on'] );
214 $cellAttributes = [
'colspan' => 2 ];
217 $hideAttributes = [];
218 if ( $this->mHideIf ) {
219 $hideAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
220 $hideClass =
'mw-htmlform-hide-if';
225 $field = Html::rawElement(
227 [
'class' =>
'mw-input' ] + $cellAttributes,
228 $inputHtml .
"\n$errors"
231 $html = Html::rawElement(
'tr',
232 [
'class' =>
"mw-htmlform-vertical-label $hideClass" ] + $hideAttributes,
234 $html .= Html::rawElement(
'tr',
235 [
'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $hideClass" ] +
239 return $html . $helptext;
251 return $request->getArray( $this->mName, [] );
259 return $this->mDefault ?? [];
266 foreach ( $columns as $column ) {
267 foreach ( $rows as $row ) {
269 $thisTag =
"$column-$row";
271 $res[$thisTag] =
false;
273 $res[$thisTag] =
true;
275 $res[$thisTag] = in_array( $thisTag, $data );
284 return [
'mediawiki.widgets.CheckMatrixWidget' ];
A checkbox matrix Operates similarly to HTMLMultiSelectField, but instead of using an array of option...
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
getOneCheckboxHTML( $checked, $attribs)
shouldInfuseOOUI()
Whether the field should be automatically infused.
getInputHTML( $value)
Build a table containing a matrix of checkbox options.
getTableRow( $value)
Get the complete table row for the input, including help text, labels, and whatever.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
loadDataFromRequest( $request)
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
filterDataForSubmit( $data)
Support for separating multi-option preferences into multiple preferences Due to lack of array suppor...