d3e2851982cc8562512b3ff51fee10b57cec22b0
[lhc/web/wiklou.git] / includes / widget / TitleInputWidget.php
1 <?php
2 /**
3 * MediaWiki Widgets – TitleInputWidget 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 * Title input widget.
12 */
13 class TitleInputWidget extends \OOUI\TextInputWidget {
14
15 protected $namespace = null;
16 protected $relative = null;
17
18 /**
19 * @param array $config Configuration options
20 * @param int|null $config['namespace'] Namespace to prepend to queries
21 * @param bool|null $config['relative'] If a namespace is set, return a title relative to it (default: true)
22 */
23 public function __construct( array $config = array() ) {
24 // Parent constructor
25 parent::__construct( array_merge( $config, array( 'infusable' => true ) ) );
26
27 // Properties, which are ignored in PHP and just shipped back to JS
28 if ( isset( $config['namespace'] ) ) {
29 $this->namespace = $config['namespace'];
30 }
31
32 if ( isset( $config['relative'] ) ) {
33 $this->relative = $config['relative'];
34 }
35
36 // Initialization
37 $this->addClasses( array( 'mw-widget-titleInputWidget' ) );
38 }
39
40 protected function getJavaScriptClassName() {
41 return 'mw.widgets.TitleInputWidget';
42 }
43
44 public function getConfig( &$config ) {
45 if ( $this->namespace !== null ) {
46 $config['namespace'] = $this->namespace;
47 }
48 if ( $this->relative !== null ) {
49 $config['relative'] = $this->relative;
50 }
51 return parent::getConfig( $config );
52 }
53 }