Merge "mediawiki.language: Implement non-digit-grouping of four-digit numbers"
[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 The MIT License (MIT); see LICENSE.txt
14 */
15 class SizeFilterWidget extends \OOUI\Widget {
16
17 protected $radioselectinput = null;
18 protected $textinput = null;
19
20 /**
21 * RadioSelectInputWidget and a TextInputWidget to set minimum or maximum byte size
22 *
23 * @param array $config Configuration options
24 * - array $config['textinput'] Configuration for the TextInputWidget
25 * - array $config['radioselectinput'] Configuration for the RadioSelectWidget
26 * - bool $congif['selectMin'] Whether to select 'min', false would select 'max'
27 */
28 public function __construct( array $config = [] ) {
29 // Configuration initialization
30 $config = array_merge( [
31 'selectMin' => true,
32 'textinput' => [],
33 'radioselectinput' => []
34 ], $config );
35 $config['textinput'] = array_merge( [
36 'type' => 'number'
37 ], $config['textinput'] );
38 $config['radioselectinput'] = array_merge( [ 'options' => [
39 [
40 'data' => 'min',
41 'label' => wfMessage( 'minimum-size' )->text()
42 ],
43 [
44 'data' => 'max',
45 'label' => wfMessage( 'maximum-size' )->text()
46 ]
47 ] ], $config['radioselectinput'] );
48
49 // Parent constructor
50 parent::__construct( $config );
51
52 // Properties
53 $this->config = $config;
54 $this->radioselectinput = new RadioSelectInputWidget( $config[ 'radioselectinput'] );
55 $this->textinput = new TextInputWidget( $config[ 'textinput' ] );
56 $this->label = new LabelWidget( [ 'label' => wfMessage( 'pagesize' )->text() ] );
57
58 // Initialization
59 $this->radioselectinput->setValue( $config[ 'selectMin' ] ? 'min' : 'max' );
60 $this
61 ->addClasses( [ 'mw-widget-sizeFilterWidget' ] )
62 ->appendContent( $this->radioselectinput, $this->textinput, $this->label );
63 }
64
65 protected function getJavaScriptClassName() {
66 return 'mw.widgets.SizeFilterWidget';
67 }
68
69 public function getConfig( &$config ) {
70 $config['textinput'] = $this->config['textinput'];
71 $config['radioselectinput'] = $this->config['radioselectinput'];
72 $config['selectMin'] = $this->config['selectMin'];
73 return parent::getConfig( $config );
74 }
75 }