32 private static $requiredParams = [
45 $missing = array_diff( self::$requiredParams, array_keys( $params ) );
49 parent::__construct( $params );
53 $rows = $this->mParams[
'rows'];
54 $columns = $this->mParams[
'columns'];
57 $p = parent::validate( $value, $alldata );
63 if ( !is_array( $value ) ) {
70 foreach ( $rows as $rowTag ) {
71 foreach ( $columns as $columnTag ) {
72 $validOptions[] = $columnTag .
'-' . $rowTag;
75 $validValues = array_intersect( $value, $validOptions );
76 if ( count( $validValues ) == count( $value ) ) {
79 return $this->
msg(
'htmlform-select-badoption' );
96 $rows = $this->mParams[
'rows'];
97 $columns = $this->mParams[
'columns'];
99 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
102 $headerContents = Html::rawElement(
'td', [],
"\u{00A0}" );
103 foreach ( $columns as $columnLabel => $columnTag ) {
104 $headerContents .= Html::rawElement(
'th', [], $columnLabel );
106 $thead = Html::rawElement(
'tr', [],
"\n$headerContents\n" );
107 $tableContents .= Html::rawElement(
'thead', [],
"\n$thead\n" );
109 $tooltipClass =
'mw-icon-question';
110 if ( isset( $this->mParams[
'tooltip-class'] ) ) {
111 $tooltipClass = $this->mParams[
'tooltip-class'];
115 foreach ( $rows as $rowLabel => $rowTag ) {
117 if ( isset( $this->mParams[
'tooltips'][$rowLabel] ) ) {
119 'class' =>
"mw-htmlform-tooltip $tooltipClass",
120 'title' => $this->mParams[
'tooltips'][$rowLabel],
121 'aria-label' => $this->mParams[
'tooltips'][$rowLabel]
123 $rowLabel .=
' ' . Html::element(
'span', $tooltipAttribs,
'' );
125 $rowContents = Html::rawElement(
'td', [], $rowLabel );
126 foreach ( $columns as $columnTag ) {
127 $thisTag =
"$columnTag-$rowTag";
130 'id' =>
"{$this->mID}-$thisTag",
133 $checked = in_array( $thisTag, (array)$value,
true );
136 $thisAttribs[
'disabled'] = 1;
137 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-off';
140 $thisAttribs[
'disabled'] = 1;
141 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-on';
146 $rowContents .= Html::rawElement(
152 $tableContents .= Html::rawElement(
'tr', [],
"\n$rowContents\n" );
156 $html .= Html::rawElement(
'table',
157 [
'class' =>
'mw-htmlform-matrix' ],
158 Html::rawElement(
'tbody', [],
"\n$tableContents\n" ) ) .
"\n";
164 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
168 'name' => $this->mName,
171 'rows' => $this->mParams[
'rows'],
172 'columns' => $this->mParams[
'columns'],
173 'tooltips' => $this->mParams[
'tooltips'] ?? [],
174 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
175 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
177 ] + OOUI\Element::configFromHtmlAttributes( $attribs )
182 $checkbox = Xml::check(
"{$this->mName}[]", $checked, $attribs );
183 if ( $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ) ) {
184 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
186 Html::element(
'label', [
'for' => $attribs[
'id'] ] ) .
187 Html::closeElement(
'div' );
193 return isset( $this->mParams[
'force-options-off'] )
194 && in_array( $tag, $this->mParams[
'force-options-off'] );
198 return isset( $this->mParams[
'force-options-on'] )
199 && in_array( $tag, $this->mParams[
'force-options-on'] );
218 $cellAttributes = [
'colspan' => 2 ];
221 $moreAttributes = [];
222 if ( $this->mCondState ) {
223 $moreAttributes[
'data-cond-state'] = FormatJson::encode( $this->mCondState );
224 $moreClass = implode(
' ', $this->mCondStateClass );
229 $field = Html::rawElement(
231 [
'class' =>
'mw-input' ] + $cellAttributes,
232 $inputHtml .
"\n$errors"
235 $html = Html::rawElement(
'tr',
236 [
'class' =>
"mw-htmlform-vertical-label $moreClass" ] + $moreAttributes,
238 $html .= Html::rawElement(
'tr',
239 [
'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $moreClass" ] +
243 return $html . $helptext;
255 return $request->getArray( $this->mName, [] );
263 return $this->mDefault ?? [];
270 foreach ( $columns as $column ) {
271 foreach ( $rows as $row ) {
273 $thisTag =
"$column-$row";
275 $res[$thisTag] =
false;
277 $res[$thisTag] =
true;
279 $res[$thisTag] = in_array( $thisTag, $data );
288 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...
A class containing constants representing the names of configuration variables.