31 private static $requiredParams = [
44 $missing = array_diff( self::$requiredParams, array_keys( $params ) );
48 parent::__construct( $params );
52 $rows = $this->mParams[
'rows'];
53 $columns = $this->mParams[
'columns'];
56 $p = parent::validate( $value, $alldata );
62 if ( !is_array( $value ) ) {
69 foreach ( $rows as $rowTag ) {
70 foreach ( $columns as $columnTag ) {
71 $validOptions[] = $columnTag .
'-' . $rowTag;
74 $validValues = array_intersect( $value, $validOptions );
75 if ( count( $validValues ) == count( $value ) ) {
78 return $this->
msg(
'htmlform-select-badoption' );
95 $rows = $this->mParams[
'rows'];
96 $columns = $this->mParams[
'columns'];
98 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
101 $headerContents = Html::rawElement(
'td', [],
"\u{00A0}" );
102 foreach ( $columns as $columnLabel => $columnTag ) {
103 $headerContents .= Html::rawElement(
'th', [], $columnLabel );
105 $thead = Html::rawElement(
'tr', [],
"\n$headerContents\n" );
106 $tableContents .= Html::rawElement(
'thead', [],
"\n$thead\n" );
108 $tooltipClass =
'mw-icon-question';
109 if ( isset( $this->mParams[
'tooltip-class'] ) ) {
110 $tooltipClass = $this->mParams[
'tooltip-class'];
114 foreach ( $rows as $rowLabel => $rowTag ) {
116 if ( isset( $this->mParams[
'tooltips'][$rowLabel] ) ) {
118 'class' =>
"mw-htmlform-tooltip $tooltipClass",
119 'title' => $this->mParams[
'tooltips'][$rowLabel],
120 'aria-label' => $this->mParams[
'tooltips'][$rowLabel]
122 $rowLabel .=
' ' . Html::element(
'span', $tooltipAttribs,
'' );
124 $rowContents = Html::rawElement(
'td', [], $rowLabel );
125 foreach ( $columns as $columnTag ) {
126 $thisTag =
"$columnTag-$rowTag";
129 'id' =>
"{$this->mID}-$thisTag",
132 $checked = in_array( $thisTag, (array)$value,
true );
135 $thisAttribs[
'disabled'] = 1;
136 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-off';
139 $thisAttribs[
'disabled'] = 1;
140 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-on';
145 $rowContents .= Html::rawElement(
151 $tableContents .= Html::rawElement(
'tr', [],
"\n$rowContents\n" );
155 $html .= Html::rawElement(
'table',
156 [
'class' =>
'mw-htmlform-matrix' ],
157 Html::rawElement(
'tbody', [],
"\n$tableContents\n" ) ) .
"\n";
163 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
167 'name' => $this->mName,
170 'rows' => $this->mParams[
'rows'],
171 'columns' => $this->mParams[
'columns'],
172 'tooltips' => $this->mParams[
'tooltips'] ?? [],
173 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
174 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
176 ] + OOUI\Element::configFromHtmlAttributes( $attribs )
181 $checkbox = Xml::check(
"{$this->mName}[]", $checked, $attribs );
182 if ( $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ) ) {
183 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
185 Html::element(
'label', [
'for' => $attribs[
'id'] ] ) .
186 Html::closeElement(
'div' );
192 return isset( $this->mParams[
'force-options-off'] )
193 && in_array( $tag, $this->mParams[
'force-options-off'] );
197 return isset( $this->mParams[
'force-options-on'] )
198 && in_array( $tag, $this->mParams[
'force-options-on'] );
217 $cellAttributes = [
'colspan' => 2 ];
220 $moreAttributes = [];
221 if ( $this->mCondState ) {
222 $moreAttributes[
'data-cond-state'] = FormatJson::encode( $this->mCondState );
223 $moreClass = implode(
' ', $this->mCondStateClass );
228 $field = Html::rawElement(
230 [
'class' =>
'mw-input' ] + $cellAttributes,
231 $inputHtml .
"\n$errors"
234 $html = Html::rawElement(
'tr',
235 [
'class' =>
"mw-htmlform-vertical-label $moreClass" ] + $moreAttributes,
237 $html .= Html::rawElement(
'tr',
238 [
'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $moreClass" ] +
242 return $html . $helptext;
254 return $request->getArray( $this->mName, [] );
262 return $this->mDefault ?? [];
269 foreach ( $columns as $column ) {
270 foreach ( $rows as $row ) {
272 $thisTag =
"$column-$row";
274 $res[$thisTag] =
false;
276 $res[$thisTag] =
true;
278 $res[$thisTag] = in_array( $thisTag, $data );
287 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.