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