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