42 private static $requiredParams = [
55 $missing = array_diff( self::$requiredParams, array_keys(
$params ) );
63 $rows = $this->mParams[
'rows'];
64 $columns = $this->mParams[
'columns'];
67 $p = parent::validate( $value, $alldata );
73 if ( !is_array( $value ) ) {
80 foreach ( $rows as $rowTag ) {
81 foreach ( $columns as $columnTag ) {
82 $validOptions[] = $columnTag .
'-' . $rowTag;
85 $validValues = array_intersect( $value, $validOptions );
86 if ( count( $validValues ) == count( $value ) ) {
89 return $this->
msg(
'htmlform-select-badoption' );
106 $rows = $this->mParams[
'rows'];
107 $columns = $this->mParams[
'columns'];
109 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
112 $headerContents = Html::rawElement(
'td', [],
"\u{00A0}" );
113 foreach ( $columns as $columnLabel => $columnTag ) {
114 $headerContents .= Html::rawElement(
'th', [], $columnLabel );
116 $thead = Html::rawElement(
'tr', [],
"\n$headerContents\n" );
117 $tableContents .= Html::rawElement(
'thead', [],
"\n$thead\n" );
119 $tooltipClass =
'mw-icon-question';
120 if ( isset( $this->mParams[
'tooltip-class'] ) ) {
121 $tooltipClass = $this->mParams[
'tooltip-class'];
125 foreach ( $rows as $rowLabel => $rowTag ) {
127 if ( isset( $this->mParams[
'tooltips'][$rowLabel] ) ) {
129 'class' =>
"mw-htmlform-tooltip $tooltipClass",
130 'title' => $this->mParams[
'tooltips'][$rowLabel],
131 'aria-label' => $this->mParams[
'tooltips'][$rowLabel]
133 $rowLabel .=
' ' .
Html::element(
'span', $tooltipAttribs,
'' );
135 $rowContents = Html::rawElement(
'td', [], $rowLabel );
136 foreach ( $columns as $columnTag ) {
137 $thisTag =
"$columnTag-$rowTag";
140 'id' =>
"{$this->mID}-$thisTag",
143 $checked = in_array( $thisTag, (array)$value,
true );
146 $thisAttribs[
'disabled'] = 1;
147 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-off';
150 $thisAttribs[
'disabled'] = 1;
151 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-on';
156 $rowContents .= Html::rawElement(
162 $tableContents .= Html::rawElement(
'tr', [],
"\n$rowContents\n" );
166 $html .= Html::rawElement(
'table',
167 [
'class' =>
'mw-htmlform-matrix' ],
168 Html::rawElement(
'tbody', [],
"\n$tableContents\n" ) ) .
"\n";
174 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
176 return new \MediaWiki\Widget\CheckMatrixWidget(
178 'name' => $this->mName,
181 'rows' => $this->mParams[
'rows'],
182 'columns' => $this->mParams[
'columns'],
183 'tooltips' => $this->mParams[
'tooltips'] ?? [],
184 'tooltips-html' => $this->mParams[
'tooltips-html'] ?? [],
185 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
186 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
188 ] + \OOUI\Element::configFromHtmlAttributes( $attribs )
193 return Xml::check(
"{$this->mName}[]", $checked, $attribs );
197 return isset( $this->mParams[
'force-options-off'] )
198 && in_array( $tag, $this->mParams[
'force-options-off'] );
202 return isset( $this->mParams[
'force-options-on'] )
203 && in_array( $tag, $this->mParams[
'force-options-on'] );
222 $cellAttributes = [
'colspan' => 2 ];
225 $moreAttributes = [];
226 if ( $this->mCondState ) {
227 $moreAttributes[
'data-cond-state'] = FormatJson::encode( $this->mCondState );
228 $moreClass = implode(
' ', $this->mCondStateClass );
233 $field = Html::rawElement(
235 [
'class' =>
'mw-input' ] + $cellAttributes,
236 $inputHtml .
"\n$errors"
239 $html = Html::rawElement(
'tr',
240 [
'class' =>
"mw-htmlform-vertical-label $moreClass" ] + $moreAttributes,
242 $html .= Html::rawElement(
'tr',
243 [
'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $moreClass" ] +
247 return $html . $helptext;
259 return $request->getArray( $this->mName, [] );
267 return $this->mDefault ?? [];
274 foreach ( $columns as $column ) {
275 foreach ( $rows as $row ) {
277 $thisTag =
"$column-$row";
279 $res[$thisTag] =
false;
281 $res[$thisTag] =
true;
283 $res[$thisTag] = in_array( $thisTag, $data );
292 return [
'mediawiki.widgets.CheckMatrixWidget' ];
301class_alias( HTMLCheckMatrix::class,
'HTMLCheckMatrix' );
array $params
The job parameters.
Module of static functions for generating XML.