40 $missing = array_diff( self::$requiredParams, array_keys( $params ) );
44 parent::__construct( $params );
48 $rows = $this->mParams[
'rows'];
49 $columns = $this->mParams[
'columns'];
52 $p = parent::validate( $value, $alldata );
58 if ( !is_array( $value ) ) {
65 foreach ( $rows as $rowTag ) {
66 foreach ( $columns as $columnTag ) {
67 $validOptions[] = $columnTag .
'-' . $rowTag;
70 $validValues = array_intersect( $value, $validOptions );
71 if ( count( $validValues ) == count( $value ) ) {
74 return $this->
msg(
'htmlform-select-badoption' );
91 $rows = $this->mParams[
'rows'];
92 $columns = $this->mParams[
'columns'];
94 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
97 $headerContents = Html::rawElement(
'td', [],
"\u{00A0}" );
98 foreach ( $columns as $columnLabel => $columnTag ) {
99 $headerContents .= Html::rawElement(
'th', [], $columnLabel );
101 $thead = Html::rawElement(
'tr', [],
"\n$headerContents\n" );
102 $tableContents .= Html::rawElement(
'thead', [],
"\n$thead\n" );
104 $tooltipClass =
'mw-icon-question';
105 if ( isset( $this->mParams[
'tooltip-class'] ) ) {
106 $tooltipClass = $this->mParams[
'tooltip-class'];
110 foreach ( $rows as $rowLabel => $rowTag ) {
112 if ( isset( $this->mParams[
'tooltips'][$rowLabel] ) ) {
114 'class' =>
"mw-htmlform-tooltip $tooltipClass",
115 'title' => $this->mParams[
'tooltips'][$rowLabel],
116 'aria-label' => $this->mParams[
'tooltips'][$rowLabel]
118 $rowLabel .=
' ' . Html::element(
'span', $tooltipAttribs,
'' );
120 $rowContents = Html::rawElement(
'td', [], $rowLabel );
121 foreach ( $columns as $columnTag ) {
122 $thisTag =
"$columnTag-$rowTag";
125 'id' =>
"{$this->mID}-$thisTag",
128 $checked = in_array( $thisTag, (array)$value,
true );
131 $thisAttribs[
'disabled'] = 1;
132 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-off';
135 $thisAttribs[
'disabled'] = 1;
136 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-on';
141 $rowContents .= Html::rawElement(
147 $tableContents .= Html::rawElement(
'tr', [],
"\n$rowContents\n" );
151 $html .= Html::rawElement(
'table',
152 [
'class' =>
'mw-htmlform-matrix' ],
153 Html::rawElement(
'tbody', [],
"\n$tableContents\n" ) ) .
"\n";
159 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
163 'name' => $this->mName,
166 'rows' => $this->mParams[
'rows'],
167 'columns' => $this->mParams[
'columns'],
168 'tooltips' => $this->mParams[
'tooltips'] ?? [],
169 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
170 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
172 ] + OOUI\Element::configFromHtmlAttributes( $attribs )
177 $checkbox = Xml::check(
"{$this->mName}[]", $checked, $attribs );
178 if ( $this->mParent->getConfig()->get(
'UseMediaWikiUIEverywhere' ) ) {
179 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
181 Html::element(
'label', [
'for' => $attribs[
'id'] ] ) .
182 Html::closeElement(
'div' );
188 return isset( $this->mParams[
'force-options-off'] )
189 && in_array( $tag, $this->mParams[
'force-options-off'] );
193 return isset( $this->mParams[
'force-options-on'] )
194 && in_array( $tag, $this->mParams[
'force-options-on'] );
213 $cellAttributes = [
'colspan' => 2 ];
216 $hideAttributes = [];
217 if ( $this->mHideIf ) {
218 $hideAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
219 $hideClass =
'mw-htmlform-hide-if';
224 $field = Html::rawElement(
226 [
'class' =>
'mw-input' ] + $cellAttributes,
227 $inputHtml .
"\n$errors"
230 $html = Html::rawElement(
'tr',
231 [
'class' =>
"mw-htmlform-vertical-label $hideClass" ] + $hideAttributes,
233 $html .= Html::rawElement(
'tr',
234 [
'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $hideClass" ] +
238 return $html . $helptext;
250 return $request->getArray( $this->mName, [] );
258 return $this->mDefault ?? [];
265 foreach ( $columns as $column ) {
266 foreach ( $rows as $row ) {
268 $thisTag =
"$column-$row";
270 $res[$thisTag] =
false;
272 $res[$thisTag] =
true;
274 $res[$thisTag] = in_array( $thisTag, $data );
283 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.
getDefault()
Stable to override.
__construct( $params)
Initialise the object.
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...