MediaWiki  1.33.0
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 
39  public function __construct( array $config = [] ) {
40  // Configuration initialization
41 
42  parent::__construct( $config );
43 
44  $this->name = $config['name'] ?? null;
45  $this->id = $config['id'] ?? null;
46 
47  // Properties
48  $this->rows = $config['rows'] ?? [];
49  $this->columns = $config['columns'] ?? [];
50  $this->tooltips = $config['tooltips'] ?? [];
51 
52  $this->values = $config['values'] ?? [];
53 
54  $this->forcedOn = $config['forcedOn'] ?? [];
55  $this->forcedOff = $config['forcedOff'] ?? [];
56 
57  // Build the table
58  $table = new \OOUI\Tag( 'table' );
59  $table->addClasses( [ 'mw-htmlform-matrix mw-widget-checkMatrixWidget-matrix' ] );
60  $thead = new \OOUI\Tag( 'thead' );
61  $table->appendContent( $thead );
62  $tr = new \OOUI\Tag( 'tr' );
63 
64  // Build the header
65  $tr->appendContent( $this->getCellTag( "\u{00A0}" ) );
66  foreach ( $this->columns as $columnLabel => $columnTag ) {
67  $tr->appendContent(
68  $this->getCellTag( new \OOUI\HtmlSnippet( $columnLabel ), 'th' )
69  );
70  }
71  $thead->appendContent( $tr );
72 
73  // Build the options matrix
74  $tbody = new \OOUI\Tag( 'tbody' );
75  $table->appendContent( $tbody );
76  foreach ( $this->rows as $rowLabel => $rowTag ) {
77  $tbody->appendContent(
78  $this->getTableRow( $rowLabel, $rowTag )
79  );
80  }
81 
82  // Initialization
83  $this->addClasses( [ 'mw-widget-checkMatrixWidget' ] );
84  $this->appendContent( $table );
85  }
86 
95  private function getTableRow( $label, $tag ) {
96  $row = new \OOUI\Tag( 'tr' );
97  $tooltip = $this->getTooltip( $label );
98  $labelFieldConfig = $tooltip ? [ 'help' => $tooltip ] : [];
99  // Build label cell
100  $labelField = new \OOUI\FieldLayout(
101  new \OOUI\Widget(), // Empty widget, since we don't have the checkboxes here
102  [
103  'label' => new \OOUI\HtmlSnippet( $label ),
104  'align' => 'inline',
105  ] + $labelFieldConfig
106  );
107  $row->appendContent( $this->getCellTag( $labelField ) );
108 
109  // Build checkbox column cells
110  foreach ( $this->columns as $columnTag ) {
111  $thisTag = "$columnTag-$tag";
112 
113  // Construct a checkbox
114  $checkbox = new \OOUI\CheckboxInputWidget( [
115  'value' => $thisTag,
116  'name' => $this->name ? "{$this->name}[]" : null,
117  'id' => $this->id ? "{$this->id}-$thisTag" : null,
118  'selected' => $this->isTagChecked( $thisTag ),
119  'disabled' => $this->isTagDisabled( $thisTag ),
120  ] );
121 
122  $row->appendContent( $this->getCellTag( $checkbox ) );
123  }
124  return $row;
125  }
126 
133  private function getCellTag( $content, $tagElement = 'td' ) {
134  $cell = new \OOUI\Tag( $tagElement );
135  $cell->appendContent( $content );
136  return $cell;
137  }
138 
146  private function isTagChecked( $tagName ) {
147  // If the tag is in the value list
148  return in_array( $tagName, (array)$this->values, true ) ||
149  // Or if the tag is forced on
150  in_array( $tagName, (array)$this->forcedOn, true );
151  }
152 
160  private function isTagDisabled( $tagName ) {
161  return (
162  // If the entire widget is disabled
163  $this->isDisabled() ||
164  // If the tag is 'forced on' or 'forced off'
165  in_array( $tagName, (array)$this->forcedOn, true ) ||
166  in_array( $tagName, (array)$this->forcedOff, true )
167  );
168  }
169 
176  private function getTooltip( $label ) {
177  return $this->tooltips[ $label ] ?? null;
178  }
179 
180  protected function getJavaScriptClassName() {
181  return 'mw.widgets.CheckMatrixWidget';
182  }
183 
184  public function getConfig( &$config ) {
185  $config += [
186  'name' => $this->name,
187  'id' => $this->id,
188  'rows' => $this->rows,
189  'columns' => $this->columns,
190  'tooltips' => $this->tooltips,
191  'forcedOff' => $this->forcedOff,
192  'forcedOn' => $this->forcedOn,
193  'values' => $this->values,
194  ];
195  return parent::getConfig( $config );
196  }
197 }
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:176
MediaWiki\Widget\CheckMatrixWidget
Check matrix widget.
Definition: CheckMatrixWidget.php:11
MediaWiki\Widget\CheckMatrixWidget\getTableRow
getTableRow( $label, $tag)
Get a formatted table row for the option, with a checkbox widget.
Definition: CheckMatrixWidget.php:95
MediaWiki\Widget\CheckMatrixWidget\__construct
__construct(array $config=[])
Operates similarly to MultiSelectWidget, but instead of using an array of options,...
Definition: CheckMatrixWidget.php:39
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:180
MediaWiki\Widget\CheckMatrixWidget\isTagDisabled
isTagDisabled( $tagName)
Check whether the given tag's checkbox should be disabled.
Definition: CheckMatrixWidget.php:160
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:146
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:184
MediaWiki\Widget\CheckMatrixWidget\$columns
$columns
Definition: CheckMatrixWidget.php:14
MediaWiki\Widget\CheckMatrixWidget\$rows
$rows
Definition: CheckMatrixWidget.php:15
MediaWiki\Widget\CheckMatrixWidget\getCellTag
getCellTag( $content, $tagElement='td')
Get an individual cell tag with requested content.
Definition: CheckMatrixWidget.php:133