41 private const REQUIRED_PARAMS = [
54 $missing = array_diff( self::REQUIRED_PARAMS, array_keys(
$params ) );
60 $params[
'vertical-label'] =
true;
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";
176 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
178 return new \MediaWiki\Widget\CheckMatrixWidget(
180 'name' => $this->mName,
183 'rows' => $this->mParams[
'rows'],
184 'columns' => $this->mParams[
'columns'],
185 'tooltips' => $this->mParams[
'tooltips'] ?? [],
186 'tooltips-html' => $this->mParams[
'tooltips-html'] ?? [],
187 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
188 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
190 ] + \OOUI\Element::configFromHtmlAttributes( $attribs )
195 return Xml::check(
"{$this->mName}[]", $checked, $attribs );
199 return isset( $this->mParams[
'force-options-off'] )
200 && in_array( $tag, $this->mParams[
'force-options-off'] );
204 return isset( $this->mParams[
'force-options-on'] )
205 && in_array( $tag, $this->mParams[
'force-options-on'] );
217 return $request->getArray( $this->mName, [] );
225 return $this->mDefault ?? [];
232 foreach ( $columns as $column ) {
233 foreach ( $rows as $row ) {
235 $thisTag =
"$column-$row";
237 $res[$thisTag] =
false;
239 $res[$thisTag] =
true;
241 $res[$thisTag] = in_array( $thisTag, $data );
250 return [
'mediawiki.widgets.CheckMatrixWidget' ];
259class_alias( HTMLCheckMatrix::class,
'HTMLCheckMatrix' );
array $params
The job parameters.