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