Merge "Allow partially blocked users to tag unrelated revisions"
[lhc/web/wiklou.git] / includes / widget / SizeFilterWidget.php
1 <?php
2
3 namespace MediaWiki\Widget;
4
5 use \OOUI\RadioSelectInputWidget;
6 use \OOUI\TextInputWidget;
7 use \OOUI\LabelWidget;
8
9 /**
10 * Select and input widget.
11 *
12 * @copyright 2011-2018 MediaWiki Widgets Team and others; see AUTHORS.txt
13 * @license MIT
14 */
15 class SizeFilterWidget extends \OOUI\Widget {
16 /** @var array */
17 protected $config;
18 /** @var LabelWidget */
19 protected $label;
20 /** @var RadioSelectInputWidget */
21 protected $radioselectinput;
22 /** @var TextInputWidget */
23 protected $textinput;
24
25 /**
26 * RadioSelectInputWidget and a TextInputWidget to set minimum or maximum byte size
27 *
28 * @param array $config Configuration options
29 * - array $config['textinput'] Configuration for the TextInputWidget
30 * - array $config['radioselectinput'] Configuration for the RadioSelectWidget
31 * - bool $congif['selectMin'] Whether to select 'min', false would select 'max'
32 */
33 public function __construct( array $config = [] ) {
34 // Configuration initialization
35 $config = array_merge( [
36 'selectMin' => true,
37 'textinput' => [],
38 'radioselectinput' => []
39 ], $config );
40 $config['textinput'] = array_merge( [
41 'type' => 'number'
42 ], $config['textinput'] );
43 $config['radioselectinput'] = array_merge( [ 'options' => [
44 [
45 'data' => 'min',
46 'label' => wfMessage( 'minimum-size' )->text()
47 ],
48 [
49 'data' => 'max',
50 'label' => wfMessage( 'maximum-size' )->text()
51 ]
52 ] ], $config['radioselectinput'] );
53
54 // Parent constructor
55 parent::__construct( $config );
56
57 // Properties
58 $this->config = $config;
59 $this->radioselectinput = new RadioSelectInputWidget( $config[ 'radioselectinput'] );
60 $this->textinput = new TextInputWidget( $config[ 'textinput' ] );
61 $this->label = new LabelWidget( [ 'label' => wfMessage( 'pagesize' )->text() ] );
62
63 // Initialization
64 $this->radioselectinput->setValue( $config[ 'selectMin' ] ? 'min' : 'max' );
65 $this
66 ->addClasses( [ 'mw-widget-sizeFilterWidget' ] )
67 ->appendContent( $this->radioselectinput, $this->textinput, $this->label );
68 }
69
70 protected function getJavaScriptClassName() {
71 return 'mw.widgets.SizeFilterWidget';
72 }
73
74 public function getConfig( &$config ) {
75 $config['textinput'] = $this->config['textinput'];
76 $config['radioselectinput'] = $this->config['radioselectinput'];
77 $config['selectMin'] = $this->config['selectMin'];
78 return parent::getConfig( $config );
79 }
80 }