40 private const REQUIRED_PARAMS = [
53 $missing = array_diff( self::REQUIRED_PARAMS, array_keys( $params ) );
59 $params[
'vertical-label'] =
true;
60 parent::__construct( $params );
64 $rows = $this->mParams[
'rows'];
65 $columns = $this->mParams[
'columns'];
68 $p = parent::validate( $value, $alldata );
74 if ( !is_array( $value ) ) {
81 foreach ( $rows as $rowTag ) {
82 foreach ( $columns as $columnTag ) {
83 $validOptions[] = $columnTag .
'-' . $rowTag;
86 $validValues = array_intersect( $value, $validOptions );
87 if ( count( $validValues ) == count( $value ) ) {
90 return $this->
msg(
'htmlform-select-badoption' );
107 $rows = $this->mParams[
'rows'];
108 $columns = $this->mParams[
'columns'];
110 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
113 $headerContents = Html::rawElement(
'td', [],
"\u{00A0}" );
114 foreach ( $columns as $columnLabel => $columnTag ) {
115 $headerContents .= Html::rawElement(
'th', [], $columnLabel );
117 $thead = Html::rawElement(
'tr', [],
"\n$headerContents\n" );
118 $tableContents .= Html::rawElement(
'thead', [],
"\n$thead\n" );
120 $tooltipClass =
'mw-icon-question';
121 if ( isset( $this->mParams[
'tooltip-class'] ) ) {
122 $tooltipClass = $this->mParams[
'tooltip-class'];
126 foreach ( $rows as $rowLabel => $rowTag ) {
128 if ( isset( $this->mParams[
'tooltips'][$rowLabel] ) ) {
130 'class' =>
"mw-htmlform-tooltip $tooltipClass",
131 'title' => $this->mParams[
'tooltips'][$rowLabel],
132 'aria-label' => $this->mParams[
'tooltips'][$rowLabel]
134 $rowLabel .=
' ' .
Html::element(
'span', $tooltipAttribs,
'' );
136 $rowContents = Html::rawElement(
'td', [], $rowLabel );
137 foreach ( $columns as $columnTag ) {
138 $thisTag =
"$columnTag-$rowTag";
141 'id' =>
"{$this->mID}-$thisTag",
144 $checked = in_array( $thisTag, (array)$value,
true );
147 $thisAttribs[
'disabled'] = 1;
148 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-off';
151 $thisAttribs[
'disabled'] = 1;
152 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-on';
157 $rowContents .= Html::rawElement(
163 $tableContents .= Html::rawElement(
'tr', [],
"\n$rowContents\n" );
167 $html .= Html::rawElement(
'table',
168 [
'class' =>
'mw-htmlform-matrix' ],
169 Html::rawElement(
'tbody', [],
"\n$tableContents\n" ) ) .
"\n";
175 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
177 return new \MediaWiki\Widget\CheckMatrixWidget(
179 'name' => $this->mName,
182 'rows' => $this->mParams[
'rows'],
183 'columns' => $this->mParams[
'columns'],
184 'tooltips' => $this->mParams[
'tooltips'] ?? [],
185 'tooltips-html' => $this->mParams[
'tooltips-html'] ?? [],
186 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
187 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
189 ] + \OOUI\Element::configFromHtmlAttributes( $attribs )
194 return Html::check(
"{$this->mName}[]", $checked, $attribs );
198 return isset( $this->mParams[
'force-options-off'] )
199 && in_array( $tag, $this->mParams[
'force-options-off'] );
203 return isset( $this->mParams[
'force-options-on'] )
204 && in_array( $tag, $this->mParams[
'force-options-on'] );
216 return $request->getArray( $this->mName, [] );
224 return $this->mDefault ?? [];
231 foreach ( $columns as $column ) {
232 foreach ( $rows as $row ) {
234 $thisTag =
"$column-$row";
236 $res[$thisTag] =
false;
238 $res[$thisTag] =
true;
240 $res[$thisTag] = in_array( $thisTag, $data );
249 return [
'mediawiki.widgets.CheckMatrixWidget' ];
258class_alias( HTMLCheckMatrix::class,
'HTMLCheckMatrix' );