30 private static $requiredParams = [
43 $missing = array_diff( self::$requiredParams, array_keys( $params ) );
47 parent::__construct( $params );
51 $rows = $this->mParams[
'rows'];
52 $columns = $this->mParams[
'columns'];
55 $p = parent::validate( $value, $alldata );
61 if ( !is_array( $value ) ) {
68 foreach ( $rows as $rowTag ) {
69 foreach ( $columns as $columnTag ) {
70 $validOptions[] = $columnTag .
'-' . $rowTag;
73 $validValues = array_intersect( $value, $validOptions );
74 if ( count( $validValues ) == count( $value ) ) {
77 return $this->
msg(
'htmlform-select-badoption' );
94 $rows = $this->mParams[
'rows'];
95 $columns = $this->mParams[
'columns'];
97 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
100 $headerContents = Html::rawElement(
'td', [],
"\u{00A0}" );
101 foreach ( $columns as $columnLabel => $columnTag ) {
102 $headerContents .= Html::rawElement(
'th', [], $columnLabel );
104 $thead = Html::rawElement(
'tr', [],
"\n$headerContents\n" );
105 $tableContents .= Html::rawElement(
'thead', [],
"\n$thead\n" );
107 $tooltipClass =
'mw-icon-question';
108 if ( isset( $this->mParams[
'tooltip-class'] ) ) {
109 $tooltipClass = $this->mParams[
'tooltip-class'];
113 foreach ( $rows as $rowLabel => $rowTag ) {
115 if ( isset( $this->mParams[
'tooltips'][$rowLabel] ) ) {
117 'class' =>
"mw-htmlform-tooltip $tooltipClass",
118 'title' => $this->mParams[
'tooltips'][$rowLabel],
119 'aria-label' => $this->mParams[
'tooltips'][$rowLabel]
121 $rowLabel .=
' ' . Html::element(
'span', $tooltipAttribs,
'' );
123 $rowContents = Html::rawElement(
'td', [], $rowLabel );
124 foreach ( $columns as $columnTag ) {
125 $thisTag =
"$columnTag-$rowTag";
128 'id' =>
"{$this->mID}-$thisTag",
131 $checked = in_array( $thisTag, (array)$value,
true );
134 $thisAttribs[
'disabled'] = 1;
135 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-off';
138 $thisAttribs[
'disabled'] = 1;
139 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-on';
144 $rowContents .= Html::rawElement(
150 $tableContents .= Html::rawElement(
'tr', [],
"\n$rowContents\n" );
154 $html .= Html::rawElement(
'table',
155 [
'class' =>
'mw-htmlform-matrix' ],
156 Html::rawElement(
'tbody', [],
"\n$tableContents\n" ) ) .
"\n";
162 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
166 'name' => $this->mName,
169 'rows' => $this->mParams[
'rows'],
170 'columns' => $this->mParams[
'columns'],
171 'tooltips' => $this->mParams[
'tooltips'] ?? [],
172 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
173 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
175 ] + OOUI\Element::configFromHtmlAttributes( $attribs )
180 $checkbox = Xml::check(
"{$this->mName}[]", $checked, $attribs );
181 if ( $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ) ) {
182 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
184 Html::element(
'label', [
'for' => $attribs[
'id'] ] ) .
185 Html::closeElement(
'div' );
191 return isset( $this->mParams[
'force-options-off'] )
192 && in_array( $tag, $this->mParams[
'force-options-off'] );
196 return isset( $this->mParams[
'force-options-on'] )
197 && in_array( $tag, $this->mParams[
'force-options-on'] );
216 $cellAttributes = [
'colspan' => 2 ];
219 $moreAttributes = [];
220 if ( $this->mCondState ) {
221 $moreAttributes[
'data-cond-state'] = FormatJson::encode( $this->mCondState );
222 $moreClass = implode(
' ', $this->mCondStateClass );
227 $field = Html::rawElement(
229 [
'class' =>
'mw-input' ] + $cellAttributes,
230 $inputHtml .
"\n$errors"
233 $html = Html::rawElement(
'tr',
234 [
'class' =>
"mw-htmlform-vertical-label $moreClass" ] + $moreAttributes,
236 $html .= Html::rawElement(
'tr',
237 [
'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $moreClass" ] +
241 return $html . $helptext;
253 return $request->getArray( $this->mName, [] );
261 return $this->mDefault ?? [];
268 foreach ( $columns as $column ) {
269 foreach ( $rows as $row ) {
271 $thisTag =
"$column-$row";
273 $res[$thisTag] =
false;
275 $res[$thisTag] =
true;
277 $res[$thisTag] = in_array( $thisTag, $data );
286 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.