MediaWiki  master
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  $table->addClasses( [ 'mw-htmlform-matrix mw-widget-checkMatrixWidget-matrix' ] );
62  $thead = new \OOUI\Tag( 'thead' );
63  $table->appendContent( $thead );
64  $tr = new \OOUI\Tag( 'tr' );
65 
66  // Build the header
67  $tr->appendContent( $this->getCellTag( "\u{00A0}" ) );
68  foreach ( $this->columns as $columnLabel => $columnTag ) {
69  $tr->appendContent(
70  $this->getCellTag( new \OOUI\HtmlSnippet( $columnLabel ), 'th' )
71  );
72  }
73  $thead->appendContent( $tr );
74 
75  // Build the options matrix
76  $tbody = new \OOUI\Tag( 'tbody' );
77  $table->appendContent( $tbody );
78  foreach ( $this->rows as $rowLabel => $rowTag ) {
79  $tbody->appendContent(
80  $this->getTableRow( $rowLabel, $rowTag )
81  );
82  }
83 
84  // Initialization
85  $this->addClasses( [ 'mw-widget-checkMatrixWidget' ] );
86  $this->appendContent( $table );
87  }
88 
97  private function getTableRow( $label, $tag ) {
98  $row = new \OOUI\Tag( 'tr' );
99  $tooltip = $this->getTooltip( $label );
100  $labelFieldConfig = $tooltip ? [ 'help' => $tooltip ] : [];
101  // Build label cell
102  $labelField = new \OOUI\FieldLayout(
103  new \OOUI\Widget(), // Empty widget, since we don't have the checkboxes here
104  [
105  'label' => new \OOUI\HtmlSnippet( $label ),
106  'align' => 'inline',
107  ] + $labelFieldConfig
108  );
109  $row->appendContent( $this->getCellTag( $labelField ) );
110 
111  // Build checkbox column cells
112  foreach ( $this->columns as $columnTag ) {
113  $thisTag = "$columnTag-$tag";
114 
115  // Construct a checkbox
116  $checkbox = new \OOUI\CheckboxInputWidget( [
117  'value' => $thisTag,
118  'name' => $this->name ? "{$this->name}[]" : null,
119  'id' => $this->id ? "{$this->id}-$thisTag" : null,
120  'selected' => $this->isTagChecked( $thisTag ),
121  'disabled' => $this->isTagDisabled( $thisTag ),
122  ] );
123 
124  $row->appendContent( $this->getCellTag( $checkbox ) );
125  }
126  return $row;
127  }
128 
135  private function getCellTag( $content, $tagElement = 'td' ) {
136  $cell = new \OOUI\Tag( $tagElement );
137  $cell->appendContent( $content );
138  return $cell;
139  }
140 
148  private function isTagChecked( $tagName ) {
149  // If the tag is in the value list
150  return in_array( $tagName, (array)$this->values, true ) ||
151  // Or if the tag is forced on
152  in_array( $tagName, (array)$this->forcedOn, true );
153  }
154 
162  private function isTagDisabled( $tagName ) {
163  return (
164  // If the entire widget is disabled
165  $this->isDisabled() ||
166  // If the tag is 'forced on' or 'forced off'
167  in_array( $tagName, (array)$this->forcedOn, true ) ||
168  in_array( $tagName, (array)$this->forcedOff, true )
169  );
170  }
171 
178  private function getTooltip( $label ) {
179  return $this->tooltips[ $label ] ?? null;
180  }
181 
182  protected function getJavaScriptClassName() {
183  return 'mw.widgets.CheckMatrixWidget';
184  }
185 
186  public function getConfig( &$config ) {
187  $config += [
188  'name' => $this->name,
189  'id' => $this->id,
190  'rows' => $this->rows,
191  'columns' => $this->columns,
192  'tooltips' => $this->tooltips,
193  'forcedOff' => $this->forcedOff,
194  'forcedOn' => $this->forcedOn,
195  'values' => $this->values,
196  ];
197  return parent::getConfig( $config );
198  }
199 }
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))
Config $config
Definition: MediaWiki.php:43
isTagDisabled( $tagName)
Check whether the given tag&#39;s checkbox should be disabled.
isTagChecked( $tagName)
Check whether the given tag&#39;s checkbox should be checked.
getCellTag( $content, $tagElement='td')
Get an individual cell tag with requested content.
and how to run hooks for an and one after Each event has a name
Definition: hooks.txt:6
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
getTooltip( $label)
Get the tooltip help associated with this row.
__construct(array $config=[])
CheckMatrixWidget constructor.
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
getTableRow( $label, $tag)
Get a formatted table row for the option, with a checkbox widget.
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
$content
Definition: pageupdater.txt:72