Merge "Update OOjs to v1.1.10"
[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 protected $suggestions = null;
18
19 /**
20 * @param array $config Configuration options
21 * @param int|null $config['namespace'] Namespace to prepend to queries
22 * @param bool|null $config['relative'] If a namespace is set,
23 * return a title relative to it (default: true)
24 * @param bool|null $config['suggestions'] Display search suggestions (default: true)
25 */
26 public function __construct( array $config = array() ) {
27 // Parent constructor
28 parent::__construct(
29 array_merge( array( 'infusable' => true, 'maxLength' => 255 ), $config )
30 );
31
32 // Properties, which are ignored in PHP and just shipped back to JS
33 if ( isset( $config['namespace'] ) ) {
34 $this->namespace = $config['namespace'];
35 }
36 if ( isset( $config['relative'] ) ) {
37 $this->relative = $config['relative'];
38 }
39 if ( isset( $config['suggestions'] ) ) {
40 $this->suggestions = $config['suggestions'];
41 }
42 if ( isset( $config['highlightFirst'] ) ) {
43 $this->highlightFirst = $config['highlightFirst'];
44 }
45
46 // Initialization
47 $this->addClasses( array( 'mw-widget-titleInputWidget' ) );
48 }
49
50 protected function getJavaScriptClassName() {
51 return 'mw.widgets.TitleInputWidget';
52 }
53
54 public function getConfig( &$config ) {
55 if ( $this->namespace !== null ) {
56 $config['namespace'] = $this->namespace;
57 }
58 if ( $this->relative !== null ) {
59 $config['relative'] = $this->relative;
60 }
61 if ( $this->suggestions !== null ) {
62 $config['suggestions'] = $this->suggestions;
63 }
64 if ( $this->highlightFirst !== null ) {
65 $config['highlightFirst'] = $this->highlightFirst;
66 }
67 return parent::getConfig( $config );
68 }
69 }