| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Widget; |
| 4 |
|
| 5 |
use OOUI\CheckboxInputWidget; |
| 6 |
use OOUI\Exception; |
| 7 |
use OOUI\FieldLayout; |
| 8 |
use OOUI\Widget; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class ComplexNamespaceInputWidget extends Widget { |
| 18 |
|
| 19 |
|
| 20 |
protected $config; |
| 21 |
|
| 22 |
protected $namespace; |
| 23 |
|
| 24 |
protected $associated = null; |
| 25 |
|
| 26 |
protected $associatedLabel = null; |
| 27 |
|
| 28 |
protected $invert = null; |
| 29 |
|
| 30 |
protected $invertLabel = null; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function __construct( array $config = [] ) { |
| 52 |
|
| 53 |
$config = array_merge( |
| 54 |
[ |
| 55 |
|
| 56 |
'namespace' => [], |
| 57 |
'invert' => [], |
| 58 |
'invertLabel' => [], |
| 59 |
'associated' => [], |
| 60 |
'associatedLabel' => [], |
| 61 |
], |
| 62 |
$config |
| 63 |
); |
| 64 |
|
| 65 |
parent::__construct( $config ); |
| 66 |
|
| 67 |
|
| 68 |
$this->config = $config; |
| 69 |
|
| 70 |
$this->namespace = new NamespaceInputWidget( $config['namespace'] ); |
| 71 |
if ( $config['associated'] !== null ) { |
| 72 |
$this->associated = new CheckboxInputWidget( array_merge( |
| 73 |
[ 'value' => '1' ], |
| 74 |
$config['associated'] |
| 75 |
) ); |
| 76 |
|
| 77 |
$this->associatedLabel = new FieldLayout( |
| 78 |
$this->associated, |
| 79 |
array_merge( |
| 80 |
[ 'align' => 'inline' ], |
| 81 |
$config['associatedLabel'] |
| 82 |
) |
| 83 |
); |
| 84 |
} |
| 85 |
if ( $config['invert'] !== null ) { |
| 86 |
$this->invert = new CheckboxInputWidget( array_merge( |
| 87 |
[ 'value' => '1' ], |
| 88 |
$config['invert'] |
| 89 |
) ); |
| 90 |
|
| 91 |
$this->invertLabel = new FieldLayout( |
| 92 |
$this->invert, |
| 93 |
array_merge( |
| 94 |
[ 'align' => 'inline' ], |
| 95 |
$config['invertLabel'] |
| 96 |
) |
| 97 |
); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
$this |
| 102 |
->addClasses( [ 'mw-widget-complexNamespaceInputWidget' ] ) |
| 103 |
->appendContent( $this->namespace, $this->associatedLabel, $this->invertLabel ); |
| 104 |
} |
| 105 |
|
| 106 |
protected function getJavaScriptClassName() { |
| 107 |
return 'mw.widgets.ComplexNamespaceInputWidget'; |
| 108 |
} |
| 109 |
|
| 110 |
public function getConfig( &$config ) { |
| 111 |
$config = array_merge( |
| 112 |
$config, |
| 113 |
array_intersect_key( |
| 114 |
$this->config, |
| 115 |
array_fill_keys( |
| 116 |
[ |
| 117 |
'namespace', |
| 118 |
'invert', |
| 119 |
'invertLabel', |
| 120 |
'associated', |
| 121 |
'associatedLabel' |
| 122 |
], |
| 123 |
true |
| 124 |
) |
| 125 |
) |
| 126 |
); |
| 127 |
$config['namespace']['dropdown']['$overlay'] = true; |
| 128 |
return parent::getConfig( $config ); |
| 129 |
} |
| 130 |
} |