Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ComplexTitleInputWidget | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
getJavaScriptClassName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getConfig | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Widget; |
4 | |
5 | use OOUI\Widget; |
6 | |
7 | /** |
8 | * Complex title input widget. |
9 | * |
10 | * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt |
11 | * @license MIT |
12 | */ |
13 | class ComplexTitleInputWidget extends Widget { |
14 | /** @var array */ |
15 | protected $config; |
16 | /** @var NamespaceInputWidget|null */ |
17 | protected $namespace = null; |
18 | /** @var TitleInputWidget|null */ |
19 | protected $title = null; |
20 | |
21 | /** |
22 | * Like TitleInputWidget, but the namespace has to be input through a separate dropdown field. |
23 | * |
24 | * @param array $config Configuration options |
25 | * - array $config['namespace'] Configuration for the NamespaceInputWidget dropdown |
26 | * with list of namespaces |
27 | * - array $config['title'] Configuration for the TitleInputWidget text field |
28 | * @phan-param array{namespace?:array,title?:array} $config |
29 | */ |
30 | public function __construct( array $config = [] ) { |
31 | // Configuration initialization |
32 | $config = array_merge( |
33 | [ |
34 | 'namespace' => [], |
35 | 'title' => [], |
36 | ], |
37 | $config |
38 | ); |
39 | |
40 | parent::__construct( $config ); |
41 | |
42 | // Properties |
43 | $this->config = $config; |
44 | $this->namespace = new NamespaceInputWidget( $config['namespace'] ); |
45 | $this->title = new TitleInputWidget( array_merge( |
46 | $config['title'], |
47 | [ |
48 | 'relative' => true, |
49 | 'namespace' => $config['namespace']['value'] ?? null, |
50 | ] |
51 | ) ); |
52 | |
53 | // Initialization |
54 | $this |
55 | ->addClasses( [ 'mw-widget-complexTitleInputWidget' ] ) |
56 | ->appendContent( $this->namespace, $this->title ); |
57 | } |
58 | |
59 | protected function getJavaScriptClassName() { |
60 | return 'mw.widgets.ComplexTitleInputWidget'; |
61 | } |
62 | |
63 | public function getConfig( &$config ) { |
64 | $config['namespace'] = $this->config['namespace']; |
65 | $config['namespace']['dropdown']['$overlay'] = true; |
66 | $config['title'] = $this->config['title']; |
67 | $config['title']['$overlay'] = true; |
68 | return parent::getConfig( $config ); |
69 | } |
70 | } |