"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "includes/htmlform/fields/HTMLCheckMatrix.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

HTMLCheckMatrix.php  (mediawiki-1.31.1):HTMLCheckMatrix.php  (mediawiki-1.32.0)
skipping to change at line 12 skipping to change at line 12
/** /**
* A checkbox matrix * A checkbox matrix
* Operates similarly to HTMLMultiSelectField, but instead of using an array of * Operates similarly to HTMLMultiSelectField, but instead of using an array of
* options, uses an array of rows and an array of columns to dynamically * options, uses an array of rows and an array of columns to dynamically
* construct a matrix of options. The tags used to identify a particular cell * construct a matrix of options. The tags used to identify a particular cell
* are of the form "columnName-rowName" * are of the form "columnName-rowName"
* *
* Options: * Options:
* - columns * - columns
* - Required list of columns in the matrix. * - Required associative array mapping column labels (as HTML) to their tag s.
* - rows * - rows
* - Required list of rows in the matrix. * - Required associative array mapping row labels (as HTML) to their tags.
* - force-options-on * - force-options-on
* - Accepts array of column-row tags to be displayed as enabled but unavail able to change * - Array of column-row tags to be displayed as enabled but unavailable to change.
* - force-options-off * - force-options-off
* - Accepts array of column-row tags to be displayed as disabled but unavai lable to change. * - Array of column-row tags to be displayed as disabled but unavailable to change.
* - tooltips * - tooltips
* - Optional array mapping row label to tooltip content * - Optional associative array mapping row labels to tooltips (as text, wil l be escaped).
* - tooltip-class * - tooltip-class
* - Optional CSS class used on tooltip container span. Defaults to mw-icon- question. * - Optional CSS class used on tooltip container span. Defaults to mw-icon- question.
* Not used by OOUI form fields.
*/ */
class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable {
static private $requiredParams = [ static private $requiredParams = [
// Required by underlying HTMLFormField // Required by underlying HTMLFormField
'fieldname', 'fieldname',
// Required by HTMLCheckMatrix // Required by HTMLCheckMatrix
'rows', 'rows',
'columns' 'columns'
]; ];
skipping to change at line 91 skipping to change at line 92
*/ */
public function getInputHTML( $value ) { public function getInputHTML( $value ) {
$html = ''; $html = '';
$tableContents = ''; $tableContents = '';
$rows = $this->mParams['rows']; $rows = $this->mParams['rows'];
$columns = $this->mParams['columns']; $columns = $this->mParams['columns'];
$attribs = $this->getAttributes( [ 'disabled', 'tabindex' ] ); $attribs = $this->getAttributes( [ 'disabled', 'tabindex' ] );
// Build the column headers // Build the column headers
$headerContents = Html::rawElement( 'td', [], ' ' ); $headerContents = Html::rawElement( 'td', [], "\u{00A0}" );
foreach ( $columns as $columnLabel => $columnTag ) { foreach ( $columns as $columnLabel => $columnTag ) {
$headerContents .= Html::rawElement( 'td', [], $columnLab el ); $headerContents .= Html::rawElement( 'td', [], $columnLab el );
} }
$tableContents .= Html::rawElement( 'tr', [], "\n$headerContents\ n" ); $tableContents .= Html::rawElement( 'tr', [], "\n$headerContents\ n" );
$tooltipClass = 'mw-icon-question'; $tooltipClass = 'mw-icon-question';
if ( isset( $this->mParams['tooltip-class'] ) ) { if ( isset( $this->mParams['tooltip-class'] ) ) {
$tooltipClass = $this->mParams['tooltip-class']; $tooltipClass = $this->mParams['tooltip-class'];
} }
skipping to change at line 132 skipping to change at line 133
if ( $this->isTagForcedOff( $thisTag ) ) { if ( $this->isTagForcedOff( $thisTag ) ) {
$checked = false; $checked = false;
$thisAttribs['disabled'] = 1; $thisAttribs['disabled'] = 1;
$thisAttribs['class'] = 'checkmatrix-forc ed checkmatrix-forced-off'; $thisAttribs['class'] = 'checkmatrix-forc ed checkmatrix-forced-off';
} elseif ( $this->isTagForcedOn( $thisTag ) ) { } elseif ( $this->isTagForcedOn( $thisTag ) ) {
$checked = true; $checked = true;
$thisAttribs['disabled'] = 1; $thisAttribs['disabled'] = 1;
$thisAttribs['class'] = 'checkmatrix-forc ed checkmatrix-forced-on'; $thisAttribs['class'] = 'checkmatrix-forc ed checkmatrix-forced-on';
} }
$checkbox = $this->getOneCheckbox( $checked, $att ribs + $thisAttribs ); $checkbox = $this->getOneCheckboxHTML( $checked, $attribs + $thisAttribs );
$rowContents .= Html::rawElement( $rowContents .= Html::rawElement(
'td', 'td',
[], [],
$checkbox $checkbox
); );
} }
$tableContents .= Html::rawElement( 'tr', [], "\n$rowCont ents\n" ); $tableContents .= Html::rawElement( 'tr', [], "\n$rowCont ents\n" );
} }
// Put it all in a table // Put it all in a table
$html .= Html::rawElement( 'table', $html .= Html::rawElement( 'table',
[ 'class' => 'mw-htmlform-matrix' ], [ 'class' => 'mw-htmlform-matrix' ],
Html::rawElement( 'tbody', [], "\n$tableContents\ n" ) ) . "\n"; Html::rawElement( 'tbody', [], "\n$tableContents\ n" ) ) . "\n";
return $html; return $html;
} }
protected function getOneCheckbox( $checked, $attribs ) { public function getInputOOUI( $value ) {
if ( $this->mParent instanceof OOUIHTMLForm ) { $attribs = $this->getAttributes( [ 'disabled', 'tabindex' ] );
return new OOUI\CheckboxInputWidget( [
'name' => "{$this->mName}[]", return new MediaWiki\Widget\CheckMatrixWidget(
'selected' => $checked, [
] + OOUI\Element::configFromHtmlAttributes( 'name' => $this->mName,
$attribs 'infusable' => true,
) ); 'id' => $this->mID,
} else { 'rows' => $this->mParams['rows'],
$checkbox = Xml::check( "{$this->mName}[]", $checked, $at 'columns' => $this->mParams['columns'],
tribs ); 'tooltips' => $this->mParams['tooltips'] ?? [],
if ( $this->mParent->getConfig()->get( 'UseMediaWikiUIEve 'forcedOff' => $this->mParams['force-options-off'
rywhere' ) ) { ] ?? [],
$checkbox = Html::openElement( 'div', [ 'class' = 'forcedOn' => $this->mParams['force-options-on']
> 'mw-ui-checkbox' ] ) . ?? [],
$checkbox . 'values' => $value,
Html::element( 'label', [ 'for' => $attri ] + OOUI\Element::configFromHtmlAttributes( $attribs )
bs['id'] ] ) . );
Html::closeElement( 'div' ); }
}
return $checkbox; protected function getOneCheckboxHTML( $checked, $attribs ) {
$checkbox = Xml::check( "{$this->mName}[]", $checked, $attribs );
if ( $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere'
) ) {
$checkbox = Html::openElement( 'div', [ 'class' => 'mw-ui
-checkbox' ] ) .
$checkbox .
Html::element( 'label', [ 'for' => $attribs['id']
] ) .
Html::closeElement( 'div' );
} }
return $checkbox;
} }
protected function isTagForcedOff( $tag ) { protected function isTagForcedOff( $tag ) {
return isset( $this->mParams['force-options-off'] ) return isset( $this->mParams['force-options-off'] )
&& in_array( $tag, $this->mParams['force-options-off'] ); && in_array( $tag, $this->mParams['force-options-off'] );
} }
protected function isTagForcedOn( $tag ) { protected function isTagForcedOn( $tag ) {
return isset( $this->mParams['force-options-on'] ) return isset( $this->mParams['force-options-on'] )
&& in_array( $tag, $this->mParams['force-options-on'] ); && in_array( $tag, $this->mParams['force-options-on'] );
skipping to change at line 242 skipping to change at line 252
// Checkboxes are just not added to the request arrays if they're not checked, // Checkboxes are just not added to the request arrays if they're not checked,
// so it's perfectly possible for there not to be an entr y at all // so it's perfectly possible for there not to be an entr y at all
return $request->getArray( $this->mName, [] ); return $request->getArray( $this->mName, [] );
} else { } else {
// That's ok, the user has not yet submitted the form, so show the defaults // That's ok, the user has not yet submitted the form, so show the defaults
return $this->getDefault(); return $this->getDefault();
} }
} }
public function getDefault() { public function getDefault() {
if ( isset( $this->mDefault ) ) { return $this->mDefault ?? [];
return $this->mDefault;
} else {
return [];
}
} }
public function filterDataForSubmit( $data ) { public function filterDataForSubmit( $data ) {
$columns = HTMLFormField::flattenOptions( $this->mParams['columns '] ); $columns = HTMLFormField::flattenOptions( $this->mParams['columns '] );
$rows = HTMLFormField::flattenOptions( $this->mParams['rows'] ); $rows = HTMLFormField::flattenOptions( $this->mParams['rows'] );
$res = []; $res = [];
foreach ( $columns as $column ) { foreach ( $columns as $column ) {
foreach ( $rows as $row ) { foreach ( $rows as $row ) {
// Make sure option hasn't been forced // Make sure option hasn't been forced
$thisTag = "$column-$row"; $thisTag = "$column-$row";
skipping to change at line 269 skipping to change at line 275
} elseif ( $this->isTagForcedOn( $thisTag ) ) { } elseif ( $this->isTagForcedOn( $thisTag ) ) {
$res[$thisTag] = true; $res[$thisTag] = true;
} else { } else {
$res[$thisTag] = in_array( $thisTag, $dat a ); $res[$thisTag] = in_array( $thisTag, $dat a );
} }
} }
} }
return $res; return $res;
} }
protected function getOOUIModules() {
return [ 'mediawiki.widgets.CheckMatrixWidget' ];
}
protected function shouldInfuseOOUI() {
return true;
}
} }
 End of changes. 12 change blocks. 
33 lines changed or deleted 48 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)