MediaWiki  1.32.5
CheckMatrixWidget.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Widget;
4 
11 class CheckMatrixWidget extends \OOUI\Widget {
12 
13  protected $name = '';
14  protected $columns = [];
15  protected $rows = [];
16  protected $tooltips = [];
17  protected $values = [];
18  protected $forcedOn = [];
19  protected $forcedOff = [];
20 
41  public function __construct( array $config = [] ) {
42  // Configuration initialization
43 
44  parent::__construct( $config );
45 
46  $this->name = $config['name'] ?? null;
47  $this->id = $config['id'] ?? null;
48 
49  // Properties
50  $this->rows = $config['rows'] ?? [];
51  $this->columns = $config['columns'] ?? [];
52  $this->tooltips = $config['tooltips'] ?? [];
53 
54  $this->values = $config['values'] ?? [];
55 
56  $this->forcedOn = $config['forcedOn'] ?? [];
57  $this->forcedOff = $config['forcedOff'] ?? [];
58 
59  // Build the table
60  $table = new \OOUI\Tag( 'table' );
61  $tr = new \OOUI\Tag( 'tr' );
62  // Build the header
63  $tr->appendContent( $this->getCellTag( "\u{00A0}" ) );
64  foreach ( $this->columns as $columnLabel => $columnTag ) {
65  $tr->appendContent(
66  $this->getCellTag( new \OOUI\HtmlSnippet( $columnLabel ) )
67  );
68  }
69  $table->appendContent( $tr );
70 
71  // Build the options matrix
72  foreach ( $this->rows as $rowLabel => $rowTag ) {
73  $table->appendContent(
74  $this->getTableRow( $rowLabel, $rowTag )
75  );
76  }
77 
78  // Initialization
79  $this->addClasses( [ 'mw-widget-checkMatrixWidget' ] );
80  $this->appendContent( $table );
81  }
82 
91  private function getTableRow( $label, $tag ) {
92  $row = new \OOUI\Tag( 'tr' );
93  $tooltip = $this->getTooltip( $label );
94  $labelFieldConfig = $tooltip ? [ 'help' => $tooltip ] : [];
95  // Build label cell
96  $labelField = new \OOUI\FieldLayout(
97  new \OOUI\Widget(), // Empty widget, since we don't have the checkboxes here
98  [
99  'label' => new \OOUI\HtmlSnippet( $label ),
100  'align' => 'inline',
101  ] + $labelFieldConfig
102  );
103  $row->appendContent( $this->getCellTag( $labelField ) );
104 
105  // Build checkbox column cells
106  foreach ( $this->columns as $columnTag ) {
107  $thisTag = "$columnTag-$tag";
108 
109  // Construct a checkbox
110  $checkbox = new \OOUI\CheckboxInputWidget( [
111  'value' => $thisTag,
112  'name' => $this->name ? "{$this->name}[]" : null,
113  'id' => $this->id ? "{$this->id}-$thisTag" : null,
114  'selected' => $this->isTagChecked( $thisTag ),
115  'disabled' => $this->isTagDisabled( $thisTag ),
116  ] );
117 
118  $row->appendContent( $this->getCellTag( $checkbox ) );
119  }
120  return $row;
121  }
122 
129  private function getCellTag( $content ) {
130  $cell = new \OOUI\Tag( 'td' );
131  $cell->appendContent( $content );
132  return $cell;
133  }
134 
142  private function isTagChecked( $tagName ) {
143  // If the tag is in the value list
144  return in_array( $tagName, (array)$this->values, true ) ||
145  // Or if the tag is forced on
146  in_array( $tagName, (array)$this->forcedOn, true );
147  }
148 
156  private function isTagDisabled( $tagName ) {
157  return (
158  // If the entire widget is disabled
159  $this->isDisabled() ||
160  // If the tag is 'forced on' or 'forced off'
161  in_array( $tagName, (array)$this->forcedOn, true ) ||
162  in_array( $tagName, (array)$this->forcedOff, true )
163  );
164  }
165 
172  private function getTooltip( $label ) {
173  return $this->tooltips[ $label ] ?? null;
174  }
175 
176  protected function getJavaScriptClassName() {
177  return 'mw.widgets.CheckMatrixWidget';
178  }
179 
180  public function getConfig( &$config ) {
181  $config += [
182  'name' => $this->name,
183  'id' => $this->id,
184  'rows' => $this->rows,
185  'columns' => $this->columns,
186  'tooltips' => $this->tooltips,
187  'forcedOff' => $this->forcedOff,
188  'forcedOn' => $this->forcedOn,
189  'values' => $this->values,
190  ];
191  return parent::getConfig( $config );
192  }
193 }
MediaWiki\Widget\CheckMatrixWidget\$values
$values
Definition: CheckMatrixWidget.php:17
MediaWiki\Widget\CheckMatrixWidget\getTooltip
getTooltip( $label)
Get the tooltip help associated with this row.
Definition: CheckMatrixWidget.php:172
MediaWiki\Widget\CheckMatrixWidget
Check matrix widget.
Definition: CheckMatrixWidget.php:11
MediaWiki\Widget\CheckMatrixWidget\getCellTag
getCellTag( $content)
Get an individual cell tag with requested content.
Definition: CheckMatrixWidget.php:129
MediaWiki\Widget\CheckMatrixWidget\getTableRow
getTableRow( $label, $tag)
Get a formatted table row for the option, with a checkbox widget.
Definition: CheckMatrixWidget.php:91
MediaWiki\Widget\CheckMatrixWidget\__construct
__construct(array $config=[])
CheckMatrixWidget constructor.
Definition: CheckMatrixWidget.php:41
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Widget\CheckMatrixWidget\$tooltips
$tooltips
Definition: CheckMatrixWidget.php:16
name
and how to run hooks for an and one after Each event has a name
Definition: hooks.txt:6
MediaWiki\Widget\CheckMatrixWidget\$forcedOff
$forcedOff
Definition: CheckMatrixWidget.php:19
MediaWiki\Widget\CheckMatrixWidget\$forcedOn
$forcedOn
Definition: CheckMatrixWidget.php:18
MediaWiki\Widget\CheckMatrixWidget\$name
$name
Definition: CheckMatrixWidget.php:13
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
MediaWiki\Widget\CheckMatrixWidget\getJavaScriptClassName
getJavaScriptClassName()
Definition: CheckMatrixWidget.php:176
MediaWiki\Widget\CheckMatrixWidget\isTagDisabled
isTagDisabled( $tagName)
Check whether the given tag's checkbox should be disabled.
Definition: CheckMatrixWidget.php:156
MediaWiki\Widget
Definition: CheckMatrixWidget.php:3
values
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
Definition: hooks.txt:175
MediaWiki\Widget\CheckMatrixWidget\isTagChecked
isTagChecked( $tagName)
Check whether the given tag's checkbox should be checked.
Definition: CheckMatrixWidget.php:142
MediaWiki\$config
Config $config
Definition: MediaWiki.php:43
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$content
$content
Definition: pageupdater.txt:72
MediaWiki\Widget\CheckMatrixWidget\getConfig
getConfig(&$config)
Definition: CheckMatrixWidget.php:180
MediaWiki\Widget\CheckMatrixWidget\$columns
$columns
Definition: CheckMatrixWidget.php:14
MediaWiki\Widget\CheckMatrixWidget\$rows
$rows
Definition: CheckMatrixWidget.php:15