diff options
author | Gergő Tisza <tgr.huwiki@gmail.com> | 2023-11-03 22:49:08 -0700 |
---|---|---|
committer | Bartosz Dziewoński <dziewonski@fastmail.fm> | 2023-11-06 23:24:51 +0000 |
commit | de18cff244e8fab2e1ab2470c3b444e76b305e12 (patch) | |
tree | 4f12986264bc1bc189bc25f3f2734bf3b9c4f10c | |
parent | 9d9c782fb350c37c315a2a4f3026db8b836eed5c (diff) | |
download | mediawikicore-de18cff244e8fab2e1ab2470c3b444e76b305e12.tar.gz mediawikicore-de18cff244e8fab2e1ab2470c3b444e76b305e12.zip |
htmlform: Support HTML tooltips in checkmatrix
Bug: T290790
Bug: T254222
Change-Id: I69e8217c408acca6bd7f19e7e274b255336dccd2
-rw-r--r-- | includes/htmlform/fields/HTMLCheckMatrix.php | 5 | ||||
-rw-r--r-- | includes/specials/SpecialBotPasswords.php | 17 | ||||
-rw-r--r-- | includes/widget/CheckMatrixWidget.php | 13 | ||||
-rw-r--r-- | resources/src/mediawiki.widgets/mw.widgets.CheckMatrixWidget.js | 6 |
4 files changed, 35 insertions, 6 deletions
diff --git a/includes/htmlform/fields/HTMLCheckMatrix.php b/includes/htmlform/fields/HTMLCheckMatrix.php index 99b969194c0d..b6e03cbae07f 100644 --- a/includes/htmlform/fields/HTMLCheckMatrix.php +++ b/includes/htmlform/fields/HTMLCheckMatrix.php @@ -22,6 +22,10 @@ use MediaWiki\Request\WebRequest; * - Array of column-row tags to be displayed as disabled but unavailable to change. * - tooltips * - Optional associative array mapping row labels to tooltips (as text, will be escaped). + * - tooltips-html + * - Optional associative array mapping row labels to tooltips (as HTML). + * Only used by OOUI form fields. Takes precedence when supported, so to support both + * OOUI and non-OOUI forms, you can set both. * - tooltip-class * - Optional CSS class used on tooltip container span. Defaults to mw-icon-question. * Not used by OOUI form fields. @@ -171,6 +175,7 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { 'rows' => $this->mParams['rows'], 'columns' => $this->mParams['columns'], 'tooltips' => $this->mParams['tooltips'] ?? [], + 'tooltips-html' => $this->mParams['tooltips-html'] ?? [], 'forcedOff' => $this->mParams['force-options-off'] ?? [], 'forcedOn' => $this->mParams['force-options-on'] ?? [], 'values' => $value, diff --git a/includes/specials/SpecialBotPasswords.php b/includes/specials/SpecialBotPasswords.php index a95a8000002b..69cacb7c414e 100644 --- a/includes/specials/SpecialBotPasswords.php +++ b/includes/specials/SpecialBotPasswords.php @@ -169,10 +169,14 @@ class SpecialBotPasswords extends FormSpecialPage { $showGrants = $this->grantsInfo->getValidGrants(); $grantLinks = array_map( [ $this->grantsLocalization, 'getGrantsLink' ], $showGrants ); + $fields[] = [ + 'type' => 'info', + 'default' => '', + 'help-message' => 'botpasswords-help-grants', + ]; $fields['grants'] = [ 'type' => 'checkmatrix', 'label-message' => 'botpasswords-label-grants', - 'help-message' => 'botpasswords-help-grants', 'columns' => [ $this->msg( 'botpasswords-label-grants-column' )->escaped() => 'grant' ], @@ -186,11 +190,16 @@ class SpecialBotPasswords extends FormSpecialPage { }, $this->botPassword->getGrants() ), - 'tooltips' => array_combine( + 'tooltips-html' => array_combine( $grantLinks, array_map( - static function ( $rights ) use ( $lang ) { - return $lang->semicolonList( array_map( [ User::class, 'getRightDescription' ], $rights ) ); + function ( $rights ) use ( $lang ) { + return $lang->semicolonList( + array_map( + fn ( $right ) => $this->msg( "right-$right" )->parse(), + $rights + ) + ); }, array_intersect_key( $this->grantsInfo->getRightsByGrant(), array_fill_keys( $showGrants, true ) ) diff --git a/includes/widget/CheckMatrixWidget.php b/includes/widget/CheckMatrixWidget.php index c0cad2bdd2cc..58c0b13de3d1 100644 --- a/includes/widget/CheckMatrixWidget.php +++ b/includes/widget/CheckMatrixWidget.php @@ -20,6 +20,8 @@ class CheckMatrixWidget extends \OOUI\Widget { /** @var array */ protected $tooltips; /** @var array */ + protected $tooltipsHtml; + /** @var array */ protected $values; /** @var array */ protected $forcedOn; @@ -43,6 +45,9 @@ class CheckMatrixWidget extends \OOUI\Widget { * - Array of column-row tags to be displayed as disabled but unavailable to change. * - tooltips * - Optional associative array mapping row labels to tooltips (as text, will be escaped). + * - tooltips-html + * - Optional associative array mapping row labels to tooltips (as HTML). Takes precedence + * over text tooltips. */ public function __construct( array $config = [] ) { // Configuration initialization @@ -56,6 +61,7 @@ class CheckMatrixWidget extends \OOUI\Widget { $this->rows = $config['rows'] ?? []; $this->columns = $config['columns'] ?? []; $this->tooltips = $config['tooltips'] ?? []; + $this->tooltipsHtml = $config['tooltips-html'] ?? []; $this->values = $config['values'] ?? []; @@ -183,7 +189,11 @@ class CheckMatrixWidget extends \OOUI\Widget { * @return string Tooltip. Null if none is available. */ private function getTooltip( $label ) { - return $this->tooltips[ $label ] ?? null; + if ( isset( $this->tooltipsHtml[ $label ] ) ) { + return new \OOUI\HtmlSnippet( $this->tooltipsHtml[ $label ] ); + } else { + return $this->tooltips[ $label ] ?? null; + } } protected function getJavaScriptClassName() { @@ -197,6 +207,7 @@ class CheckMatrixWidget extends \OOUI\Widget { 'rows' => $this->rows, 'columns' => $this->columns, 'tooltips' => $this->tooltips, + 'tooltipsHtml' => $this->tooltipsHtml, 'forcedOff' => $this->forcedOff, 'forcedOn' => $this->forcedOn, 'values' => $this->values, diff --git a/resources/src/mediawiki.widgets/mw.widgets.CheckMatrixWidget.js b/resources/src/mediawiki.widgets/mw.widgets.CheckMatrixWidget.js index 2bbd7b9ddb08..e6f96fe88dc3 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.CheckMatrixWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.CheckMatrixWidget.js @@ -17,6 +17,8 @@ * disabled but unavailable to change. * @cfg {Object} [tooltips] Optional object mapping row labels to tooltips * (as text, will be escaped). + * @cfg {Object} [tooltipsHtml] Optional object mapping row labels to tooltips + * (as HTML). Takes precedence over text tooltips. */ mw.widgets.CheckMatrixWidget = function MWWCheckMatrixWidget( config ) { var $headRow = $( '<tr>' ), @@ -34,6 +36,7 @@ this.rows = config.rows || {}; this.columns = config.columns || {}; this.tooltips = config.tooltips || []; + this.tooltipsHtml = config.tooltipsHtml || []; this.values = config.values || []; this.forcedOn = config.forcedOn || []; this.forcedOff = config.forcedOff || []; @@ -56,7 +59,8 @@ new OO.ui.Widget(), // Empty widget, since we don't have the checkboxes here { label: new OO.ui.HtmlSnippet( rowLabel ), - help: widget.tooltips[ rowLabel ], + help: widget.tooltips[ rowLabel ] || + widget.tooltipsHtml[ rowLabel ] && new OO.ui.HtmlSnippet( widget.tooltipsHtml[ rowLabel ] ), align: 'inline' } ); |