40 private const REQUIRED_PARAMS = [
53 $missing = array_diff( self::REQUIRED_PARAMS, array_keys( $params ) );
59 $params[
'vertical-label'] =
true;
60 parent::__construct( $params );
65 $rows = $this->mParams[
'rows'];
66 $columns = $this->mParams[
'columns'];
69 $p = parent::validate( $value, $alldata );
75 if ( !is_array( $value ) ) {
82 foreach ( $rows as $rowTag ) {
83 foreach ( $columns as $columnTag ) {
84 $validOptions[] = $columnTag .
'-' . $rowTag;
87 $validValues = array_intersect( $value, $validOptions );
88 if ( count( $validValues ) == count( $value ) ) {
91 return $this->
msg(
'htmlform-select-badoption' );
108 $rows = $this->mParams[
'rows'];
109 $columns = $this->mParams[
'columns'];
111 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
114 $headerContents = Html::rawElement(
'td', [],
"\u{00A0}" );
115 foreach ( $columns as $columnLabel => $columnTag ) {
116 $headerContents .= Html::rawElement(
'th', [], $columnLabel );
118 $thead = Html::rawElement(
'tr', [],
"\n$headerContents\n" );
119 $tableContents .= Html::rawElement(
'thead', [],
"\n$thead\n" );
121 $tooltipClass =
'mw-icon-question';
122 if ( isset( $this->mParams[
'tooltip-class'] ) ) {
123 $tooltipClass = $this->mParams[
'tooltip-class'];
127 foreach ( $rows as $rowLabel => $rowTag ) {
129 if ( isset( $this->mParams[
'tooltips'][$rowLabel] ) ) {
131 'class' =>
"mw-htmlform-tooltip $tooltipClass",
132 'title' => $this->mParams[
'tooltips'][$rowLabel],
133 'aria-label' => $this->mParams[
'tooltips'][$rowLabel]
135 $rowLabel .=
' ' .
Html::element(
'span', $tooltipAttribs,
'' );
137 $rowContents = Html::rawElement(
'td', [], $rowLabel );
138 foreach ( $columns as $columnTag ) {
139 $thisTag =
"$columnTag-$rowTag";
142 'id' =>
"{$this->mID}-$thisTag",
145 $checked = in_array( $thisTag, (array)$value,
true );
148 $thisAttribs[
'disabled'] = 1;
149 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-off';
152 $thisAttribs[
'disabled'] = 1;
153 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-on';
158 $rowContents .= Html::rawElement(
164 $tableContents .= Html::rawElement(
'tr', [],
"\n$rowContents\n" );
168 $html .= Html::rawElement(
'table',
169 [
'class' =>
'mw-htmlform-matrix' ],
170 Html::rawElement(
'tbody', [],
"\n$tableContents\n" ) ) .
"\n";
177 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
179 return new \MediaWiki\Widget\CheckMatrixWidget(
181 'name' => $this->mName,
184 'rows' => $this->mParams[
'rows'],
185 'columns' => $this->mParams[
'columns'],
186 'tooltips' => $this->mParams[
'tooltips'] ?? [],
187 'tooltips-html' => $this->mParams[
'tooltips-html'] ?? [],
188 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
189 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
191 ] + \OOUI\Element::configFromHtmlAttributes( $attribs )
201 return Html::check(
"{$this->mName}[]", $checked, $attribs );
209 return isset( $this->mParams[
'force-options-off'] )
210 && in_array( $tag, $this->mParams[
'force-options-off'] );
218 return isset( $this->mParams[
'force-options-on'] )
219 && in_array( $tag, $this->mParams[
'force-options-on'] );
231 return $request->getArray( $this->mName, [] );
240 return $this->mDefault ?? [];
248 foreach ( $columns as $column ) {
249 foreach ( $rows as $row ) {
251 $thisTag =
"$column-$row";
253 $res[$thisTag] =
false;
255 $res[$thisTag] =
true;
257 $res[$thisTag] = in_array( $thisTag, $data );
267 return [
'mediawiki.widgets.CheckMatrixWidget' ];
277class_alias( HTMLCheckMatrix::class,
'HTMLCheckMatrix' );