summaryrefslogtreecommitdiff
path: root/www/wiki/includes/widget/ComplexTitleInputWidget.php
blob: ca6c8484d1ffb905a69340e7cd88a492f821b838 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

namespace MediaWiki\Widget;

/**
 * Complex title input widget.
 *
 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
 * @license MIT
 */
class ComplexTitleInputWidget extends \OOUI\Widget {

	protected $namespace = null;
	protected $title = null;

	/**
	 * Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
	 *
	 * @param array $config Configuration options
	 *   - array $config['namespace'] Configuration for the NamespaceInputWidget dropdown
	 *     with list of namespaces
	 *   - array $config['title'] Configuration for the TitleInputWidget text field
	 */
	public function __construct( array $config = [] ) {
		// Configuration initialization
		$config = array_merge(
			[
				'namespace' => [],
				'title' => [],
			],
			$config
		);

		parent::__construct( $config );

		// Properties
		$this->config = $config;
		$this->namespace = new NamespaceInputWidget( $config['namespace'] );
		$this->title = new TitleInputWidget( array_merge(
			$config['title'],
			[
				'relative' => true,
				'namespace' => isset( $config['namespace']['value'] ) ?
					$config['namespace']['value'] :
					null,
			]
		) );

		// Initialization
		$this
			->addClasses( [ 'mw-widget-complexTitleInputWidget' ] )
			->appendContent( $this->namespace, $this->title );
	}

	protected function getJavaScriptClassName() {
		return 'mw.widgets.ComplexTitleInputWidget';
	}

	public function getConfig( &$config ) {
		$config['namespace'] = $this->config['namespace'];
		$config['namespace']['dropdown']['$overlay'] = true;
		$config['title'] = $this->config['title'];
		$config['title']['$overlay'] = true;
		return parent::getConfig( $config );
	}
}